In this article, I’ll go through the steps to configure a static IP address on Ubuntu 22.04 while using a WiFi connection.
Note that my Ubuntu Server used a DHCP-assigned IPv4 address on a WiFi connection before working on this setup.
Prerequisites
Before proceeding, you need to gather some information:
- Check the IP address of the default gateway:
ip route show default
This command will show the default route and the corresponding gateway IP address.
- Check the subnet mask:
ip addr show
This command will display the IP addresses and subnet masks for all interfaces.
- Note the gateway address and desired static IP address to assign
In my case, the gateway address is192.168.10.1
, and I decided to assign the static IP address192.168.10.100/24
.
Configuring the Static IP Address
- Open the network configuration file with a text editor. For example, using
nano
:
sudo nano /etc/netplan/<target-configuration-file>.yaml
In my case, I’m using a WiFi connection, so I’ll choose the WiFi-specific configuration file.
- Modify the configuration file by adding the following lines under the
wifis
section for your WiFi interface (e.g.,wlan0
):
wifis:
wlan0:
dhcp4: no
addresses: [192.168.10.100/24]
routes:
- to: default
via: 192.168.10.1
nameservers:
addresses: [192.168.10.1, 8.8.8.8, 8.8.4.4]
addresses and default routes will be the ones you’ve noted above.
- Verify the new network configuration:
sudo netplan try
This command will check the syntax of the configuration file and show you the changes that will be made. You might see a warning about ovsdb-server.service
not running, but you can ignore it for now.
- If the verification is successful, apply the new network configuration:
sudo netplan apply
- Verify that the static IP address has been assigned correctly:
ip addr show
You should see your new static IP address listed under the WiFi interface (wlan0
).
- Verify the connection by pinging the static IP address from another device on the same home network:
ping 192.168.10.100
And yes! It worked!
PING 192.168.10.100 (192.168.10.100): 56 data bytes
64 bytes from 192.168.10.100: icmp_seq=0 ttl=64 time=54.810 ms
64 bytes from 192.168.10.100: icmp_seq=1 ttl=64 time=68.789 ms
64 bytes from 192.168.10.100: icmp_seq=2 ttl=64 time=85.646 ms
64 bytes from 192.168.10.100: icmp_seq=3 ttl=64 time=106.507 ms
That’s it! You’ve successfully configured Ubuntu 22.04 to use a static IP address on your WiFi connection.