Ubuntu Server 20.04 LTS - Basic Network Configuration with netplan

Post a Comment
Ubuntu Server 20.04 LTS using netplan as a default network configuration tools. It is coming without net-tools, basic command like ifconfig, route, arp, netstat can not be found anymore without manually install net-tools package with apt install net-tools. Default network configuration package replace by netplan.

Netplan already replaced net-tools since Ubuntu 18.04 LTS or maybe before. It is between 16.04 and 18.04 maybe, because I am only using LTS version of Ubuntu.

Netplan will read the network configuration file with .yaml extension from /etc/netplan/ folder. It is work just like /etc/network/interfaces on the previous version of network configuration tools on Ubuntu. The only thing I hate is, there is no ifup / ifdown to hook script when an interface become up or down and have to install network-dispatcher to have it. I hope it will be there soon

This time we will only learn the basic network configuration using netplan as network configurator. We will only cover about assigning network address via DHCP, manually assigning static IP Address, gateway and DNS server to Ubuntu Server 20.04 LTS. There still many thing netplan can do like split routing, policy routing with metric, creating vlan, and so on.

Ubuntu Server 20.04 LTS - Basic Network Configuration with netplan

Checking available network interfaces
 ip addr
Remember the network interfaces name, we need this later on netplan configuration file. (I really miss the time when we just need to remember eth0, eth1, and so on...)
Ubuntu Server 20.04 LTS - Basic Network Configuration with netplan
Checking available network interfaces with 'ip addr'
Configuring dynamic address (DHCP) on interface

- Edit netplan .yaml network configuration file with nano

 sudo nano /etc/netplan/00-installer-config.yaml
The name of the file can be anything with .yaml extension. Use ls /etc/netplan/ to find out yaml filename or you can empty the directory and create your own yaml configuration file.
Ubuntu Server 20.04 LTS - Basic Network Configuration with netplan
Edit netplan .yaml network configuration file with nano
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: yes
Your config file should be like that. It is configure the enp0s3 network interface to listen to dhcp server and obtaining network address from the dhcp server.

In netplan yaml configuration file, indentation is really important. From example above, network: have no space before it, while version, renderer and ethernets using 2 spaces before them, 4 spaces before enp0s3 and 6 spaces before dhcp4.

Also note there is a space after colon ( : ) on every parameter. The indentation need to be consistent, if you are using 1 space, every indentation must be increase with 1 space too.

To quit nano, press CTRL+x the y and Enter.

- Apply the configuration and check the IP Address

netplan apply
apply network configuration
ip addr
check the ip address (no ifconfig)
ip route
check the ip gateway (no route -n)
resolvectl status
check the DNS server ip address (I miss the old /etc/resolv.conf)
Ubuntu Server 20.04 LTS - Basic Network Configuration with netplan
Apply the configuration and check the IP Address
Manually assigning static IP Address, gateway and DNS servers

- Edit netplan .yaml network configuration file with nano

 sudo nano /etc/netplan/00-installer-config.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      addresses:
        - 10.0.2.1/24
      gateway4: 10.0.2.2
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]
This configuration will assign to interface enp0s3:
IP address: 10.0.2.1
Gateway: 10.0.2.2
DNS Server: 8.8.8.8 and 1.1.1.1
Ubuntu Server 20.04 LTS - Basic Network Configuration with netplan
Manually assigning static IP Address, gateway and DNS servers
Save the file and quit nano by pressing CTRL+x then y and Enter

- Apply the configuration and check the IP Address

netplan apply
ip addr
ip route 
resolvectl status
Ubuntu Server 20.04 LTS - Basic Network Configuration with netplan
Apply the configuration and check the IP Address
Just like the other posts, I have prepared a Youtube video for you who don't really into reading about Ubuntu Server 20.04 LTS - Basic Network Configuration with netplan. Enjoy!

Related Posts

    Post a Comment

    Subscribe Our Newsletter