Monday, July 4, 2011

How to find out Gateway/Router IP address under Linux/Unix

Run route command
route -n

Output:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.42.0       0.0.0.0         255.255.254.0   U     1      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth0
0.0.0.0         10.0.43.254     0.0.0.0         UG    0      0        0 eth0

10.0.43.254 is gateway IP address for the computer. The flag U indicates that route is up and G indicates gateway.

You can also run netstat command to find the gateway.
netstat -nr

Output:

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.0.42.0       0.0.0.0         255.255.254.0   U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
0.0.0.0         10.0.43.254     0.0.0.0         UG        0 0          0 eth0



1 comment: