When managing modern Ubuntu servers and desktops, configuring a static IP address and DNS settings is a fundamental skill every Linux system administrator needs. With Ubuntu 26.04, Netplan remains the primary method for network configuration, replacing legacy systems by offering a clean and declarative YAML interface. This tutorial dives deep into setting up static IPs and DNS servers using Netplan on Ubuntu 26.04. Whether you’re administering local physical servers, virtual machines, or cloud instances, understanding how to manage your network configuration reliably is crucial—especially if you work remotely and need to avoid network outages triggered by misconfigurations.
Understanding How Netplan Manages Network Configuration
Netplan abstracts the complexity of underlying network components by consolidating configurations into YAML files located under /etc/netplan/. On Ubuntu 26.04, you may find one or more YAML files starting with numbers like 00-installer-config.yaml or 50-cloud-init.yaml. These files are parsed in lexical order and merged to produce the final network configuration. Netplan then hands off the settings either to systemd-networkd for servers or NetworkManager for desktops.
In real production environments, administrators often deal with server setups where consistent IP addressing is vital—such as hosting production applications, running internal services, or establishing VPN gateways. Static IP configuration guarantees that your server doesn’t unexpectedly lose reachability after reboot, which is a lifesaver during critical maintenance windows.
ls /etc/netplan/ 00-installer-config.yaml
This command lists the existing Netplan YAML configuration files. Note that editing these original files is essential; never modify files in /run/ as these are generated dynamically and overwritten during system operations.
Setting a Static IP with Netplan on Ubuntu 26.04
Before applying any changes, make sure to identify the network interface name using:
ip addr show
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:1a:4b:16:01:59 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.50/24 brd 192.168.1.255 scope global dynamic enp1s0
valid_lft 86347sec preferred_lft 86347sec
The ip addr show command lists all network interfaces with their IP addresses. Here, enp1s0 is the Ethernet interface currently using DHCP-assigned IP 192.168.1.50/24. Identifying the exact interface name is critical because hardcoding a wrong interface name in the YAML file will break connectivity.
Next, edit the Netplan file to configure a static IP. For example, assuming your network gateway is 192.168.1.1 and DNS servers are Google’s and Cloudflare’s (8.8.8.8 and 1.1.1.1):
sudo nano /etc/netplan/00-installer-config.yaml
Modify it as follows:
network:
version: 2
renderer: networkd
ethernets:
enp1s0:
dhcp4: false
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 1.1.1.1
Key elements explained:
dhcp4: falsedisables DHCP for IPv4, enabling static addressing.addressesspecifies the static IP and subnet mask in CIDR format.routesreplaces the oldergateway4directive, defining the default gateway.nameservers.addresseslists the DNS servers for hostname resolution.renderer: networkdensuressystemd-networkdis used, which is typical in server environments.
A mistake I often encounter is mixing tabs and spaces or incorrect indentation in YAML files, which instantly causes Netplan to refuse the config. Always use spaces, preferably 2 spaces per indentation level.
Applying Changes Safely: Using netplan try
In one troubleshooting case I handled, a sysadmin remotely applied new network settings that cut off SSH connectivity. To protect yourself in similar remote management scenarios, use:
sudo netplan try [OK] Waiting for the network to come up... Press ENTER to keep the new configuration
The netplan try command applies the new config temporarily and waits for confirmation (usually 120 seconds). If you lose connection or don’t confirm, it automatically reverts to the last working configuration. This “safety net” is essential for avoiding lockouts when working via SSH.
After confirming connectivity by pressing ENTER, you can make changes permanent anytime with sudo netplan apply.
Verifying Network Settings After Applying Static IP
It’s good practice to verify the network settings once applied. Start with:
ip addr show enp1s0
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:1a:4b:16:01:59 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.100/24 brd 192.168.1.255 scope global permanent enp1s0
valid_lft forever preferred_lft forever
A static IP shows a “permanent” lease instead of a dynamic lease timer. Next, confirm the routing table:
ip route show default via 192.168.1.1 dev enp1s0 proto static metric 100 192.168.1.0/24 dev enp1s0 proto kernel scope link src 192.168.1.100 metric 100
The presence of a default route through your gateway ensures outbound traffic is routed properly.
For DNS, check which servers are actively used:
resolvectl status enp1s0
Link 2 (enp1s0)
Current Scopes: DNS
Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 8.8.8.8
DNS Servers: 8.8.8.8 1.1.1.1
DNS Domain:
resolvectl reports the DNS servers managed by systemd-resolved, verifying your Netplan DNS settings are active.
Configuring Multiple DNS and Search Domains
In complex networks like corporate environments, specifying multiple DNS servers and search domains ensures redundancy and ease of access to internal hosts. An example config that includes search domains might look like this:
network:
version: 2
renderer: networkd
ethernets:
enp1s0:
dhcp4: false
addresses:
- 10.10.1.20/24
routes:
- to: default
via: 10.10.1.1
nameservers:
search:
- internal.company.local
- corp.example.com
addresses:
- 10.10.1.53
- 8.8.4.4
The search key allows hostname resolution using short names. For instance, you can SSH simply using ssh dbserver instead of the fully qualified domain name.
This feature is often overlooked but can seriously improve workflow efficiency in sizable IT environments.
Best Practices to Follow When Managing Static IPs on Ubuntu Servers
- Always back up existing Netplan YAML files before making changes. This lets you easily revert if needed.
- Use
netplan tryfor remote configuration to avoid losing SSH connectivity. - Validate YAML syntax using online tools or parsing commands before applying.
- Be aware that on cloud providers, network settings might be overridden by
cloud-init. In such cases, avoid editing50-cloud-init.yamldirectly; instead, use cloud-init userdata or disable cloud-init network configuration. - After changes, always verify IP address, routes, and DNS server settings using
ip addr,ip route, andresolvectl. - If multiple network interfaces are present, configure each carefully, paying attention to routing to prevent conflicts.
- Document your network configuration changes thoroughly, especially in production environments.
Troubleshooting Scenario: Lost SSH Access After Netplan Update
In a situation I handled recently, a junior sysadmin attempted to set a static IP remotely but mistyped the gateway IP address in the YAML file. Immediately after applying the change, SSH connection dropped, locking them out.
Luckily, they had used netplan try, and after the timeout, the system automatically reverted to the previous DHCP configuration, restoring connectivity. The lesson here is clear: always use netplan try when changing network settings remotely, and double-check gateway and interface naming.
To diagnose, one can reboot the server, SSH back in, inspect /etc/netplan/, and fix the YAML file. Using verbose logging by running sudo netplan --debug apply can reveal parsing errors early.
sudo netplan --debug apply DEBUG: Loaded config files: /etc/netplan/00-installer-config.yaml DEBUG: start apply DEBUG: setting up link enp1s0 DEBUG: ...
This command applies the config with detailed debug output, helping you pinpoint issues such as syntax errors or invalid parameters.
Conclusion
Configuring a static IP address and DNS correctly with Netplan on Ubuntu 26.04 is essential for reliable, predictable network service—especially in production servers or remote systems. By understanding Netplan’s YAML structure, using safety features like netplan try, and validating changes before applying, you reduce downtime and avoid network lockouts.
Always identify the correct interface, configure routes carefully, and verify DNS settings with resolvectl. With these practices, you’ll maintain a stable network environment whether on bare-metal servers, VMs, or cloud virtual instances.
Have you experienced any challenging situations with Netplan configurations? Share your tips or stories with your team—it can save someone’s day.