Setup VMWARE Host as router for Solaris, Linux, FreeBSD, and Windows XP Guest OS

VMware Workstation allows the creation and execution of multiple x86 virtual computers simultaneously. Setting up VMWARE workstation host computer can be tricky. Official VMWARE workstation document recommend of creating vmnet1 and vmnet2. However, you can use eth0 and vmnet1 to route all traffic from guest operating systems via Linux host. This is quite useful:

* If you don’t want setup firewall for each operating system inside VMWARE
* Ease of IP accounting etc


VMWARE Workstation Running on P4 system with 4 GB RAM
OS: Red Hat Enterprise Linux 4.0

  • eth0:
  • vmnet1: (hostonly networking)

Step # 1: Stop vmware and service

Shutdown all VM’s and stop vmware service: # /etc/init.d/vmware stop

Force Linux to act as a router:
echo 1 > /proc/sys/net/ipv4/ip_forward

Open /etc/sysctl.conf file and
# vi /etc/sysctl.conf
Make sure IP packet forwarding is set:
net.ipv4.ip_forward = 1

Save and close the file. Above line ensures that Linux as a router after rebooting system.

Step # 2: Configure hostonly networking

You need to configure interfaces on Linux Vmware host:

  • eth0 (Bridge) : Static IP
  • vmnet1 (hostonly) : Static IP

Type following command to configure vmware:
# /usr/bin/
At networking screen, add hostonly networking for vmnet1 Keep eth0 (bridge) as it is. Assign IP to vmnet1.

Step # 3: Configure Linux Host to route traffic

Just add following IPtables rules to your iptables script so that you can route traffic between eth0 (Linux host) and vmnet1 (Guest OS):
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface vmnet1 -j ACCEPT
iptables -A INPUT -i vmnet1 -s -d -j ACCEPT

Step # 4 Configure Guest OS

  1. Start Vmware application.
  2. Select Virtual machine
  3. Click on VM
  4. Select Settings
  5. Select Ethernet1
  6. Select Network Connection: “Host-only: A private network shared with the host”
  7. Click ok to save

Power on virtual system and point router IP address to, here is sample FreeBSD rc.conf file:defaultrouter=""
ifconfig_lnc0="inet netmask"
Please note that you need to add appropriate iptables rules to allow incoming traffic to Guest os. Just add your rules to Linux host.
See also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 8 comments so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
8 comments… add one
  • Mike Apr 18, 2012 @ 21:34

    Hey all, I know this is an old post but still relevant 😉 Thanks for sharing nice tricks nixcraft !

    My home physical network is as it is for many of us.
    I have a machine on the network which IP address is fixed (through DHCP) This machine runs Linux and hosts couple of VMs.
    I’ve created a hostonly network vmnet20 ( for them.

    Now I want to access them from my home network without changing their IP. On my home router I’ve added a route as follow : UG 0 0 br0

    From another machine ( I can do a traceroute and I confirm the router does it’s job, but I never reach the guest VM, neither when I ping or ssh.

    I added the iptables roules metionned in the article.

    Any idea what I forgot, or did wrong ?

  • Ludovic Kuty May 5, 2011 @ 10:55

    Great tutorial.

    Note that the following commands are not strictly necessary:
    iptables –append FORWARD –in-interface vmnet1 -j ACCEPT
    iptables -A INPUT -i vmnet1 -s -d -j ACCEPT

    There are just used if the box is secured and the default policy of the forward and input chains is not accept.

  • S!FE Oct 1, 2010 @ 16:43

    can you put example for virtualbox because i tried but didn’t success .

  • Rashmi Ranjan Apr 12, 2008 @ 7:28

    The above discussion is helpful if we are trying to set up windos as guest and Linux as host. But my requirement is Windos XP is host and linux is guest. Please let me know how do I establish a connection between the machines.

    A quick reply would be really very helpful.

  • 🐧 nixCraft Dec 8, 2006 @ 10:42


    You need to add 1 to /proc/sys/net/ipv4/ip_forward (file name is not correct)

    Appreciate your post!

  • Peter Burkholder Dec 8, 2006 @ 5:22

    I got this to work once I remembered:

    echo 1 > /proc/sys/net/ipv4/ip_foward


  • 🐧 nixCraft Nov 24, 2006 @ 9:31

    There are many ways to disable su. Simple and easy solution is remove su command or put it to /root directory.

    Other solution would be remove executable permission for rest of the world.

  • inam Nov 24, 2006 @ 0:36

    can root disable the su command on a system

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @