Ubuntu Server 20.04 Static IP
We’re going to cover how to set up a static IP address on Ubuntu Server 20.04. Ubuntu has been using the Netplan network management tool by default since Ubuntu 17.10. This has replaced the use of the ifconfig command and the /etc/network/interfaces configuration file.
NOTE - If you are using Ubuntu cloud you might need to disable some extra things.
Depending on whether you are using the server or desktop system there should be a different backend system (renderer) in use by Netplan.
Two supported renderers for Netplan:
- NetworkManager ( mostly desktops )
- Systemd-networkd ( mostly servers with no GUI - Ubuntu Server by default )
Find your interface name. Use any one of the following commands:
ip a ip link sudo lshw -class network
My interface looked like this: enp0s3
The Netplan configs can be found here:
There should be at least one file in this directory and that will probably hold your current configuration. The file names can supposedly vary wildly.
I had only this file one file on a freshly installed system, yours might be different:
You could just configure this file directly or you could rename it first. You could also delete it and create a new config instead. The manual recommends using the following name:
I recommend renaming it like this:
mv /etc/netplan/00-installer-config.yaml /etc/netplan/99_config.yaml
It should have DHCP enabled by default and will look something like this:
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: true
Under your interface, set dhcp4 to no. Add one or more addresses. Define a gateway. Specify one or more DNS servers. To use Google’s DNS servers you can specify 188.8.131.52 and 184.108.40.206. This is helpful to avoid being blocked by your ISP.
IMPORTANT - Use the correct spacing in the config file.
Here is a working example with my network device:
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: no addresses: - 192.168.3.3/24 gateway4: 192.168.3.1 nameservers: addresses: [220.127.116.11, 18.104.22.168]
You can also specify domains to search by default.
nameservers: addresses: [192.168.3.10, 192.168.3.11] search: [domain1, domain2]
Apply the changes:
sudo netplan apply
Verify that the changes are in place:
ip addr show dev enp0s3
If you want to change your hostname just update it in these two files: