Ubuntu 26.04 Tutorial / Configure Static IP and DNS with a Recovery Plan
A static-IP change affects interface addressing, routing, DNS, and management access together. Obtain console access and original configuration backups first, then validate syntax, try the change with a timeout, and verify new connections and reboot behavior.
Verify real network values and ownership
ip -br address
ip route
resolvectl status
sudo netplan get
Check for address conflicts first. This tutorial uses the dedicated host-only network from the VM creation lesson: server 192.168.56.20/24, permitted Linux client 192.168.56.10/24, and host 192.168.56.1/24. No ping response alone proves an unused address; record actual NICs, MACs, and the existing default route.
The YAML targets a new Server lab with two wired NICs managed by systemd-networkd. Verify by actual MACs and settings that enp0s3 is NAT/DHCP and enp0s8 is host-only. Change cloud-init-generated configuration through its owning workflow.
Prepare backups and console access
(
set -eu
backup=$(sudo mktemp -d /root/netplan-backup.XXXXXX)
sudo cp -a /etc/netplan "$backup/"
printf 'Backup: %s\n' "$backup"
)
Record the backup path and actual file to edit, and sign in through the VM or provider console. Keep the current SSH session open. Inspect merged YAML if another file defines the same interface; do not assume a newly added file will override everything correctly.
Write address, route, and DNS together
Edit the identified Netplan source with sudoedit using actual interface names. This complete minimal example retains NAT DHCP addressing, default routing, and DNS while assigning a static address only to the host-only NIC. Preserve other NIC, IPv6, bridge, and VLAN policy; avoid duplicate definitions across files.
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: true
enp0s8:
dhcp4: false
addresses:
- 192.168.56.20/24
Restrict the source file to administrator access, verifying the actual path before sudo chmod 600 actual-file. Preserve the environment’s IPv6 DHCP, router-advertisement, and DNS policy separately. An IPv4 example is not a reason to delete existing IPv6 configuration.
Validate syntax and try with a timeout
sudo netplan generate && sudo netplan try --timeout 120
If generation fails, correct the reported file, line, or key before applying. While try waits, use another terminal or client to test the new address, route, DNS, and required services, and confirm only after success. Do not assume timeout rollback is infallible; retain console access.
Verify the client address and real routes
On a second Server VM using networkd, use the same structure with 192.168.56.10/24 on its verified host-only NIC; the server uses .20. Keep DHCP internet paths on both NAT adapters. VM-to-VM traffic uses the host-only network directly and needs no NAT forwarding.
ip -br address
ip route
ip route get 192.168.56.10
resolvectl query ubuntu.com
The route-get command runs on the server toward client .10; use .20 as the destination on the client. The host-only destination should use its own NIC, while the internet default uses NAT. Do not add .1 as gateway or DNS on the host-only NIC.
Recover original files and runtime state
If access is lost, inspect actual addresses and on-disk YAML through the console. Restore only the changed source from backup and undo only any newly introduced file. Validate the restored configuration before applying it and checking the original address, route, and DNS.
Even a successful live change needs a separate reboot check. Use a name-resolution test such as resolvectl query ubuntu.com and a fresh client connection to required services. ICMP may be blocked, so one ping is not a complete connectivity verdict.




