Skip to main content
To configure a static IP address on Ubuntu, edit the Netplan network configuration files.
1
Find your network interface
2
ip addr
3
Look for the interface that is currently connected to your network. In this example it is wlo1:
4
3: wlo1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether a0:29:42:00:3c:78 brd ff:ff:ff:ff:ff:ff
    altname wlp0s20f3
    inet 192.168.0.20/24 brd 192.168.0.255 scope global dynamic noprefixroute wlo1
5
Create or edit the Netplan configuration file
6
List the files in /etc/netplan/:
7
ls /etc/netplan
# 01-network-manager-all.yaml  50-cloud-init.yaml
8
Create a new file called 99-static-ip.yaml. Using a higher prefix like 99- ensures this configuration takes priority over earlier files like 01- or 50-.
9
First, find your default gateway:
10
ip route | grep default
# default via 192.168.0.1 dev wlo1 proto dhcp src 192.168.0.20 metric 600
11
Then create the config file:
12
network:
  version: 2
  renderer: NetworkManager
  # ethernets:  # for wired connections
  wifis:        # for wireless connections
    wlo1:       # use your actual interface name
      dhcp4: no
      dhcp6: no
      addresses:
        - 192.168.0.20/24
      routes:
        - to: default
          via: 192.168.0.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4, 1.1.1.1]
      access-points:  # for wireless connections only
        "kc_5G":
          password: <wireless-password>
13
Nameservers translate domain names to IP addresses:
  • 8.8.8.8 = Google Public DNS
  • 8.8.4.4 = Google Secondary DNS
  • 1.1.1.1 = Cloudflare Public DNS
14
Apply the Netplan configuration
15
Test the configuration first:
16
sudo netplan try
17
If you see “Permissions are too open” warnings, fix them:
18
sudo chmod 600 /etc/netplan/01-network-manager-all.yaml
sudo chmod 600 /etc/netplan/99-static-ip.yaml
19
Then apply:
20
sudo netplan try   # Accept within the timeout window
sudo netplan apply
21
Verify the static IP
22
Use ip addr to confirm the dynamic keyword is gone:
23
ip addr show wlo1
# inet 192.168.0.20/24 brd 192.168.0.255 scope global noprefixroute wlo1
24
Use ip route to confirm proto static:
25
ip route | grep default
# default via 192.168.0.1 dev wlo1 proto static metric 600
26
Test internet connectivity:
27
ping -c 3 google.com
28
If you still see dynamic or proto dhcp after applying the config, try the following:
  1. Disable cloud-init network management:
    echo "network: {config: disabled}" | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
    
  2. Move conflicting Netplan files to a backup folder:
    mkdir backup
    mv 50-cloud-init.yaml 90-NM-*.yaml backup/
    
  3. Flush the old dynamic lease and reapply:
    sudo ip addr flush dev <interface-name>
    sudo netplan apply
    

Build docs developers (and LLMs) love