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
- Find your network info:
ip link # Get interface name
ip route | grep default # Get gateway
- 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 interface192.168.1.100/24
→ Your desired static IP and subnet192.168.1.1
→ Your default gateway/router IP8.8.8.8
→ Your preferred DNS servers
- To apply the changes, run:
sudo netplan apply
Verify
Check with:
ip a