Configuring Static IP Addresses

Servers need static IP addresses so that DNS records, firewall rules, and application configs that reference the IP remain valid. DHCP is fine for workstations but not for servers — a DHCP lease expiry or DHCP server restart could change the server's IP, breaking all the services that depend on it. Ubuntu uses Netplan for network configuration, with YAML files that are rendered into either networkd or NetworkManager backend configuration.

Why static IPs for servers

  • DNS records (A records) point to a specific IP — must not change
  • Firewall rules allow/deny specific IP addresses
  • Other applications config files reference the IP (databases, load balancers)
  • SSH known_hosts entries would need updating if IP changes

Finding your Netplan file

# Netplan config files live in /etc/netplan/
ls /etc/netplan/

Common filenames

00-installer-config.yaml       # Ubuntu Server installer creates this
50-cloud-init.yaml             # Cloud instances (AWS, Azure, GCP)
01-netcfg.yaml
# View the current config
cat /etc/netplan/00-installer-config.yaml

Configuring a static IP

sudo nano /etc/netplan/00-installer-config.yaml

Static IP configuration (replace values with your network details)

network:
  version: 2
  ethernets:
    ens3:
      dhcp4: false              # Disable DHCP
      dhcp6: false
      addresses:
        - 192.168.1.10/24       # Your static IP + prefix length
      routes:
        - to: default
          via: 192.168.1.1      # Your default gateway
      nameservers:
        addresses:
          - 8.8.8.8             # Primary DNS
          - 1.1.1.1             # Secondary DNS
        search:
          - example.com         # Optional: DNS search domain

⚠️ WARNING: YAML is whitespace-sensitive. Indentation must use spaces, never tabs. Two spaces per level. A formatting error in the Netplan file will cause the network to fail on next reboot. Always test changes with netplan try before rebooting, and always have console access (IPMI, cloud console) available when modifying a remote server's network config.

Applying and testing

# BEST PRACTICE: Test first (automatically reverts after 120 seconds if you don't confirm)
sudo netplan try

netplan try output

Do you want to keep these settings?

Press ENTER before the timeout to accept the new configuration

Changes will revert in 118 seconds
_
# If network still works, press Enter to confirm
# If you lost connectivity, wait 120 seconds — it reverts automatically

# Apply permanently without the revert timer (use only after testing)
sudo netplan apply

# Verify the change
ip addr show ens3
ip route show
ping -c 3 8.8.8.8     # Test gateway reachability
dig google.com         # Test DNS

Multiple IPs on one interface

# Add multiple addresses under the addresses key:
network:
  version: 2
  ethernets:
    ens3:
      dhcp4: false
      addresses:
        - 192.168.1.10/24     # Primary IP
        - 192.168.1.11/24     # Secondary IP (virtual IP for failover)
        - 10.10.0.5/16        # Additional address on different network
      routes:
        - to: default
          via: 192.168.1.1

Conclusion

Always use netplan try rather than netplan apply when working on remote servers — the automatic rollback after 120 seconds is a critical safety net. The minimum required configuration for a static IP: dhcp4: false, an addresses entry with the IP and prefix length, a routes entry pointing to the default gateway, and nameservers with at least one DNS address. Verify with ip addr show, ip route show, and a ping to both the gateway and an external host.

FAQ

Is Configuring Static IP Addresses important for Ubuntu administrators?+

Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.

Should I practice this on a live server?+

Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.

What should I do after reading this article?+

Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.

Need help with Ubuntu administration?

Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.

Hire Me for Support