How to Configure Static IP Address on Ubuntu 20.04

In most cases IP addresses are configured by DHCP server running on yore router and they are assigned dynamically. But in some specific cases you need to have always the same IP.

Netplan

Netplan is the default IP address management tool. It is used from Ubuntu version 17.10. We can configure it in command line, but it set up  using GUI.

Command line

Network interface

First we need to know, what network interfaces are available in our device and specify, which one will we use.
Enter this command in command line:

ip link

Command prints out all network interfaces in our device.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 9c:5c:8e:bb:ea:50 brd ff:ff:ff:ff:ff:ff
altname enp0s31f6
3: enp7s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 9c:5c:8e:bc:ad:a0 brd ff:ff:ff:ff:ff:ff
4: wlp1s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DORMANT group default qlen 1000
link/ether 64:5d:86:b8:3e:ae brd ff:ff:ff:ff:ff:ff
altname wlp0s20f3
5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default
link/ether 02:42:19:d5:55:eb brd ff:ff:ff:ff:ff:ff

Interfaces are named differently, we will be interested in those, which have the en or wl prefix.

en = ethernet
wl = wireless p# = PCI bus number s# = slot number f# = function index

In this example we will configure enp7s0 interface, which is a cable connection to a PC network.

Configuration

All configuration files are located in /etc/netplan directory and as configuration files uses YAML. We will make our changes in file 00-installer-config.yaml.

sudo vi /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
enp7s0:
dhcp4: yes
version: 2

Static IP address is configured by adding new lines:

# This is the network config written by 'subiquity'
network:
ethernets:
enp7s0:
dhcp4: no
addresses:
- 192.168.1.2/24
gateway4: 192.168.1.1
nameservers:
addresses: [1.1.1.1, 8.8.8.8]
version: 2

Close the file and restart service.

sudo netplan apply

Verify the IP address settings:

ip addr show dev enp7s0
3: enp7s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 9c:5c:8e:bc:ad:a0 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.2/24 brd 192.168.1.255 scope global noprefixroute enp7s0
valid_lft forever preferred_lft forever
inet6 fe80::2498:76d0:f77d:5c47/64 scope link noprefixroute
valid_lft forever preferred_lft forever

GUI

1. Open context menu in upper right corner:

Ako nastaviť statickú IP adresu v Ubuntu 20.04

2. Click on the settings icon of the chosen network interface:

Ako nastaviť statickú IP adresu v Ubuntu 20.04

3. Fill in the correct IP address and click Apply.

Ako nastaviť statickú IP adresu v Ubuntu 20.04