1. Overview

Every device on a network, such as a laptop, tablet, or mobile, has an IP address associated with it. Even our router has an IP address. This address is used to access the router’s setup page for administrative control and configuration. Once we have the router’s IP address, we can log in and change the WiFi SSID and password, block certain users, adjust security settings, configure port forwarding, and perform other tasks.

There are various methods to find the IP address of a router in a Linux system. In this tutorial, we’ll look at some command-line and GUI methods to display the IP address of the router.

2. Router’s IP Address vs. Default Gateway

A router’s IP address is the address assigned to a router for accessing its configuration page and for other devices to communicate with.

On the other hand, the default gateway in a network is the address where traffic is sent when it’s destined outside the current network, such as the Internet. Although the default gateway and the router’s IP address serve different purposes, in many cases, such as home networks, the default gateway IP address is the same as the private IP address of the router. This means that all devices on the local network use the router’s IP address as their default gateway.

Now, let’s find the IP address of our router using different methods.

3. Using the netstat Command

netstat is a command-line tool in Linux that displays information about routing and network connections on the local system. It also shows which ports are currently in use and the processes using them.

The netstat command can also display the IP address of our router. For this, we’ll need to run netstat with the -rn options:

$ netstat -rn | awk '$1 == "0.0.0.0" {print $2}' | head -1
192.168.44.2

The -r option in this command displays the kernel routing table, while the -n option displays the addresses numerically. From the output, we can find the IP address of our router, which is 192.168.44.2, listed next to the o.o.o.o destination address. Using awk and head -1, we can extract the IP address from the routing table.

4. Using the arp Command

ARP cache stores the mapping of MAC addresses to IP addresses. The arp command displays and modifies the entries to the ARP cache. It also enables us to find the IP address of our router. Using arp along with the awk command, we can print the IP address of our router:

$ arp -n | awk 'NR == 2 {print $1}'
192.168.44.2

Notably, this command displays the IP address of the router only if our machine is the only one on the network.

5. Using the ip route Command

The ip route command is used to view or manipulate entries in the Linux system’s routing table. We can use the command to create, delete, or modify static routes to specific hosts or networks. We can also find the IP address of the router using the ip route command:

$ ip route show | grep -i 'default via' | awk '{print $3}'
192.168.44.2

The ip route command shows the contents of the routing table. Using the grep command, we can filter the specific line containing the IP address. Then, using the awk command, we can print only the required output, which is the IP address of our router.

6. Using the nmcli Command

nmcli is a Linux command-line utility that can gather network device information. We can also use this command to manage network devices, such as when creating, editing, activating, and deactivating network connections.

Let’s display the IP address of the router using the nmcli command:

$ nmcli dev show ens33 | grep 'IP4.GATEWAY' | awk '{print $2}'
192.168.44.2

In this case, ens33 is the network interface of our system. The nmcli command we used above shows the network interface properties, whereas grep and awk filter the output to show only the IP address of the router.

7. Using the route Command

Similar to ip route, we can also use the route command to display and modify the routing table entries in a Linux system.

To display the IP address of our router, we can use the route command with the -n option:

$ route -n | awk '$1 == "0.0.0.0" {print $2}' | head -1
192.168.44.2

The -n option displays the routing table in numerical format. We can find the IP address of our router, 192.168.44.2, listed against the 0.0.0.0 IP address. Consequently, we use awk and head -1 to extract the IP address from the routing table.

8. Using a GUI

There’s also a graphical way to display the IP address of the router. Here, we’re using the GNOME desktop environment.

To do this, we should right-click the desktop and select Display Settings:

Open Settings window

This will open the Settings window. From the left tab of the Settings window, we click on Network. This opens our system’s network settings. Then, we click the cog icon next to the network adapter:

Open network adapter settings

This will display the network adapter properties. Among other information, we can also find the IP address of our router, 192.168.44.2, which is listed against the Default Route entry:

Network adapter properties

Once we’ve found the IP address of our router, we can now easily access and log in to its web page for configurations.

9. Conclusion

In this article, we’ve covered different ways to display only the IP address of a router in a Linux system. These methods include utilizing tools such as netstat, arp, ip route, nmcli, route, or GUI settings to obtain the information we need. Using either these command-line tools or the graphical way, we can easily find the router’s IP address and configure its settings.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.