I’m using VMware Fusion for development (I have a Mac but I run Ubuntu in a virtual machine). I’m usually SSHd in to the vm from several terminals.
Every now and then, the IP address of the virtual machine changes – and I have to update various tools that point to it. I can’t quite figure out the circumstances under which this happens – sometimes it’s when I switch from WiFi to Ethernet, but other times it just seems to happen for no reason at all. It’s only every week or so (I usually leave my machine plugged in to Ethernet).
Any idea how I can convince VMware Fusion to just stick with one IP address for my VM?
Set your VM to use a static IP address instead of one assigned by DHCP.
- Open the Network Connections configuration window. You can do this by right-clicking on the network connection icon on the top bar, or through different menu options depending on your Ubuntu version.
- Choose your connection and hit Edit. Go to the IPv4 Settings tab.
- Switch the Method dropdown from “Automatic (DHCP)” to “Manual”. Open up a terminal and use the `ifconfig` and `route` utilities to find your current IP address and default gateway. Choose an IP address on the same subnet (mine look like 192.168.58.3), a 255.255.255.0 netmask, and the default gateway (mine is 192.168.58.2). The DNS server is is the same as the default gateway. Enter these values into the manual connection configuration and hit Save. You may need to disable and re-enable networking for it to start working.
The above assumes you’re running desktop Ubuntu. The process is similar for other operating systems.
After assigning a static IP address, I give the VMs an entry in my host machine’s /etc/hosts file. That becomes a place you can look to find the next unassigned IP.