Sunday, July 15, 2012

Static IPs for Ubuntu Server 12.04 guest in VMware Player

If you want your Ubuntu 12.04 guest VM to have a static IP, you can do the following:
  • Use the NAT mode in the VMware network settings (Virtual Machines > Virtual Machine Settings > Network Adapter > NAT)
  • In Ubuntu, edit /etc/network/interfaces with your favourite editor (I use VIM) to add some configuration lines — check out the "Static IP Address Assignment" section in  https://help.ubuntu.com/12.04/serverguide/network-configuration.html 
  • For example, I use the following:
    auto eth0
    iface eth0 inet static
    address 192.168.111.111
    netmask 255.255.255.0
    network 192.168.111.0
    broadcast 192.168.111.255
    gateway 192.168.111.2
    dns-nameservers 192.168.111.2
  • Make sure that the Virtual Network Editor settings for VMnet8 (NAT) match your static ip, e.g., the Subnet IP is consistent with your static IP. If you are running VMware Player and don't already have the Virtual Network Editor installed, take a look at this post for instructions on how to install it for free. 
  • Most importantly, make sure the gateway / DNS relay is set to 192.168.111.2. I had tried changing it to 192.168.111.1, but that address is reserved for the VMnet8 adapter. It took me a while to figure out how VMware networking works, but it all made sense after reading this fantastic primer by RedNectar! Incidentally, the last IP in your DHCP range is reserved for the DHCP server, so don't set it to that either.
Have fun!