A large network like the internet can have multiple smaller interconnected networks. A gateway is a network node or point which serves as the access point to another network. All your traffic first goes to the router and then to the rest of the internet.
There are various ways to find gateway or router IP address in Linux a few of them are discussed here in this article.
How to find default gateway or router IP using IP command
The ip command is a very useful tool to configure network interfaces. We will use this command here to display the default gateway or router IP address.
Open your terminal and run the following command –
ip r
or you can use –
ip route
As you can see in the output of this command the IP address 192.168.122.1 is the default gateway or router IP address which is given in the first line.
Find default gateway using the route command
The route command is used to display and manipulate the IP routing table. You can use the option -n
with the route command to display the default gateway. Before using this command you may need to install the net-tools
package in some Linux distributions.
Use the following command to install it –
sudo apt install net-tools
After installing net-tools
, run the following command –
route -n
See the output of this command the UG in the flag column corresponding to the IP address 192.168.122.1 means up(U) and gateway(G). The IP address 192.168.122.1 is the default gateway or the router IP address.
Find default gateway using netstat command
The netstat command is used to monitor the network connections also it is used to displays the routing tables, interface statics, etc. This tool is available for various operating systems including Windows.
Now use the -rn
options with netstat command to display the default gateway or router IP –
netstat -rn
The UG given in the first line of flags column means up and gateway and the IP 192.168.122.1 is the default gateway or router IP address.
Conclusion
By using any one of the given commands you can easily find the default gateway or router IP. Now if you have any queries on this you can write to us in the comments below.