| by Arround The Web | No comments

How to Set Up a Static IP Address on WiFi Network from the Command-Line on Linux using NetworkManager

Most likely, your WiFi router will use DHCP to assign random IP addresses on your desktop/laptop. If you want to run some kind of servers/services on your desktop/laptop and you only have the WiFi connectivity available, you need to set up a static/fixed IP address for your WiFi network. This way, your servers/services will be available at the same IP address at all time and it will save you a lot of connectivity issues and reconfiguration hassles.

In this article, we will show you how to set up a static/fixed IP address for your WiFi network from the command line on modern Linux distributions that use the NetworkManager to manage the network devices.

This article should work on the following listed Linux distributions and other Linux distributions (not listed) that use the NetworkManager to manage the networks and have the “nmcli” command line tool available.

  • Ubuntu
  • Debian
  • Linux Mint
  • Elementary OS
  • Fedora
  • RHEL
  • CentOS Stream
  • AlmaLinux
  • Rocky Linux
  • openSUSE
  • SUSE Linux Enterprise Server (SLES)
  • Oracle Linux

Topic of Contents:

Connecting to a WiFi Network from the Command Line on Linux Using Nmcli

Before you get started, make sure that your WiFi network interface is enabled and you’re connected to your desired WiFi network using NetworkManager.

Finding the Current IP Addressing Information of the WiFi Network Interface on Linux

While setting up a static/fixed IP address for your WiFi network, learning about the current IP addressing information will be helpful as most of the IP information (i.e. DNS server, gateway, subnet mask) will remain the same; only the IP address might be changed.

To find the name of the WiFi network interface and the currently active NetworkManager connection name, run the following command:

$ sudo nmcli device

In our case, the WiFi network interface’s name is “wlp7s27u1” and the currently active NetworkManager connection’s name is “NodeKite-2.4G”. Take a note of these information as you will need them shortly.

To find the currently configured IP addressing information (i.e. IP address, subnet mask, gateway, DNS server) of the “wlp7s27u1” WiFi network interface, run the following command:

$ sudo nmcli -f GENERAL.DEVICE,GENERAL.CONNECTION,IP4.ADDRESS,IP4.GATEWAY,IP4.DNS device show wlp7s27u1

As you can see, the IP address that is assigned on our “wlp7s27u1” WiFi network interface is 192.168.0.113, the subnet mask is /24 (or, 255.255.255.0), the gateway IP address (the IP address of the connected WiFi router) is 192.168.0.1, and the DNS server address is 1.1.1.1.

Setting Up a Static/Fixed IP Address for WiFi Network from the Command Line on Linux Using Nmcli

To set up a static/fixed IP address for your WiFi network, you need to know the NetworkManager connection name that is configured for your WiFi network interface to connect to your WiFi network.

To find the NetworkManager connection name, run the following command:

$ sudo nmcli connection

In our case, the NetworkManager connection name for our WiFi network is “NodeKite-2.4G”.

To configure a static/fixed IP address of 192.168.0.25 (let’s say) for the “NodeKite-2.4G” WiFi network (let’s say) with all the other IP information (i.e. subnet mask, gateway, DNS server) intact, run the following command:

$ sudo nmcli connection modify "NodeKite-2.4G" ipv4.method manual ipv4.addresses 192.168.0.25/24 ipv4.gateway 192.168.0.1 ipv4.dns 1.1.1.1

Once the “NodeKite-2.4G” NetworkManager connection is configured with a static/fixed IP address, run the following command to apply the changes:

$ sudo nmcli connection up "NodeKite-2.4G"

As you can see, a static/fixed IP address is set for the “wlp7s27u1” WiFi network interface.

You can confirm that the static/fixed IP address of 192.168.0.25 is set for the “wlp7s27u1” WiFi network interface using the “ip” command as well:

$ ip a

Checking for Internet Connectivity from the Command Line

If you configured a static/fixed IP address on the WiFi network interface correctly, you should be able to ping “google.com” (or the domain names of any other popular websites) to verify that you have an internet connectivity.

$ ping -c 3 google.com

Conclusion

In this article, we showed you how to find the current IP addressing information of your WiFi network interface. We also showed you how to configure a static/fixed IP address for your WiFi network interface on Linux from the command line using NetworkManager. Setting a static/fixed IP address is essential for hosting some sort of servers/services on your computer.

Share Button

Source: linuxhint.com

Leave a Reply