This page looks best with JavaScript enabled

Setting a Static IP Address on Ubuntu Server 22.04

 ·  ☕ 2 min read

Ubuntu Server 22.04 uses a utility called ‘netplan’ for networking. To set a static IP we need to edit the config file.

In the terminal, go to the netplan config file location:

1
cd /etc/netplan/

The file should be called 00-installer-config.yaml. To edit it we need to run nano as root so we can make changes to it.

1
sudo nano /etc/netplan/00-installer-config.yaml

The static IP config should look similar to this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
network:
  renderer: networkd
  ethernets:
    eth0:
      addresses:
        - 192.168.10.5/24
      nameservers:
        addresses: [1.1.1.1,8.8.8.8]
      routes:
        - to: default
          via: 192.168.1.1
  version: 2
  • eth0: is the name of my network interface - yours may differ.
  • Under addresses: is the static IP to set, you’ll need to use CIDR notation, so /24 is 255.255.255.0.
  • DNS servers are configured under nameservers: multiple servers should be command separated.
  • The default gateway is set under routes: and - to: default.

Save the file with CTRL + O and press enter to overwrite the existing file.
Exit with CTRL + X

To apply the changes run the following command:

1
sudo netplan apply

To confirm the settings, run the following to see the current IP:

1
ip addr show eth0

run the following to see the default gateway:

1
ip route show

And now you know, and knowing is half the battle.

Support My Work

If you would like to support me, please check out the link below.

If you have any questions or comments please leave them below.

-Mike

Share on
Support the author with