Posted: . At: 1:48 PM. This was 8 years ago. Post ID: 8702
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

How to find out the gateway IP address of your Linux machine on a LAN.

This is how you find out the gateway IP address of your Linux machine on a LAN. I have executed the route -n command and I have this output. The UG flags on the IP address denote it as a gateway IP address.

root@darknet:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.128.128.128  0.0.0.0         UG    1024   0        0 wlan0
10.0.0.0        0.0.0.0         255.0.0.0       U     0      0        0 wlan0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 wlan0

This is also another way to find out this information. The ip route command will give you the gateway IP address.

root@darknet:~# ip route
default via 10.128.128.128 dev wlan0  proto static  metric 1024 
10.0.0.0/8 dev wlan0  proto kernel  scope link  src 10.41.47.187 
169.254.0.0/16 dev wlan0  scope link  metric 1000

Yet another way, the netstat -r -n command, this will give the gateway IP address.

root@darknet:~# netstat -r -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.128.128.128  0.0.0.0         UG        0 0          0 wlan0
10.0.0.0        0.0.0.0         255.0.0.0       U         0 0          0 wlan0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 wlan0

These commands are a great way to get information about your IP address and the all important gateway IP that the network user was after. Interesting and very useful if the IP address of the router has been forgotten…

And here is an even quicker way.

ubuntu ~ $ ip route | grep default
default via 172.31.16.1 dev eth0

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.