news
Serverspace has added a new Rocky Linux OS
WB
William Bell
June 3, 2020
Updated June 7, 2023

How to configure static IP address on Ubuntu 18.04

Ubuntu

Main idea of this article

The most often case of infrastructure organization today is automated settings assign via DHCP server cause no more needed on client side. But if you don't have DHCP - no panic. You may set IP address manually after this material reading.

Firstly, you should define the network interface which settings you are want to change. To see all network cards with theirs settings just run command below:

ip a

List All Active Network Interfaces on Ubuntu

In this output we've seen that our computer has three ethernet adapters. One of them is assigned to docker, other is loopback interface. So, our aim is ens33 network adapter. Let's go.

Since version 17.10 Ubuntu uses netplan tool to manage connectivity settings. This utility based on YAML synopsis rules. All settings are stored in /etc/netplan/*.yaml files.

So we should list all files in /etc/netplan/ directory:

ls /etc/netplan/

Set Static IP Address in Ubuntu 18.04

 

NOTE: If there are no files found you can re-build it to default system config:

sudo netplan generate

 

As we see, only 50-cloud-init.yaml file is present. To change connectivity settings we will edit it via text editor.

sudo nano /etc/netplan/50-cloud-init.yaml

Open the netplan configuration file

Let's find our adapter's name inside. By default, Ubuntu 18.04 is trying to get network settings from dedicated DHCP-node. Directive below is responsible for this:

dhcp4: true = dchp
Find your network interface nameTo modify this behavior just change the YAML-file like that:

As you can see there’s dhcp4: true = dchp for ipv4 is enabled

Some explains:

ens33 – interface name
dhcp4, dhcp6 – this sections are respective to the dhcp-properties for 4th and 6th IP-protocol versions.
addresses – static addresses "pointed" to the interface. (in CIDR format)
gateway4 – IPv4 address for default hope.
nameservers – IP addresses for servers which resolves DNS-queries.

NOTE: You must use spaces only, no tabs.

To apply changes just run this command:

sudo netplan apply

Apply the recent network changes

As we see, no error messages, everything is OK.

And finally, just see system settings again:

ip a

Check your ip configuration again

Congratulations! IP addresses config is fully consistent with YAML-file we modified.

Conclusion

After this instruction reading you may assign static IP addresses to your Ubuntu server.

Vote:
4 out of 5
Аverage rating : 4.8
Rated by: 12
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.