VMWare Fusion – DHCP and Port Forwarding

In my previous post I explained the 2 main options for networking in VMWare Fusion. Enough with the back story. In this post I’m assuming that you are using NAT and you want to set up port forwarding.

VMWare Fusion still has no GUI for setting up port forwarding, so we have to go into the config files and do it ourselves. Sometimes VMWare will just overwrite the settings, so you may want to bookmark post so you can re-do this in the future.

Restarting Fusion Network Service


Changing these config files can be a pain. When you change the config files, you’ll have to reset Fusion’s networking to get it to reload the config files. The easiest way to do this is just shut down your VM’s, and restart VMWare Fusion. If you hate restarting your VM’s as much as I do, this is just dumb. Luckily, you don’t have to restart VMWare Fusion.

This will restart the networking process that Fusion uses. If there are any errors then it will tell you the service failed to start. It doesn’t do much for telling you why, but it gives you more info than restarting Fusion does, so I guess that’s a plus.

Static IP address – DHCP


If you’re setting up port forwarding, you’ll probably want to configure a static IP address for the Guest as well. Before I did this, sometimes my Guest would just randomly change it’s IP address, breaking the port forwarding.

The dhcp config is the best place to set up your static IP address. To edit the config file:

Inside the config file you’ll see something like this:

Look at the line that says range 192.168.208.128 192.168.208.254;. This is telling you the range of IP addresses that Fusion will assign out. So you’ll want to pick a 192.168.208.X address outside of that range. Don’t use 192.168.208.1 though. that address is statically assigned to the HOST.

NOTE: 192.168.208.X is what MY machine assigns out, but I’ve seen different ranges on different people’s computers. LOOK AT YOUR CONFIG FILE TO FIND YOUR RANGE.

We’ll be adding an entry to the bottom of the file that looks like this:

<some-name> can be any value you want.
<MAC-ADDRESS> is the MAC address of the Guest.
<IP-address> is the desired IP address of the Guest.

The entry in my dhcp config looks like this:

Port Forwarding


Now that we’ve set up a static IP address, we just need to set up the port forwarding.

There’s a lot of stuff in this file that we’re going to leave alone. Near the bottom you’ll see something like this

This is where we’ll be putting the port forwarding. If you read the above section you’ll see
#<external port number> = <VM's IP address>:<VM's port number>
which has the format we’ll be using. So all we need to do is add this line

To forward web traffic to the Guest. NOTE: use the IP address you picked for your Guest to be statically assigned.

Remember to restart the Fusion Networking services.

Ruby Script


Finally, now that you know how to edit the configuration files, I threw together a Ruby script to make it a little faster for us.

If you’re one of my co-workers, I have a gem set up on an internal gem server so just come ask me about it.

If you’re not one of my co-workers, I don’t have this set up as a public gem, but you’re welcome to download it: FusionNetworkUtil-1.0.0 and then sudo gem install FusionNetworkUtil-1.0.0.gem. Maybe I’ll put it up as a public gem in the future, but right now I don’t want. I recommend just installing the gem and reading how it works, but the full source is below.

The gem provides a cli for some basic Fusion networking things. Run fusionNetwork -h for the usage. NOTE: the executable is “fusionNetwork” not “fusionNetworkUtil” even though the gem its called “FusionNetworkUtil.”

This script uses the docopt ruby gem to parse the parameters of the script (link). If you don’t use the gem, you’ll have to manually run sudo gem install docopt.

Docopt is pretty cool, it allows you to write a string to specify the usage, and it will parse the parameters into an object. This is the string that I pass to docopt for the usage:

As you can see, there’s just some really easy parameters. --stop, --start and --restart (-r) will start, stop and restart the network using the commands from the beginning of the post:

Here’s a post explaining what all those system start and system stop lines are doing.

There’s also the --edit (-e) and --dhcp (-d) commands. Those are --edit for editing the NAT configuration (maybe someday I’ll change it to –NAT). And --dhcp for editing the dhcp config.

Those parameters will open the NAT or dhcp config files, it will try and open it with your VISUAL editor, then your EDITOR, and finally fall back to using vim as a last resort.

The whole script looks like this.

Leave a Comment

Your email address will not be published. Required fields are marked *