Configure Static IP using Netplan on Ubuntu

· #linux

Assigning a static IP address is often required in server environments or when devices need to be consistently reachable on the network. On Ubuntu, this is managed using Netplan, a YAML-based network configuration utility.


Setup

  1. Find your network info:
ip link                  # Get interface name
ip route | grep default  # Get gateway
  1. Create a new file /etc/netplan/01-netcfg.yaml. Add this:
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: false
      addresses:
        - 192.168.1.100/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8

Replace:

  • eth0 → Your actual network interface
  • 192.168.1.100/24 → Your desired static IP and subnet
  • 192.168.1.1 → Your default gateway/router IP
  • 8.8.8.8 → Your preferred DNS servers
  1. To apply the changes, run:
sudo netplan apply

Verify

Check with:

ip a