Introduction
Managing network configurations is a fundamental task for Linux administrators. I choose Netplan, introduced in Ubuntu 17.10. With Netplan network configuration has become more streamlined and intuitive. Netplan leverages YAML files to define and manage network settings, offering a unified approach to configure both NetworkManager and systemd-networkd backends.
Whether you’re setting up a home network or managing complex enterprise configurations, Netplan simplifies tasks like assigning IP addresses, configuring DNS servers, and setting up VLANs. In this guide, we’ll explore how to harness the power of Netplan to manage your network configurations efficiently.
Netplan – Static IP Configuration on Ubuntu
Go to the /etc/netplan/50-cloud-init.yaml and check current IP settings
more /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
ens160:
dhcp4: false
addresses: [192.168.10.40/24]
gateway4: 192.168.10.253
nameservers:
addresses: [192.168.10.201, 192.168.10.253]
version: 2
Example of Netplan Static IP Configuration:
Netplan – DHCP Configuration on Ubuntu
network: version: 2 renderer: networkd ethernets: enp0s3: dhcp4: yes
Netplan – VLAN Configuration on Ubuntu
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
eth0:
dhcp4: true
optional: true
# Add VLAN 30 with IP Address
vlans:
eth0.30:
id: 30
link: eth0
addresses: [10.3.3.10/24]
version: 2
Test and Apply Configuration
# Try the configuration before applying
netplan try -timeout 120
# Apply network configuration
netplan apply
More examples of Netplan configuration on Ubuntu:
- Linux Networking: Add VLAN on Ubuntu with netplan
- Linux Networking: netplan DHCP Configuration on Ubuntu