Introduction
On Ubuntu Server, Netplan manages network configuration. It reads YAML files in /etc/netplan/ and applies them through backends such as systemd-networkd.
Before you start
Keep local console access when changing a remote server's network settings. An incorrect configuration can disconnect the active session.
Prerequisites
Collect the following information before editing the configuration file:
- sudo access
- The static IP address and subnet prefix
- The default gateway address
- DNS server addresses
- The network interface name
01 — Identify the network interface
Find the interface name that is connected to the server network. Common names include ens160, enp0s3, and eth0.
ip addr
ip link
02 — Inspect Netplan files
List the YAML files that Netplan reads, then inspect the current configuration before making changes.
ls -la /etc/netplan/
sudo cat /etc/netplan/*.yaml
03 — Back up the current configuration
After confirming the file name, create a backup before editing it. The following command uses the common cloud-init file name.
sudo cp /etc/netplan/50-cloud-init.yaml /etc/netplan/50-cloud-init.yaml.bak
04 — Configure a static IP address
Edit the appropriate YAML file and define the interface configuration. This example uses ens160 with a static IPv4 address, a default route, and DNS servers.
network:
version: 2
renderer: networkd
ethernets:
ens160:
dhcp4: false
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 1.1.1.1
- 8.8.8.8
Adjust this example
Replace ens160, the IP address, subnet prefix, gateway, and DNS servers with values that match your network. Define the default gateway with routes using to: default and via.
05 — Validate and apply the configuration
Generate the backend configuration first. For remote systems, use netplan try where possible so the configuration can be confirmed before it becomes permanent, then apply it.
sudo netplan generate
sudo netplan try
sudo netplan apply
06 — Test the network configuration
Verify the assigned address, the default route, Netplan status, gateway reachability, and external connectivity.
ip addr show ens160
ip route
netplan status ens160
ping -c 4 192.168.1.1
ping -c 4 8.8.8.8
Troubleshooting
Review these common causes when a static Netplan configuration does not work as expected.
YAML indentation error
YAML is indentation-sensitive. Use spaces consistently, do not use tabs, and run netplan generate to identify the reported line.
Incorrect interface name
The name below ethernets must exactly match the device name reported by ip link. Update the YAML if the actual name is different from ens160.
Gateway is unreachable
Confirm that the gateway belongs to the same network as the static address and that the default route uses routes with to: default and via.
DNS does not resolve names
Confirm that the DNS addresses are correct and reachable. If pinging an IP works but a hostname does not, review the nameservers configuration.
Best practices
- Inspect the existing files and keep a backup before editing.
- Use netplan try when changing a remote server to reduce the risk of losing access.
- Use the actual interface name and address values assigned for the local network.
- Test the address, route, gateway, and DNS after applying the configuration.
Frequently asked questions
How should I define the default gateway in a new Netplan configuration?
Define the default route in routes with to: default and via.
How do I find the correct interface name?
Run ip link or ip addr and use the reported device name under ethernets in the YAML file.
What should I do if I lose network access after applying a change?
Use console access to review the YAML and restore the backup if needed. For future remote changes, validate with netplan try before applying permanently.
Conclusion
A static Ubuntu Server address is configured by identifying the interface, updating its Netplan YAML with the correct address, default route, and DNS, validating the configuration, and testing the resulting network state.