Home FAQ How To Configure IP Address In Ubuntu 18.04 LTS
configure ip address in ubuntu 18.04

How To Configure IP Address In Ubuntu 18.04 LTS

By sk
10615 Views

The method of configuring IP address on Ubuntu 18.04 LTS is significantly different than the older methods. Unlike the previous versions, the Ubuntu 18.04 uses Netplan utility. It is a new command line network configuration utility, to configure IP address. Netplan has been introduced by Ubuntu developers in Ubuntu 17.10. In this new approach, we no longer use /etc/network/interfaces file to configure IP address rather we use a YAML file. The default configuration files of Netplan are found under /etc/netplan/ directory. In this brief tutorial, we are going to learn to configure static and dynamic IP address in Ubuntu 18.04 LTS server and desktop editions.

Configure Static IP Address In Ubuntu 18.04 LTS Server

Let us find out the default network configuration file:

$ ls /etc/netplan/
50-cloud-init.yaml

As you can see, the default network configuration file is 50-cloud-init.yaml and it is obviously a YAML file.

Now, let check the contents of this file:

$ cat /etc/netplan/50-cloud-init.yaml

I have configured my network card to obtain IP address from the DHCP server when I am installing Ubuntu 18.04, so here is my network configuration details:

configure network

Figure 1 - Default Network configuration file in Ubuntu 18.04

As you can see, I have two network cards, namely enp0s3 and enp0s8, and both are configured to accept IPs from the DHCP server.

Before making any changes in this file, let us backup it.

$ sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak

Let us now configure static IP addresses to both network cards.

To do so, open the default network configuration file in any editor of your choice.

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

Now, update the file by adding the IP address, netmask, gateway and DNS server. For the purpose of this guide, I am going to use the following network settings.

  • IP address for enp0s3 : 192.168.225.50
  • IP address for enp0s8 : 192.168.225.51
  • Gateway : 192.168.225.1
  • Netmask : 255.255.255.0
  • DNS servers : 8.8.8.8 and 8.8.4.4.

After configuring all network settings, here is how the contents of 50-cloud-init.yaml file looks like.

configure static ip

Configure static ip in Ubuntu 18.04

Please mind the space between the lines. Don't use TAB key to align the lines as it will not work in Ubuntu 18.04. Instead, just use SPACEBAR key to make them in a consistent order as shown in the above picture.

Also, we don't use a separate line to define netmask (255.255.255.0) in Ubuntu 18.04. For instance, in older Ubuntu versions, we configure IP and netmask like below:

address = 192.168.225.50
netmask = 255.255.255.0

However, with netplan, we combine those two lines with a single line as shown below:

addresses : [192.168.225.50/24]

Once you're done, Save and close the file.

Apply the network configuration using command:

$ sudo netplan apply

If there are any issues, run the following command to investigate and check what is the problem in the configuration.

$ sudo netplan --debug apply

Output:

** (generate:1556): DEBUG: 09:14:47.220: Processing input file //etc/netplan/50-cloud-init.yaml..
** (generate:1556): DEBUG: 09:14:47.221: starting new processing pass
** (generate:1556): DEBUG: 09:14:47.221: enp0s8: setting default backend to 1
** (generate:1556): DEBUG: 09:14:47.222: enp0s3: setting default backend to 1
** (generate:1556): DEBUG: 09:14:47.222: Generating output files..
** (generate:1556): DEBUG: 09:14:47.223: NetworkManager: definition enp0s8 is not for us (backend 1)
** (generate:1556): DEBUG: 09:14:47.223: NetworkManager: definition enp0s3 is not for us (backend 1)
DEBUG:netplan generated networkd configuration exists, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:device enp0s3 operstate is up, not replugging
DEBUG:netplan triggering .link rules for enp0s3
DEBUG:device lo operstate is unknown, not replugging
DEBUG:netplan triggering .link rules for lo
DEBUG:device enp0s8 operstate is up, not replugging
DEBUG:netplan triggering .link rules for enp0s8

Now, let us check the Ip address using command:

$ ip addr

Sample output from my Ubuntu 18.04 LTS:

Check IP address

Check IP address in Ubuntu 18.04

Congratulations! We have successfully configured static IP address in Ubuntu 18.04 LTS with Netplan configuration tool.

For more details, refer the Netplan man pages.

$ man netplan

Configure Dynamic IP Address In Ubuntu 18.04 LTS Server

To configure dynamic address, just leave the default configuration file as the way it is. If you already have configured static IP address, just remove the newly added lines and make the YAML file look like exactly as shown in the figure 1 in the previous section.

Configure Static and Dynamic IP Address In Ubuntu 18.04 LTS Desktop

Configuring IP address in Ubuntu desktop systems doesn't require much technical knowledge.

Click on the drop down box on the top panel of your Ubuntu desktop and choose Settings icon from the lower left.

Launch System's settings from top panel

Launch System's settings from top panel

Click on Network tab on the left pane and then click on the gear button under the Wired section. This will open your network card settings window. Navigate to IPv4 section, choose Manual method and finally enter your IP address, Netmask, Gateway etc. Once you have entered all details, click Apply button to save the changes.

Configure Static IP Address In Ubuntu 18.04 LTS Desktop

Configure Static IP Address In Ubuntu 18.04 LTS Desktop

To configure Dynamic ip address, just choose the "Automatic (DHCP)" option in the above section.

That's all. You know now how to configure static and dynamic IP in Ubuntu 18.04 LTS server and desktop editions.

Personally, I don't like this new YAML method in Ubuntu server. The old method is much easier and better. If I don't correctly align the lines, the network settings doesn't work. In the old method, I don't need to align the lines in proper order.

What about you? Did you find it easy or hard? Let me know in the comment section below.

Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

18 comments

LLyn0 November 25, 2018 - 11:27 pm

Thank you for brief review, but I disagree that this method is more complicated than the old one. If you’re familiar with yaml, this way is better.

Reply
sk November 26, 2018 - 2:23 pm

I get used to the old method, so I find the Netplan method is bit difficult. I am not familiar with YAML and I had to spend some time to figure out why my network settings isn’t not working.

Reply
Lars van Egmond April 12, 2019 - 2:15 pm

Thank you SK for sharing this information !

Reply
sk April 12, 2019 - 2:18 pm

You’re welcome, mate!

Reply
Fábio May 1, 2019 - 2:04 am

Very nice explanation! And the point of indenting the lines is really important. Thank you!

Reply
jason May 18, 2019 - 2:34 am

Hi, thank you for this.
I cant help notice that the changes will not persist ad it gets overwritten. Anyone have any advice.

kind regards

Reply
Jason P June 18, 2019 - 7:36 am

I am trying to set up a static IP on Ubuntu 18.04 server, but I continue to get an error (ModuleNotFound) for netifaces. It is installed on the server, but I can’t see how to connect the two to apply the new yaml file. I can’t seem to find much on the topic. Hoping someone could help.

Reply
Simon August 11, 2019 - 10:54 am

I don’t know why you would not just allocate the address in the DHCP server.

Reply
Ron Crowder August 13, 2019 - 10:41 pm

Sometimes if you are setting up a server you want a specific address assigned to it outside of the client machines.

Reply
jeff g October 9, 2019 - 6:53 pm

This is exactly why everyone hates linux… I work in IT and it is so frustrating to keep up with these stupid changes all the time with each new release, it gets even worse when you have different versions in your environment… Things that take 1-2 minutes to do in Windows end up taking up half of your day and with no proper documentation online…

Reply
Lolito October 10, 2019 - 12:31 am

Thank you bro’, you just saved my life

Reply
Segun October 16, 2019 - 10:16 am

Why do we always have to do simple things the hard way?. network configuration in Ubuntu 18.04 is simply lame, and up till this moment, nobody has been able to indicate the advantage of Netplan over the previous method of network configuration in 16.04 and earlier. Jeff g, i agree with you, this is why people hate Linux.

Imagine network settings that should take few minutes is now a stringent and fragile process that could ruin your entire OS. No special advantage that i know of. This is so lame.

Reply
Jordan November 23, 2019 - 12:06 am

Can you please show how to add more than one IP address to the system?

Reply
Jordan November 23, 2019 - 12:07 am

I agree, these are chief reasons Windows Server is becoming more common than Linux with enterprise and industry level work.

Reply
niels andersen December 30, 2019 - 7:02 pm

this is brilliant, so much eacier to deploy config with ansible or policy, and so much easier to remove config.

There may be a “hidden” address in the 50-cloud.yaml file from the installer. Double check that if you get funny issues.

Reply
Jorry January 5, 2020 - 3:17 am

How does it work when the subnet is not 255, for example a /30 ?

I don’t understand how it can know it’s subnet with just this information.

Reply
aisha July 8, 2020 - 12:18 am

perfectly tutorial, it works for me follow these steps above. thank you

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More