Router – What’s the difference between a gateway and a router

gatewaynetworkingrouter

Here we can see the router is 67.23.27.187(first hop), but the gateway is 67.23.27.1. What's the difference between a gateway and a router? How does my computer know the IP of the router when only the gateway address is configured?

[root@jiaoyou ~]# tracepath google.com
 1:  67-23-27-187.static.slicehost.net (67.23.27.187)       0.000ms pmtu 1500
 1:  67-23-24-2.static.slicehost.net (67.23.24.2)           0.000ms 
 1:  67-23-24-2.static.slicehost.net (67.23.24.2)           4.000ms 
 2:  core7-aggr511a-1.dfw1.rackspace.net (98.129.84.148)  128.008ms 
 3:  bbr1-core7-vlan2007.dfw1.rackspace.net (174.143.123.117)   4.000ms 
 4:  no reply
 5:  no reply

[root@jiaoyou ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=jiaoyou
GATEWAY=67.23.27.1

Best Answer

A gateway and a router are essentially the same. The term "default gateway" is used to mean the router on your LAN which has the responsibility of being the first point of contact for traffic to computers outside the LAN.

If your LAN has multiple routers, the router designated as a default gateway can notify your computer, using an ICMP redirect or other mechanism, of a more appropriate route for a given destination.

For example


                   (Internet)---[Google]
                       |         64.20.60.99
                      [R2]
67.23.27/255           |187
|------+--------+------+-----|
       |9       |1
     [PC]     [R1]
                |      67.23.28/255
           |----+------+----------|
                       |9
                    [Server]

If router R1 is PC's default gateway, when PC first tries to contact Google, PC will send data to R1 (as PC knows Google's IP-address is not in PC's subnet), However R1 will tell the PC that a more appropriate route to 64.20.60.99 is via router R2. PC will add this to it's routing table, hence R1 won't show in a subsequent traceroute.

The command netstat -nr on your PC will reveal both the static routes it learned from it's configuration files and the dynamic routes it learned by ICMP redirects or by listening to routing protocol broadcasts/multicasts.

The term "gateway" has other connotations that are not relevant for the file and command in your question.