15

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
masegaloeh
  • 17,978
  • 9
  • 56
  • 104

7 Answers7

20

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.

smitelli
  • 1,214
  • 1
  • 10
  • 16
RedGrittyBrick
  • 3,792
  • 1
  • 16
  • 21
  • @Eugene: The diagramming style is based on classic 10-Base-2 Ethernet diagramming style. Regard it as symbolic. All devices attached to a horizontal line are linked by an Ethernet switch (or hub, it doesn't affect the answer). Server knows 60.20.60.99 is on a different subnet (by comparing addresses after applying the netmask) so it looks in it's routing table to find a route. It probably only has a default route for R1 so it assembles a packet with data for 60.20.60.99 with the MAC address of R1. R1 receives the packet and consult's its own routing tables & forwards the packet to R2, Repeat. – RedGrittyBrick May 25 '15 at 09:16
  • There is also an explanation which doesn't involve any redirects. It may simply be that the gateway has multiple addresses and is using a different address as source for ICMP error messages than the one used by the client in ARP requests. – kasperd Jun 04 '15 at 21:50
8

@RedGrittyBrick is absolutely correct with his answer ("a router and a gateway are essentially the same"), some other responders are confusing the terms or, to put it kindly, have misunderstood the question (or wikipedia).

As far as routing goes the term "gateway" is almost only ever used in conjunction with "default", and that "gateway" provides a route to every network for which there is no more specific route available.

By definition then, the gateway must be a device that does routing, it could be a dedicated device, specifically a router, or a host which has been configured to route, but it is doing the same job. Thus a gateway can be a router and a router can be known as a gateway.

There is no difference in TTL between a "default gateway" and a router, once a device which is doing routing passes an IP packet from one network/subnet to another it must decrement the TTL, that is made quite clear in the relevant RFC.

A gateway need not be doing NAT, typically a home network will have a default gateway that is a router connected to ADSL, that type of device will do NAT, whereas the default gateway on your subnet at work will just lead to the wider office LAN and will not do NAT.

In answer to your question about getting out to somewhere that is not on the local subnet, @RedGrittyBrick is again correct about the ICMP redirects, in addition, the process that a host goes through when sending out a packet is this:

1 - Use own IP address and mask to check if destination packet's IP address is in local subnet.

2 - If destination in local subnet, send ARP request for MAC address of that local device then send frame to host.

3 - If destination not in local subnet, send ARP request for MAC address of gateway to that network then send frame to gateway for onward forwarding (at which point the point about ICMP redirects may kick in).

Thus it can be seen that every host makes a routing choice of its own prior to sending out packets (of course this data is cached so lookups are not occurring for every single packet).

blankabout
  • 1,004
  • 1
  • 9
  • 16
3

A router serves as a gateway, but with additional functionality. Per wikipedia: "A gateway is an essential feature of most routers, although other devices (such as any PC or server) can function as a gateway."

DavidO
  • 151
  • 4
1

What is your IP?

Packets originating from the router itself will not have the Time-To-Live (TTL) reduced as they exit the router.

Packets from another source passing through a router will have it's TTL reduced by 1 at each hop. If the packets enter the router with a TTL of 1 and the router is the destination then the traffic will be received by the router. If the router is not the destination the packets will have their TTL reduced to 0 before exiting the router and will be dropped.

Bart De Vos
  • 17,761
  • 6
  • 62
  • 81
MealstroM
  • 1,517
  • 1
  • 16
  • 31
0

A gateway governs access of computers in a network to other computers.

A router is a special form of a gateway: It can forwards IP packets between different networks.

In your case, the gateway knows the router and forwards all requests which are for non-internal addresses to the router.

Aaron Digulla
  • 954
  • 1
  • 13
  • 24
0

Usually the "gateway" is a machine that make NAT "masquerading" and that means that the gateway send out the request for data in the name of private IPs for which the respective machine is gateway, and when the data is back, pass the data to those private IPs. If you will, it can be said that the gateway "impersonates" the private IP machines with regard to the internet.

A router OTOH just rutes packets from one interface to the other. Having a set of rules (static set up or dynamically set up (routing protocols)) the router know to send the packets on a specific interface in order for those packets to reach the desired network

http://en.wikipedia.org/wiki/IP_masquerading
http://en.wikipedia.org/wiki/Routing

and to answer specifically to your question: "how does my computer know the IP of the router when only the gateway address is configured" : each connected machine will know the address of his "next-hop" ip (gateway). the next-hop of a gateway is the ip of an connected interface of a router that have the knowledge to direct your packets to the proper paths to reach the destination network

also: YOUR next-hop is 67.23.27.1.
67.23.27.187 is either next-hop for 67.23.27.1 or the next-ip for the path to the google.com

  • you are confusing the more generic term gateway with the tcp/ip term gateway. Every router between subnets is a gateway with the default gateway for any device being where any destination not in the routing table (typically outside your subnet) is sent. – JamesRyan Apr 21 '11 at 10:06
  • 1
    well, i intended what i said! its true that there is the "gateway of last resort"(default route) or "next-hop" connections but from what i understood i thought that the question was about the general terms of "gateway" and "router". There are 2 questions in the main post and i mainly answered to the first one. http://en.wikipedia.org/wiki/Default_gateway http://en.wikipedia.org/wiki/Router – Adrian Sevcenco Apr 25 '11 at 15:05
-2

well when the transmission is within one local area or a LAN the router in that case is called as a gateway for examples suppose you have 6 houses in your locality(just an example) now all want to access internet you will be having a common router first of all which will be called as a gateway.Now if the address of the gateway(ip address not the mac) is something like 192.128.1.1 then your ip address will be just an extension to this address like 192.128.1.101,192.128.1.102,192.128.1.103...and so on.Now the gateway is further connected to internet which has a huge huge network of gateways but this time those will be called as routers.So in your case the first hop is from your house to the gateway that is from 67.23.27.187 to 67.23.27.1 and then to the other routers.Hope you get it.