How To Configure IP Address In Ubuntu 18.04 LTS
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:
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 : 184.108.40.206 and 220.127.116.11.
After configuring all network settings, here is how the contents of 50-cloud-init.yaml file looks like.
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
** (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:
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.
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.
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.
How about you? Did you find it easy or hard? Let me know in the comment section below.