Thursday, 30 August 2012

How To View Default Gateway In Linux?

This is asked in some of the interviews. We can get default gateway information in linux in many ways. Such as viewing network card file or executing a command.To see default gateway by view network interface card file content.#cat /etc/sysconfig/networking/devices/interface-no
Example :[root@example ~]# cat /etc/sysconfig/networking/devices/ifcfg-eth0
# Intel Corporation 82546EB Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:02:a5:4c:af:99
ONBOOT=yes
TYPE=Ethernet
NETMASK=255.255.255.0
IPADDR=10.200.0.21
GATEWAY=10.200.0.1

Through route commandroute
Example:Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 * 255.255.255.0 U 0 0 0 eth1
10.78.0.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth1
default 10.200.0.1 0.0.0.0 UG 0 0 0 eth0

Through ip route command
ip route

Example :[root@example ~]# ip route192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.110.78.0.0/24 dev eth0 proto kernel scope link src 10.78.0.21169.254.0.0/16 dev eth1 scope link
default via 10.200.0.1 dev eth0

Through netstat commandnetstat -r

Example:[root@example ~]# netstat -r
Kernel IP routing tableDestination Gateway Genmask Flags MSS Window irtt Iface
192.168.0.0 * 255.255.255.0 U 0 0 0 eth1
10.78.0.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth1
default 10.200.0.1 0.0.0.0 UG 0 0 0 eth0

Note:For any system/server there will be only one default gateway, if suppose if you assign two default gateways to your machine, your system will not come to know where to send the packets.

0 comments:

Post a Comment

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | coupon codes