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:
/etc/netplan
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:
/etc/netplan/00-installer-config.yaml |
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:
/etc/netplan/99_config.yaml |
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 8.8.8.8 and 8.8.4.4. 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: [8.8.8.8, 8.8.4.4]
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
Changing Hostname
If you want to change your hostname just update it in these two files:
- /etc/hostname
- /etc/hosts