
How to Set a Static IP Address on Ubuntu Server
Ubuntu Server (24.04 LTS Noble Numbat and later releases, including point updates through 2026) uses Netplan as the default network configuration tool. Netplan employs declarative YAML files to define network settings, which are then translated into backend configurations (typically systemd-networkd on servers). This approach provides consistency across installations, supports complex setups (bridges, bonds, VLANs), and avoids legacy tools like /etc/network/interfaces.
Setting a static IP means disabling DHCP and explicitly defining the address, subnet mask (via CIDR notation), gateway, and DNS servers. The process is the same on physical hardware, VMs (KVM, VirtualBox, VMware), and most cloud instances (though cloud providers often override via metadata/cloud-init).
Prerequisites
- Know your desired static IP, subnet, gateway, and preferred DNS servers. Example: IP 192.168.1.100/24, gateway 192.168.1.1, DNS 8.8.8.8 and 1.1.1.1
- Identify the network interface name: ip link show or ip -c addr. Common names: enp1s0, ens3, eth0, eno1 (predictable naming since ~16.04).
- Have console or out-of-band access (e.g., IPMI, cloud console) in case of misconfiguration — a wrong IP can lock you out of SSH.
Step-by-Step Configuration
Backup existing configuration Netplan files live in /etc/netplan/. Back up before editing:
Bashsudo cp -r /etc/netplan /etc/netplan.bak-$(date +%F)Locate or create the Netplan file List files: ls /etc/netplan/ Typical names: 00-installer-config.yaml, 50-cloud-init.yaml, 01-netcfg.yaml. If no suitable file exists, create one (higher numbers override lower):
Bashsudo nano /etc/netplan/99-static-ip.yamlEdit the YAML configuration Replace or add content matching your interface and desired settings. Use spaces (not tabs) for indentation — YAML is strict.
Minimal complete example for a single Ethernet interface:
YAMLnetwork: version: 2 renderer: networkd ethernets: enp1s0: # ← replace with your interface name dhcp4: false dhcp6: false addresses: - 192.168.1.100/24 # your static IP + subnet mask in CIDR routes: - to: default via: 192.168.1.1 # your gateway/router IP nameservers: addresses: [8.8.8.8, 1.1.1.1] # preferred DNS servers # search: [example.local] # optional search domainKey elements explained:
- dhcp4: false / dhcp6: false — disables automatic IP assignment
- addresses — list of IPs (usually one); CIDR notation combines address + prefix length
- routes block — defines the default gateway (metric optional but useful with multiple interfaces)
- nameservers — overrides DHCP-provided DNS; use public resolvers or internal ones
- renderer: networkd — standard for servers (NetworkManager is desktop default)
Validate syntax before applying
Bashsudo netplan generate --debugNo output or errors = good. Errors show line numbers and issues (indentation, missing colons, etc.).
Apply safely
Bashsudo netplan try- Applies changes for 120 seconds
- Press Enter to keep; any key or timeout reverts automatically
- Excellent safeguard against locking yourself out
If confident: sudo netplan apply
Verify the new configuration
Baship -c addr show enp1s0 ip route show ping 8.8.8.8 ping google.com # tests DNS too timedatectl status # optional – shows resolver statusCheck logs if issues arise:
Bashjournalctl -u systemd-networkd -xe
Common Pitfalls & Troubleshooting
- Wrong interface name → no IP assigned; double-check with ip link
- YAML syntax error → netplan apply fails silently or reverts; always use netplan generate first
- Multiple YAML files → higher-numbered files override; check all with ls /etc/netplan/
- Cloud instances → cloud-init may override; look for 50-cloud-init.yaml and adjust or disable overrides
- No connectivity after apply → revert with sudo netplan try (if still in session) or console access
- DNS not resolving → ensure nameservers block is present; test with resolvectl status
Why Netplan Over Older Methods?
Netplan centralizes configuration, supports atomic application (safer than editing live interfaces), integrates cleanly with systemd-networkd, and scales to complex topologies without manual scripting. Legacy /etc/network/interfaces is no longer supported on modern Ubuntu Server installs.
For most servers (web, database, file, container hosts), a static IP ensures predictable access for SSH, monitoring agents, firewalls, and reverse proxies. Once set, it persists across reboots and upgrades unless cloud-init intervenes.
If you share your current ip addr output, desired IP details, or whether this is a cloud VM vs bare metal, more precise YAML examples can be tailored.