This page looks best with JavaScript enabled

Setting a Static IP Address on Ubuntu Server 24.04/22.04 LTS

 ·  ☕ 2 min read

Ubuntu Server 24.04/22.04 LTS 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 if it doesn’t exist then the following will create it. We need to run a text editor, in this case, 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.253
  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

Run the following command to set the permissions for the config file:

1
sudo chmod 0600 /etc/netplan/00-installer-config.yaml

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

Run the following command to see the DNS servers being used:

1
resolvectl status

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