DEV Community

mich0w0h
mich0w0h

Posted on

18

Configure Static IP in Ubuntu 22.04

Configuring Ubuntu 22.04 to Use a Static IP Address

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:

  1. Check the IP address of the default gateway:
ip route show default
Enter fullscreen mode Exit fullscreen mode

This command will show the default route and the corresponding gateway IP address.

  1. Check the subnet mask:
ip addr show
Enter fullscreen mode Exit fullscreen mode

This command will display the IP addresses and subnet masks for all interfaces.

  1. Note the gateway address and desired static IP address to assign In my case, the gateway address is 192.168.10.1, and I decided to assign the static IP address 192.168.10.100/24.

Configuring the Static IP Address

  1. Open the network configuration file with a text editor. For example, using nano:
sudo nano /etc/netplan/<target-configuration-file>.yaml
Enter fullscreen mode Exit fullscreen mode

In my case, I'm using a WiFi connection, so I'll choose the WiFi-specific configuration file.

  1. 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]
Enter fullscreen mode Exit fullscreen mode

addresses and default routes will be the ones you've noted above.

  1. Verify the new network configuration:
sudo netplan try
Enter fullscreen mode Exit fullscreen mode

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.

  1. If the verification is successful, apply the new network configuration:
sudo netplan apply
Enter fullscreen mode Exit fullscreen mode
  1. Verify that the static IP address has been assigned correctly:
ip addr show
Enter fullscreen mode Exit fullscreen mode

You should see your new static IP address listed under the WiFi interface (wlan0).

  1. Verify the connection by pinging the static IP address from another device on the same home network:
ping 192.168.10.100
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

That's it! You've successfully configured Ubuntu 22.04 to use a static IP address on your WiFi connection.

References

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay