Linux Network Configuration with Netplan
Netplan describes network configuration in YAML and passes it to a renderer such as NetworkManager or systemd-networkd. The exact interface name and renderer vary by installation, so inspect them rather than copying a name from another machine.
Inspect the current state
ip link
ip address
ip route
resolvectl status
Back up the existing YAML before changing it:
sudo cp -a /etc/netplan /etc/netplan.backup
DHCP configuration
network:
version: 2
ethernets:
enp1s0:
dhcp4: true
Replace enp1s0 with the actual interface name. Apply interactively where possible:
sudo netplan try
netplan try rolls back if confirmation is not received. Use netplan apply only when you have console access or a recovery path.
Static IPv4 configuration
network:
version: 2
ethernets:
enp1s0:
addresses: [192.0.2.20/24]
routes:
- to: default
via: 192.0.2.1
nameservers:
addresses: [192.0.2.53, 1.1.1.1]
The 192.0.2.0/24 network is documentation-only. Choose addresses from the network actually assigned to your lab. CIDR notation is explained in IPv4 Subnets, Netmasks, and CIDR.
Verify
ip address show dev enp1s0
ip route
ping -c 3 192.0.2.1
resolvectl query example.com
Do not confuse a working local route with working DNS. Test address reachability and name resolution separately.