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
  • 1
    can you show output of netstat -rn ?
    – gelraen
    Apr 21, 2011 at 9:28

7 Answers 7


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.

  • 1
    @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 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 with the MAC address of R1. R1 receives the packet and consult's its own routing tables & forwards the packet to R2, Repeat. May 25, 2015 at 9: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 4, 2015 at 21:50

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


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


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.


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.


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

  • 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, 2011 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. en.wikipedia.org/wiki/Default_gateway en.wikipedia.org/wiki/Router Apr 25, 2011 at 15:05

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 then your ip address will be just an extension to this address like,, 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 to and then to the other routers.Hope you get it.

You must log in to answer this question.