Tuesday, May 1, 2012

Ubuntu Linux: Find Out Default Gateway

How do I find out default gateway IP address (default router IP assigned) for my Ubuntu Linux systems?

Use the route or ip command to get default routing table for Ubuntu Linux. Open the terminal and type the following command:
route -n
Sample outputs:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 0.0.0.0 255.255.255.0 U 2 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 wlan0
0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 wlan0
Destination for 0.0.0.0 is set to 192.168.2.1 via wlan0 interface i.e. 192.168.2.1 is default gateway. If you just type the route command with the -n switch it show word default instead of 0.0.0.0:
route
Sample outputs:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 * 255.255.255.0 U 2 0 0 wlan0
192.168.1.0 * 255.255.255.0 U 1 0 0 eth0
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
link-local * 255.255.0.0 U 1000 0 0 wlan0
default 192.168.2.1 0.0.0.0 UG 0 0 0 wlan0

ip route Command

The following command does the same thing:
ip route show
Sample outputs:
192.168.2.0/24 dev wlan0  proto kernel  scope link  src 192.168.2.3  metric 2
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.254 metric 1
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
169.254.0.0/16 dev wlan0 scope link metric 1000
default via 192.168.2.1 dev wlan0 proto static

No comments:

Post a Comment