Modern Ubuntu server releases use netplan to manage network settings. This guide covers configuring a static IP address on Ubuntu Server, a typical first step when building a new server to ensure communication remains available even when DHCP services are unavailable.
Check Current Network Configuration
Default Ubuntu installations typically use DHCP for IP configuration. Verify the active network adapter name and current settings with the ip command:
ip aThe output shows all network interfaces. Look for the interface with an assigned IP address:
root@server45 ~ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
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 noprefixroute
valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 30:9c:23:dd:ee:ff brd ff:ff:ff:ff:ff:ff
altname enp0s31f6
altname enx309c23d35430
inet 188.9.51.22/32 scope global eno1
valid_lft forever preferred_lft forever
inet6 fe80::329c:23ff:aaaa:bbbb/64 scope link proto kernel_ll
valid_lft forever preferred_lft forever
6: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN group default qlen 1000
link/none
inet 172.16.29.129/24 scope global wg0
valid_lft forever preferred_lft forever
inet6 fd00::131/64 scope global
valid_lft forever preferred_lft forever
In this example, the active interface is eno1. The loopback interface (lo) and VPN interface (wg0) can be ignored.
Query the DHCP lease information for the active interface:
netplan ip leases eno1Replace eno1 with your actual interface name. This output displays the current DHCP-assigned address, netmask, gateway, DNS servers, and domain name. You will need this information when configuring the static IP address.
Check the existing netplan configuration file. On Ubuntu 22.04, the installer creates /etc/netplan/00-installer-config.yaml, if there are other files in this folder, they need to be considered, too:
cat /etc/netplan/00-installer-config.yamlThe default configuration typically shows only DHCP enabled for IPv4. Note the indentation structure, as YAML files require precise formatting.
Configure Static IP Address
Create a backup of the original configuration file:
cp /etc/netplan/00-installer-config.yaml ~/00-installer-config.yaml.bakThe tilde (~) represents the current user’s home directory, ensuring the backup is stored outside /etc/netplan where it will not be parsed during network service restarts.
Edit the netplan configuration file with your preferred text editor:
sudo nano /etc/netplan/00-installer-config.yamlReplace the contents with a static IP configuration. Use values appropriate for your network. This example shows a configuration for the 172.16.29.0/24 network:
network:
version: 2
ethernets:
eno1:
dhcp4: no
dhcp6: no
addresses:
- 172.16.29.40/24
routes:
- to: default
via: 172.16.29.1
nameservers:
addresses:
- 172.16.29.30
- 172.16.29.31
search:
- home.domainReplace the interface name (eno1), IP address (172.16.29.40/24), gateway (172.16.29.1), DNS servers, and search domain with values from your network administrator or from the DHCP lease information gathered earlier. Ensure indentation is exact, as YAML syntax errors will prevent the configuration from applying.
Set appropriate permissions on the configuration file:
sudo chmod 600 /etc/netplan/00-installer-config.yamlValidate and Apply Configuration
Validate the YAML syntax before applying the configuration:
sudo netplan generateThis command checks for syntax errors and reports any problems. Common errors include incorrect indentation or typos in key names. If errors appear, edit the file again to correct them, then run netplan generate again until it completes without errors.
Apply the new network configuration:
sudo netplan applyThis command activates the static IP settings. If you changed the IP address, your current SSH session may disconnect. Reconnect using the new IP address.
Verify Network Configuration
After reconnecting to the server, verify the new IP address is active:
ip aThe active interface should show the configured static IP address. The word “dynamic” should no longer appear in the output, confirming DHCP is disabled.
Verify DNS configuration with resolvectl:
resolvectl statusThis output shows the configured DNS servers and search domain for each interface. Verify the values match your netplan configuration.
Test network connectivity and DNS resolution by pinging a local hostname:
ping server99If the search domain is configured correctly, the short hostname should resolve to a fully qualified domain name. Test external connectivity and DNS:
ping google.comSuccessful responses confirm the static IP, gateway, and DNS settings are all functioning correctly.
Troubleshooting DNS Search Domains
In some cases, the DNS search domain configured in netplan may not function correctly. If short hostname resolution fails, manually configure the search domain in systemd-resolved:
sudo nano /etc/systemd/resolved.confUncomment the Domains line and add your search domain:
Domains=home.domainRestart the systemd-resolved service to apply the change:
sudo systemctl restart systemd-resolvedAdvanced Configuration
For systems with multiple network interfaces or dual-stack IPv4/IPv6 networks, the netplan configuration becomes more complex. This example shows a configuration with two interfaces and both IPv4 and IPv6 addressing:
network:
version: 2
ethernets:
eth0:
accept-ra: false
addresses:
- 2A03:B0C0:0003:1234:1234:1234:15F3:B001/64
- 17.172.14.79/20
- 10.19.0.5/16
match:
macaddress: da:16:ff:aa:bb:ff
mtu: 1500
nameservers:
addresses:
- 67.207.67.3
- 67.207.67.2
search: [mydomain.com]
routes:
- to: ::/0
via: 2a03:b0c0:3:d0::1
- to: 0.0.0.0/0
via: 167.172.160.1
set-name: eth0
eth1:
addresses:
- 10.135.88.123/16
match:
macaddress: 32:07:23:91:99:51
mtu: 1500
nameservers:
addresses:
- 67.207.67.3
- 67.207.67.2
search: [myotherdomain.com]
set-name: eth1This configuration demonstrates multiple IP addresses on a single interface, separate IPv4 and IPv6 default routes, interface matching by MAC address, and MTU settings. Adjust all values to match your specific network requirements.
AI assistance is used on this site for language, formatting, and turning research into a consistent template. It is not used to perform the underlying research or verify technical claims. Every command, configuration, and step in this post is tested by hand before publication.