Home Linux Networking How To Configure IP Address In Ubuntu 18.04 LTS

How To Configure IP Address In Ubuntu 18.04 LTS

By sk
Published: Updated: 56.6K 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:

Default Network configuration file in Ubuntu 18.04
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 in Ubuntu 18.04
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 in Ubuntu
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.


Heads Up: We updated this guide with more methods to configure static IP address in latest Ubuntu versions. Please check the following guide for more details.


You May Also Like

20 comments

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
Gh0st December 10, 2020 - 11:50 pm

What terminal emulator are you using? it looks cool

Reply
sk December 11, 2020 - 11:14 am

Deepin Terminal.

Reply
1 2

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. By using this site, we will assume that you're OK with it. Accept Read More