If you’re like me, you probably have a lot of virtual machines running on your computer. And if you’re like me, you probably want to set a static IP address for each one so you can easily connect to them.
Here’s a quick and easy guide on how to set a static IP address on an Ubuntu virtual machine.

Contents
Why you might need to set a static IP address on your Ubuntu VM
If you want to access your Ubuntu VM from a specific (static) IP address, you’ll need to set up a static IP address.
This is also useful if you want to run a server on your VM that is accessible from the internet.
There are two ways to set a static IP address on Ubuntu: using the GUI interface or the command line. We’ll show you both methods.
How to set a static IP address using the Ubuntu GUI
This tutorial explains how to set a static IP address on an Ubuntu system from the GUI and from the command line.
The process for setting a static IP address in Ubuntu is slightly different than it is in other Linux distributions, but not greatly so. We’ll go over both methods in this tutorial.
How to set a static IP address using the Ubuntu command line
Assuming you’re using Ubuntu Server 18.04, you can set a static IP address by following these steps:
- Edit the
/etc/netplan/01-netcfg.yaml
file and add the following lines, substituting the IP address, gateway, and DNS settings as appropriate for your network:network: version: 2 renderer: networkd ethernets: ens3: dhcp4: no addresses: [192.168.0.100/24] gateway4: 192.168.0.1 nameservers: addresses: [8.8.8.8, 8.8.4.4]
Note that theens3
interface may be named differently on your system - To find out what it’s called, run the
ifconfig
command and look for the interface that has an IP address assigned to it (usually this will beeth0
). - Also note that if your system has multiple network adapters (for example, if you’re using a virtual machine with both a “host only” adapter and a “NAT” adapter), you’ll need to configure each one separately in this file.
- Edit the
/etc/resolvconf/resolv.conf
file and add the following line, substituting the DNS server IP address as appropriate for your network::
nameserver
How to verify your static IP address is working
If you have set a static IP address on your Ubuntu VM, you can check if it is working by SSHing into the machine and running the following command:
ip addr
You should see an output like this:
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2:(vmnet8): mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ ether 00::11 brd ff::ff
inet 192.168.:11/24 brd 192.168... scope global vmnet8
valid_lft forever preferred_lft forever
This output shows that the static IP address we set (192.168.:11) is working as expected.
Conclusion
In conclusion, setting a static IP address on a virtual machine running Ubuntu is a fairly simple process.
You will need to edit the /etc/network/interfaces file and add your desired IP address, netmask, gateway, and DNS server information.
Once you have saved your changes and restarted your network interface, your new IP address should be assigned to your virtual machine.