Friday 18 November 2016

Default Gateway in Linux

What is Gateway?
A gateway is a network point that acts as an entrance to another network. On the Internet, a node or stopping point can be either a gateway node or a host (end-point) node. Both the computers of Internet users and the computers that serve pages to users are host nodes. The computers that control traffic within your company’s network or at your local Internet service provider (ISP) are gateway nodes. In the network for an enterprise, a computer server acting as a gateway node is often also acting as a proxy server and a firewall server. A gateway is often associated with both a router, which knows where to direct a given packet of data that arrives at the gateway, and a switch, which furnishes the actual path in and out of the gateway for a given packet.

How to find default gateway?
rahul-linux:~$ ip route show
default via 192.168.1.1 dev eth1  proto static
192.168.1.0/24 dev eth1  proto kernel  scope link  src 192.168.1.100  metric 1

rahul-linux:~$ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth1
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth1

The flag U indicates that route is up and G indicates that it is gateway.

rahul-linux:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth1
192.168.1.0     0.0.0.0         255.255.255.0   U     1      0        0 eth1

How to find gateway?
[root@rhel7 ~]# routel
         target            gateway          source    proto    scope    dev tbl
      10.0.0.0/ 8                        10.1.1.56   kernel     link enp0s3
       10.0.0.0          broadcast       10.1.1.56   kernel     link enp0s3 local
      10.1.1.56              local       10.1.1.56   kernel     host enp0s3 local
 10.255.255.255          broadcast       10.1.1.56   kernel     link enp0s3 local
      127.0.0.0          broadcast       127.0.0.1   kernel     link     lo local
     127.0.0.0/ 8            local       127.0.0.1   kernel     host     lo local
      127.0.0.1              local       127.0.0.1   kernel     host     lo local
127.255.255.255          broadcast       127.0.0.1   kernel     link     lo local

[root@rhel7 ~]# cat /etc/sysconfig/network
GATEWAY="10.1.1.1"

[root@rhel7 ~]# routel | grep default
        default          10.1.1.1                   static          enp0s3
        default        unreachable                   kernel              lo unspec
        default        unreachable                   kernel              lo unspec

No comments:

Post a Comment