1. To configure a static IP address on your Ubuntu server you need to find and modify a relevant netplan network configuration file. See the above section for all possible Netplan configuration file locations and forms. For example, you might find there is a default netplan configuration file called 01-netcfg.yaml
with the following content instructing the networkd
daemon to configure your network interface via DHCP:
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
2. To set your network interface enp0s3
to static IP address 192.168.1.222
with gateway 192.168.1.1
and DNS server as 8.8.8.8
and 8.8.4.4
replace the above configuration with the one below.
WARNING
You must adhere to a correct code indent for each line of the block. In other words, the number of spaces before each configuration stanza matters. Otherwise, you may end up with an error message similar to:
Invalid YAML at //etc/netplan/01-netcfg.yaml line 7 column 6: did not find expected key
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: no
addresses: [192.168.1.222/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]
3. Once ready apply the new Netplan configuration changes with the following commands:
$ sudo netplan apply
In case you run into some issues execute:
$ sudo netplan --debug apply