jwallace.us

tech, tunes, and other stuff

Port Forwarding With VMware Fusion & NAT

Perhaps you would like to run a Linux based web server under VMWare Fusion, and would like for it to be accessed from the internet.  This will explain how to set it up.

Your first task will be to set up a static IP for your VM.  First you’ll need to find out what the MAC address VMWare is using for your VM.  You can obtain that information by going into VMWare’s virtual machines directory to see what it is assigning to its ethernet0.generatedAddress parameter.  On my Mac, I can find that here:

/Users/john/Documents/Virtual Machines.localized/Ubuntu.vmwarevm

So I open a Terminal window (I like iTerm) and issue these commands:

1
2
cd "/Users/john/Documents/Virtual Machines.localized/Ubuntu.vmwarevm"
cat *.vmx | grep generatedAddress

and I get this back:

1
2
ethernet0.generatedAddress = "00:0c:29:03:44:9b"
ethernet0.generatedAddressOffset = "0"

Make note of the generatedAddress entry, we’ll use that below.

Next you need to go to this folder…

/Library/Application Support/VMware Fusion/vmnet8

…then edit dhcp.conf and look for an entry similar to this:

dhcp.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
subnet 192.168.216.0 netmask 255.255.255.0 {
   range 192.168.216.128 192.168.216.254;
   option broadcast-address 192.168.216.255;
   option domain-name-servers 192.168.216.2;
   option domain-name localdomain;
   default-lease-time 1800;                # default is 30 minutes
   max-lease-time 7200;                    # default is 2 hours
   option routers 192.168.216.2;
}
host vmnet8 {
   hardware ethernet 00:50:56:C0:00:08;
   fixed-address 192.168.216.1;
   option domain-name-servers 0.0.0.0;
   option domain-name "";
   option routers 0.0.0.0;
}
####### VMNET DHCP Configuration. End of "DO NOT MODIFY SECTION" #######

For each VM that you wish to set up a static IP, you will need to make a similar entry at the end of the file.  Make sure the fixed-address entry below is outside the range is the subnet entry above (192.168.216.128 through 192.168.216.254).

1
2
3
4
host linuxvm {
   hardware ethernet 00:0c:29:03:44:9b;
   fixed-address 192.168.216.32;
}

After this entry, save dhcp.conf.

Now, in the same directory as dhcp.conf you will find another configuration file called nat.conf.   Open up nat.conf  for editing.  and make the following addition under the [incomingtcp] section:

80 = 192.168.216.32:80

Optionally, you may wish to make entries in your Mac’s /etc/hosts file.  For example:

1
2
# ubuntu linux vm (vmware)
192.168.216.32  linuxvm

After making these changes, you will need to restart VMWare networking with the following command:

sudo "/Library/Application Support/VMware Fusion/boot.sh" --restart

Thats all there is to it.  You are now ready to run your web server in a Linux VM !