On ubuntu 18.04 LTS, the network configuration is now managed by NetPlan by default. The network configuration files are saved in /etc/netplan/ directory with a .yaml extension.
When you install the Ubuntu 18.04 server version, the default NetPlan yaml file is located at /etc/netplan/50-cloud-init.yaml, by default it uses DHCP method to get ip address configuration for the interface.
What is NetPlan?
Netplan is a utility for easily configuring networking on a linux system. You simply create a YAML description of the required network interfaces and what each should be configured to do.
In this quick tutorial, we are going to show you how to setup a static IP address on ubuntu 18.04 LTS using NetPlan tool
– First, use the below command to print a list of all the available network interfaces. In this case, the name of the interface is
$ ip link 1: lo:
mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 3: enp3s0: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether 56:00:00:60:20:0a brd ff:ff:ff:ff:ff:ff
– Let’s rename the 50-cloud-init.yaml and create our new configuration file named 01-netcfg.yaml , or you can even make changes on the 50-cloud-init.yaml like the below example.
In this example we are going to configure a static IP address, where the IP is 192.168.1.151, subnet mask 24 (255.255.255.0), default gateway is 192.168.1.254 and nameservers 192.168.1.254 and 18.104.22.168 on the network interface enp3s0 .
$ sudo mv /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.org $ sudo vi /etc/netplan/01-netcfg.yaml network: version: 2 renderer: networkd ethernets: enp3s0: addresses: - 192.168.1.151/24 gateway4: 192.168.1.254 nameservers: search: [yallalabs.com, yallalabs.local] addresses: [192.168.1.254, 22.214.171.124]
– Save the file and exit. Then apply the recent network changes using following netplan command.
$ sudo netplan apply
You have learned how to assign a static IP address on your Ubuntu 18.04 machine using the Command Line. You might want to check the following guides:
- How to Setup Skype on Ubuntu 18.04 LTS Bionic Beaver
- Install Sublime Text 3 on Ubuntu 18.04 LTS Bionic Beaver
- Build / Install Python 3.7 on Ubuntu 18.04 LTS Bionic Beaver
- How to Install Google Chrome Web Browser on Ubuntu 18.04
We hope this tutorial was enough Helpful. If you need more information, or have any questions, just comment below and we will be glad to assist you!