Netplan is a new command-line network configuration utility introduced in Ubuntu 17.10 to easily manage and configure network Settings in Ubuntu. It allows you to use YAML format description files to visualize the information that defines the network interface.

Netplan can use NetworkManager or Systemd-NetworkD’s network daemon as the kernel interface. The default Netplan description file is in /etc/netplan/*. Yaml. The Netplan description file uses the YAML syntax.

In Ubuntu 18.04, it is invalid to configure the management network interface in /etc/network/interfaces using the original ifupdown toolkit.

This article will show you how to configure static IP addresses, dynamic IP addresses, and DNS for network interfaces using Netplan in Ubuntu 18.04.

How Netplan works

Netplan’s official website: https://netplan.io/

Netplan automatically generates the configuration information required by the back-end network daemon based on the configuration information defined in the description file. The back-end network daemon then manages the network devices using the Linux kernel based on the configuration information.

Configure the network using Networkd

Systemd-networkd is a system daemon that manages network devices. It can detect and configure the status of network devices and create virtual network devices.

Before configuration, let’s take a look at the meanings of several common configuration items.

1. Enp0s5 Specifies the name of the network interface to be configured. Dhcp4 Determine whether to enable DHCP for IPv4. Dhcp6 Check whether DHCP is enabled for IPv6. 4. addresses Defines static IP addresses of network interfaces. Gateway4 Specifies the IPv4 address of the default gateway. 6. Nameservers Specifies the IP address of the DNS server.Copy the code

Use Networkd to configure dynamic IP addresses

After the Ubuntu 18.04 Server is installed, the default Netplan description file is /etc/netplan/50-cloud-init.yaml.

  • Example Modify the description file of Netplan

$ sudo vim /etc/netplan/50-cloud-init.yaml

network:
version: 2
renderer: networkd
ethernets:
enp0s5:
dhcp4: yes
dhcp6: yesCopy the code
  • Run the following command for it to take effect

$ sudo netplan applyCopy the code

Use Networkd to configure static IP addresses

  • Example Modify the description file of Netplan

$ sudo vim /etc/netplan/50-cloud-init.yaml network: renderer: networkd ethernets: enp0s5: addresses: -192.168.100.211/23 gateway4: 192.168.100.1 nameservers: addresses: [8.8.8.8, 8.8.4.4] Search: [] optional:true
version: 2Copy the code
  • Run the following command for the configuration to take effect

$ sudo netplan applyCopy the code

If you want to add an IPv6 address, add it in the addresses line. Separate multiple addresses with commas:

$ sudo vim /etc/netplan/50-cloud-init.yaml

network:
renderer: networkd
ethernets:
enp0s5:
addresses: [192.168.100.211/23, 'fe80:0:0:0:0:0:c0a8:64d3']
gateway4: 192.168.100.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
search: []
optional: true
version: 2Copy the code

Configure multiple nics using Networkd

If you want to configure multiple network cards at the same time, you only need to define multiple network devices in the Netplan description file.

$ sudo vim /etc/netplan/50-cloud-init.yaml

Configure enP0S3 as a dynamic IP address and enP0S5 as a static IP address.
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
dhcp6: no
enp0s5:
dhcp4: no
dhcp6: no
addresses: [192.168.100.211/23]
gateway4: 192.168.100.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]Copy the code

Configure the network using NetworkManager

NetworkManager is used to manage network devices on the desktop. If you use NetworkManager as the system daemon for network device management, NetworkManager’s graphical program will be used to manage the network interface. To use NetworkManager, first modify the Netplan description file:

$ sudo vim /etc/netplan/50-cloud-init.yaml

network:
version: 2
renderer: NetworkManagerCopy the code

The next step is to generate NetworkManager configuration information:

$ sudo netplan applyCopy the code

Finally, you can open the Network interface graph on the Ubuntu desktop system to manage the network.

Other related

  • Basic syntax rules of YAML language

YAML was designed to be easy for humans to read and write. It is essentially a universal data serialization format. The basic syntax rules of YAML are as follows:

1. Case sensitive 2. Use indentation to indicate hierarchy 3. 4. The number of indent Spaces does not matter, as long as elements of the same level are aligned to the left.# indicates a comment, which is ignored by the parser all the way to the end of the line.Copy the code

See the article “YAML Language Tutorials” for more information on how to use YAML.

  • Manually create the configuration information for the network daemon according to the Netplan description file

$ sudo netplan generateCopy the code

After the command is executed, the /etc/netplan/*. Yaml command is used to generate the configuration information of the network daemon. Such as:

$ cat /run/systemd/network/10-netplan-enp0s5.network [Match] Name=enp0s5 [Link] RequiredForOnline=no [Network] 23 the Gateway Address = 192.168.100.211 / = 192.168.100.1 DNS = 8.8.8.8 DNS = 8.8.4.4Copy the code
  • View the current system’s DNS Servers

$ systemd-resolve --status Global DNSSEC NTA: In-addr.arpa 16.172.in-addr.arpa 168.192. In-addr.arpa 17.172. In-addr.arpa 18.172 20.172. The in - addr. ARPA 21.172. The in - addr. ARPA 22.172. The in - addr. ARPA 23.172. The in - addr. ARPA 24.172. The in - addr. ARPA 25.172. The in - addr. ARPA 26.172. The in - addr. ARPA 27.172. The in - addr. ARPA 28.172. The in - addr. ARPA 29.172. The in - addr. ARPA 30.172. The in - addr. ARPA 31.172. The in - addr. ARPA corp d.f.ip6.arpa home internal intranet lanlocal
private
test

Link 2 (enp0s5)
Current Scopes: DNS
LLMNR setting: yes
MulticastDNS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 8.8.8.8
8.8.4.4Copy the code

Reference documentation

http://www.google.com

http://t.cn/RBxJCC7

http://t.cn/RBxXXlx

http://t.cn/R5mqugZ

http://t.cn/RBxDyMH