Ubuntu 18.04: Network Configuration Utility

Prior to version 18.04, network configurations have been via these commands:

sudo vim /etc/network/interfaces 
sudo systemctl restart networking
# OR
sudo /etc/init.d/networking restart

Starting with Ubuntu 18.04, Netplan is the new tool. YAML is the language. Everyone is now well versed in this way of doing things to stay relevant with Linux, especially Ubuntu. Here is the sequence of commands:

Create a new file in the netplan directory:

Discover network interfaces of current system

kimconnect@nuc:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether b0:35:9f:11:28:a8 brd ff:ff:ff:ff:ff:ff
inet brd scope global dynamic noprefixroute wlp2s0
valid_lft 86125sec preferred_lft 86125sec
inet brd scope global secondary noprefixroute wlp2s0
valid_lft forever preferred_lft forever
inet6 fe80::2b6:9cdb:4687:53c3/64 scope link noprefixroute
valid_lft forever preferred_lft forever

Create a new file inside the netplan directory

vim /etc/netplan/wlp2s0.yaml

Insert this content (be mindful of precise indentation)

version: 2
renderer: networkd
addresses: []
dhcp4: true
addresses: [,]
# since sudo command was required, this error occurs:
"/etc/netplan/wlp2s0.yaml" E212: Can't open file for writing
# Press Esc > Shift + : > then type this to save in vim without exiting
:w !sudo tee %

Verify that file now exists

kimconnect@nuc:~$ ls /etc/netplan
01-network-manager-all.yaml wlp2s0.yaml

Attempt to apply changes. If there’s any error, this message would appear

kimconnect@nuc:~$ sudo netplan apply
/etc/netplan/wlp2s0.yaml:1:1: Error in network definition: unknown key 'nameservers'

To edit the file and correct things, run the same edit command as a sudoer

sudo vim /etc/netplan/wlp2s0.yaml

Repeat issuing the sudo netplan apply command after every edit to ensure that there are no errors.

Posted on Categories Linux

Leave a Reply

Your email address will not be published. Required fields are marked *