Take the 2-minute tour ×

Here we can see the router is hop), but the gateway is 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 (       0.000ms pmtu 1500
 1:  67-23-24-2.static.slicehost.net (           0.000ms 
 1:  67-23-24-2.static.slicehost.net (           4.000ms 
 2:  core7-aggr511a-1.dfw1.rackspace.net (  128.008ms 
 3:  bbr1-core7-vlan2007.dfw1.rackspace.net (   4.000ms 
 4:  no reply
 5:  no reply

[root@jiaoyou ~]# cat /etc/sysconfig/network
share|improve this question

migrated from stackoverflow.com Apr 21 '11 at 8:43

This question came from our site for professional and enthusiast programmers.

can you show output of netstat -rn ? –  gelraen Apr 21 '11 at 9:28

6 Answers 6

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

67.23.27/255           |187
       |9       |1
     [PC]     [R1]
                |      67.23.28/255

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 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.

share|improve this answer

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


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 is either next-hop for or the next-ip for the path to the google.com

share|improve this answer
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
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. en.wikipedia.org/wiki/Default_gateway en.wikipedia.org/wiki/Router –  adrian_sev Apr 25 '11 at 15:05

@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).

share|improve this answer

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.

share|improve this answer

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."

share|improve this answer

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.

share|improve this answer

Your Answer

