Assigning a Static IP on Ubuntu Server the Easy Way

Configure a persistent static IP address on Ubuntu Server using Netplan, the modern, YAML‑based networking system used in all current Ubuntu releases.

Scenario

Your team is deploying several Ubuntu servers to host internal applications and services. During testing, you notice that each time a server reboots, it receives a different IP address from DHCP.

To ensure your Ubuntu servers remain reachable and stable, you need to assign a static IP address directly on the server using Netplan, Ubuntu’s default network configuration tool.

Lab Objectives

  • Identify your Ubuntu network interface
  • Locate the active Netplan configuration file
  • Assign a static IP address using YAML
  • Apply and validate the configuration
  • Ensure the server remains reachable after reboot

Prerequisites

  • Ubuntu Server 18.04 or newer (Netplan‑based)
  • Sudo or root access
  • Basic familiarity with Linux commands
  • A chosen static IP, gateway, and DNS servers

In this setup:

  • The server is called server1
  • It has two NICs:
    • eth0 (already using DHCP)
    • eth1 (to be configured with a static IP)
  • The desired IP configuration:
    • IP Address: 10.0.10.10/24
    • Gateway: 10.0.10.1
    • Name Servers: 10.0.10.1
  • Configuration is managed using Ubuntu's netplan utility

Identify the NICs

Run:

ip a

This lists all interfaces and shows which ones are active and which have IPs. In this case, eth0 uses DHCP; eth1 is unconfigured.

Review Netplan Files

Netplan stores network settings in YAML format under:

/etc/netplan/

Run:

ls /etc/netplan

View current config:

sudo cat /etc/netplan/<filename>.yaml

The file will show DHCP set to true for eth0.

Set a Static IP Using Netplan’s CLI

Use netplan set to apply settings without manually editing YAML files. This will create a new yaml file named eth1-net-config.yaml

sudo netplan set ethernets.eth1.addresses=["10.0.10.10/24"] --origin-hint eth1-net-config

Check changes:

netplan get

You'll see eth1 listed with the new static IP.

Add Gateway and DNS

sudo netplan set ethernets.eth1.gateway4="10.0.10.1" --origin-hint eth1-net-config
sudo netplan set ethernets.eth1.nameservers.addresses=["10.0.10.1"] --origin-hint eth1-net-config

Confirm configuration:

netplan get

Apply the Configuration

sudo netplan apply

Verify IPs:

ip a

eth1 will now show 10.0.10.10/24 as its assigned address.

The Results

  • eth1 is now statically configured.
  • Gateway and name servers are applied.
  • The configuration is saved in a dedicated file (eth1-net-config.yaml).
  • netplan get confirms all parameters are correctly indented and valid.

The Conclusion

Using netplan set and netplan get simplifies interface management—especially on servers with multiple NICs. Configurations are modular, clean, and easy to maintain. Static IPs are essential for service stability, and this method avoids manual YAML edits altogether.

Lab Video