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 command
route
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 route
192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.1
10.78.0.0/24 dev eth0 proto kernel scope link src 10.78.0.21
169.254.0.0/16 dev eth1 scope link
default via 10.200.0.1 dev eth0
Through netstat command
netstat -r
Example:
[root@example ~]# netstat -r
Kernel IP routing table
Destination 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.
How To View Default Gateway In Linux?
7/07/2010 09:11:00 AM Posted by Meghana M BhombhoreLabels: Basics, How-To's
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment