jjfc

jjfc

Netplan Network Configuration

Introduction#

Typically, the default setting for Ubuntu is to automatically obtain an IP address through a DHCP server, which is very useful for desktop systems as it requires no changes.

However, it is always recommended to assign a static IP address for Ubuntu servers, as this static IP address will remain unchanged after a reboot.

Ubuntu 17.10 and later versions use "Netplan" as the default network management tool. Therefore, configuring an IP address on Ubuntu 20.04 is different from older versions of Ubuntu.

In this article, we will describe how to configure a static IP address in an Ubuntu 20.04 server. This also applies to Ubuntu 18.04, referring to the use of the Netplan tool to configure the network in Ubuntu 18.04.

What is Netplan#

Netplan is a utility developed by Canonical (Ubuntu) that allows for easy network configuration on Linux systems. It is based on YAML configuration, which greatly simplifies the network configuration process.

To configure a network interface, simply create a YAML description for the desired network interface, and Netplan will generate all the necessary configurations for the selected renderer tool.

You can find the Netplan network configuration files in “/etc/netplan/*.yaml”. Netplan currently supports the following backend renderers, such as “NetworkManager” and “Systemd-networkd”.

NetworkManager is typically used on desktops, while Systemd-networkd is used on servers.

Disable Network Manager and Enable systemd-networkd#

First, run the following commands to disable NetworkManager:

sudo systemctl stop NetworkManager
sudo systemctl disable NetworkManager
sudo systemctl mask NetworkManager

Next, start and enable systemd-networkd:

sudo systemctl unmask systemd-networkd.service
sudo systemctl enable systemd-networkd.service
sudo systemctl start systemd-networkd.service

Configure Netplan#

To configure the DNS server in Ubuntu 22.04, edit the netplan configuration file and add the following content:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: yes
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

In the example above, we added Google DNS servers (8.8.8.8 and 8.8.4.4) as DNS resolvers. You can change this to DNS servers that suit your network environment.

Apply the changes:

sudo netplan apply

Now, you have successfully configured a static IP address and DNS server on your Ubuntu 22.04 server.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.