Skip to content

Netplan

Netplan is a network configuration util for linux.

Configuration is stored in /etc/netplan/*.yaml. Multiple files may exist but alphabetically later ones will override keys in previous files. Customise network configuration by creating the file /etc/netplan/99-custom.yaml which will be loaded last.

network:
ethernets:
enp0s8:
dhcp4: true
version: 2
# static IP
network:
ethernets:
enp0s3:
addresses:
- 192.168.120.62/24
enp0s8:
addresses:
- 192.168.140.62/24
gateway4: 192.168.140.1
nameservers:
addresses: [192.168.100.66]
version: 2

The above

  • assigns a single IP 192.168.120.62 to enp0s3, with a netmask of 255.255.255.0.
  • assigns a single IP 192.168.140.62 to enp0s8, with a netmask of 255.255.255.0.

It creates a route table

Terminal window
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.140.1 0.0.0.0 UG 0 0 0 enp0s8
192.168.120.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s3
192.168.140.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s8

And updates DNS

Terminal window
$ resolvectl status
Link 3 (enp0s8)
Current Scopes: DNS
DefaultRoute setting: yes
LLMNR setting: yes
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
Current DNS Server: 192.168.100.66
DNS Servers: 192.168.100.66

Run netplan try to immediately apply and confirm. It will rollback if you do not confirm the changes.

Do not reboot until configuration has been successfully applied and tested as it will attempt to apply the configuration at startup.

Terminal window
# netplan try
Warning: Stopping systemd-networkd.service, but it can still be activated by:
systemd-networkd.socket
Do you want to keep these settings?
Press ENTER before the timeout to accept the new configuration
Changes will revert in 119 seconds
Configuration accepted.