Find Out The Default Gateway In UNIX Box

In Linux box, we can find out the default gateway for active connection by using the following commands :

root@tedy-laptop:/# ip route
10.181.190.0/23 dev eth0  proto kernel  scope link  src 10.181.190.235  metric 1
10.189.104.0/22 dev wlan0  proto kernel  scope link  src 10.189.104.105  metric 2
169.254.0.0/16 dev eth0  scope link  metric 1000
default via 10.181.190.1 dev eth0  proto static
root@tedy-laptop:/#

If we use ip route command, the gateway indicated by “via”; and default means all IP. It same like 0.0.0.0 in the following command :

root@tedy-laptop:/# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.181.190.0    0.0.0.0         255.255.254.0   U         0 0          0 eth0
10.189.104.0    0.0.0.0         255.255.252.0   U         0 0          0 wlan0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
0.0.0.0         10.181.190.1    0.0.0.0         UG        0 0          0 eth0
root@tedy-laptop:/#

In Solaris box, we can find out the default gateway for active connection by using the following commands :

root@test-box02# cat /etc/defaultrouter
10.21.75.1
root@test-box02#
root@test-box02# netstat -rn | grep default
default              10.21.75.1           UG        12802016
root@test-box02#

Leave a Reply

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