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:
|
|
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.
|
|
The static IP config should look similar to this:
|
|
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
is255.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:
|
|
To apply the changes run the following command:
|
|
To confirm the settings, run the following to see the current IP:
|
|
Run the following to see the default gateway:
|
|
Run the following command to see the DNS servers being used:
|
|
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