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 |