You probably already know how to get your system’s IP address in Linux.
But how do you know the IP address of your router?
I am not talking about the public-facing IP which you can get by connecting to websites like Show My IP or simply searching for ‘what is my ip’ in DuckDuckGo.
I am talking about the default gateway IP which your Linux desktop uses to connect to it.
Why do you need it? Well, if you need to change the SSID, password, or other configuration of your wi-fi/network, you have to connect to it. And the simplest way is to type the router's IP address in a web browser and then use the router’s username and password.
While I cannot help you with the username and password of your router, I can surely tell you how to get its IP.
As always, I’ll show both GUI and command-line methods.
Method 1: Get the router’s IP address in Linux using GUI
It’s quite simple actually. I am using GNOME desktop with Ubuntu here. If you use some other desktop environments, screenshots may look different.
Open System Settings:
Now go to Wi-Fi or Network (if you are using a wired, Ethernet connection). Here, click on the little settings symbol beside your currently used network.
It will open a new window with several details about your connection such as the IP address, DNS, and Mac address. You can also see the saved wifi password under the security tab.
You’ll also see an entry named ‘Default Route’. This is what you are looking for. The IP address of your router.
Your system and all other devices on your network connect to the router using this IP address. This is the setup most households have.
Now that I have shown the GUI method, let’s go to the terminal route.
Method 2: Get the router’s IP address in Linux command line
Open a terminal and use the following command:
ip route
It will show you a few entries.
abhishek@itsfoss:~$ ip route
default via 192.168.1.1 dev wlp0s20f3 proto dhcp metric 600
169.254.0.0/16 dev wlp0s20f3 scope link metric 1000
192.168.1.0/24 dev wlp0s20f3 proto kernel scope link src 192.168.1.34 metric 600
The first line, which starts with ‘default via’, gives you the gateway IP. This is your router’s IP address.
As you can see, 192.168.1.1 is the IP address of my router. Usually, the router’s IP address is the first number of the subnet. However, this is not a hard and fast rule. I have seen routers with x.y.z.30 addresses as well.
Bonus tip
As shared by Samir in the comments, you can also use the ping command to get the gateway IP:
ping _gateway
In case you didn’t know, you have to use the Ctrl+C to stop a running command in Linux.
I hope you find this tip useful when you need it.