Skip to main content
Tips

How to Find Default Gateway IP in Linux

This quick Linux tip shows various methods to find gateway IP address of your router in Linux command line.

Abhishek Prakash

In an earlier article, I told you about finding IP address in Linux command line. In this quick tip, I’ll show you how to find the default gateway IP in Linux command line.

A gateway is works as the entrance or a door between two networks. A router is an example of the gateway. All your traffic goes to the router and then to the rest of the internet.

Sometimes, you’ll need to know the IP address of your router. The gateway IP is your router’s IP address in the normal setup.

I am going to use the IP command to show the gateway IP in Linux.

Open a terminal and use the following command:

ip route

You should see an output like this:

default via 192.168.0.1 dev wlp58s0 proto dhcp metric 600
169.254.0.0/16 dev wlp58s0 scope link metric 1000
192.168.0.0/24 dev wlp58s0 proto kernel scope link src 192.168.0.106 metric 600

Focus on the line that starts with default. This will give the default gateway IP.

Alternatively and conveniently, you can use the above command in combination with the grep command:

ip route | grep default

This will just give the default gateway IP in the output:

default via 192.168.0.1 dev wlp1s0 proto dhcp metric 600

And as you can see, 192.168.0.1 is the default gateway IP in my case.

Other methods to find gateway IP address in Linux

The IP command in Linux provides most of your basic networking needs. But as you have already noticed by now, there are multiple ways to do a certain things in Linux.

To know the gateway IP, you can use other networking command line tools as well. Let me show them to you.

Find gateway in Linux with route command

You can use the -n option with the route command to display the routing table with the IP addresses.

route -n

The sample output should be like this:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    600    0        0 wlp58s0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 wlp58s0
192.168.0.0     0.0.0.0         255.255.255.0   U     600    0        0 wlp58s0

Notice the U and G flags? U means the route is ‘up’ and the G indicates that it is gateway.

Show gateway in Linux with netstat command

To display the gateway information, you can use the netstat command and display the routing table that consists the gateway as well.

netstat -r -n

Output should be identical to what you saw with the route command:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG        0 0          0 wlp58s0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 wlp58s0
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 wlp58s0

You can identify the gateway with the G flag.

Conclusion

I hope this quick Linux tip helped you in finding the default gateway IP in Linux command line. Add this website to your feed reader for such regular Linux tips and tutorials.

Abhishek Prakash