Software and Hardware Environment

  • Ubuntu 18.04 64 – bit

Introduction to the

Netplan is a new command-line network configuration program introduced in Ubuntu 17.10 to make it easy to manage and configure network Settings on ubuntu systems. Netplan can use network daemons such as NetworkManager(for desktop systems) or Systemd-Networkd (for server systems) to interface to the kernel, thus making the underlying network differences transparent to the user. The default netplan configuration file is in /etc/netplan/*. Yaml. The configuration file uses yamL syntax.

What is a YAML

YAML(Yet Another Markup Language) is a Markup Language, similar to XML, used for writing project configuration files. It has simple syntax, is case-sensitive, uses indentation to indicate hierarchies, and allows you to interweave comments into your configuration (which beats JSON).

The data structures in YAML are

  • object

    A set of key-value pairs, also known as a map or hash

  • An array of

    A set of sequential values, also known as a list, is a set of lines beginning with a conjunction (-)

  • scalar

    A single, nondivisible value, such as a string, Boolean, integer, etc

Dynamic Address Configuration

In DHCP mode, the configuration is relatively simple. We edit the configuration file /etc/netplan/50-cloud-init.yaml. The name of the YAML configuration file may be different

network:
    renderer: networkd
    ethernets:
        eno1:
            dhcp4: true
            dhcp6: true
    version: 2
Copy the code

After the modification is saved, run the following command to take effect

sudo netplan apply
Copy the code

To view debugging information, add the –debug parameter

Static Address Configuration

To use static IP, edit the file /etc/netplan/50-cloud-init.yaml as well

Network: renderer: networkD EtherNets: ENO1: dhCP4: false addresses: [172.21.2.26/24] gateway4: 172.21.2.1 Nameservers: Addresses: [8.8.8.8] Optional: True version: 2Copy the code

Addresses = static addresses; gateway4 = gateway; nameservers = DNS server; if there are multiple addresses, separate them in brackets with commas (,), for example [8.8.8.8, 114.114.114.114]

If multiple network ports exist, you can copy the eno1 statement configuration block and modify it. Eno1 here is the first network port on my server

Use sudo netplan apply, and then use ifconfig to check if the Settings are correct

The resources

  • netplan.io/examples
  • Xugaoxiang.com/2019/12/03/…
  • wiki.ubuntu.com/Netplan