I have just started testing Ubuntu 18.04 . The first thing I noticed was how different it handles network interfaces. The way Ubuntu manages network interfaces has completely changed.
Have you heard of NetPlan? Probably not, if you have, then you’re a step ahead of many. NetPlan is a new network configuration tool introduced in Ubuntu 17.10 to manage network settings.
It can be used write simple YAML description of the required network interfaces with what they should be configured to do; and it will generate the required configuration for a chosen renderer tool.
This new tool replaces the static interfaces (/etc/network/interfaces) file that had previously been used to configure Ubuntu network interfaces. Now you must use /etc/netplan/*.yaml to configure Ubuntu interfaces.
The new interfaces configuration file now lives in the /etc/netplan directory. There are two renderers. NetworkManager and networkd.
NetworkManager renderer is mostly used on desktop computers and networkd on servers. If you want NetworkManager to control the network interfaces, use NetworkManager as the renderer, otherwise use networkd.
Netplan configuration files are stored in the /etc/netplan directory and have the extension .yaml. You’ll probably find one or two YAML files in this directory.
The network configuration file will differ from setup to setup. Some may be named 01-netcfg.yaml, 50-cloud-init.yaml, etcs.
Below is a sample file for a network interface using networkd as renderer using DHCP. Networkd uses the command line to configure the network interfaces.
sudo nano /etc/netplan/*.yaml
You should see a similar DHCP server for servers like the one below:
network: ethernets: enp0s3: dhcp4: true renderer: networkd version: 2
On Desktops, you may see something like the one below:
network: renderer: NetworkManager version: 2
Static IP Addresses with Networkd
To configure a static IP address using the new NetPlan tool on Ubuntu server, the file should look similar to the content below.
Run the commands below to open the network configuration file.
sudo nano /etc/netplan/*.yaml
Then change the dhcp4 value to no, then configure the static IP address details, including DNS and Gateway addresses.
network: ethernets: enp0s3: addresses: 192.168.1.2/24 dhcp4: false gateway4: "192.168.1.1" nameservers: addresses: - "22.214.171.124" - "126.96.36.199" renderer: networkd version: 2
When you’re done editing the file, save it and exit.
Run the commands below to apply your changes.
sudo netplan apply
To validate that your changes are apply, run the commands below to view the IP address configuration detals.
ip addr show dev enp0s3
It should display similar lines like the one below:
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 08:00:27:e0:e9:4d brd ff:ff:ff:ff:ff:ff inet 192.168.1.1/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s3 valid_lft 976sec preferred_lft 976sec inet6 fe80::2aa0:522f:4f82:8d5b/64 scope link noprefixroute valid_lft forever preferred_lft forever
You will want to make sure that the file meets YAML code indent standards. If not probably indented, you’ll get an error.
For more about NetPlay, visit this site.
Congratulations! You’ve just successfully configured static IP addresses on Ubuntu servers.
You may also like the post below: