When does a router know to send a packet to the internet and not over LAN

2

Assuming a router has a built in switch which passes data packets to machines on the LAN based on the MAC address of all locally connected devices I want to know when and how (readying the packet for the internet using IP addresses) its sent to the internet. I'm making an assumption that all local options are exhausted first but I thought it might be more intelligent than that.

W0lf7

Posted 2013-07-24T22:31:01.893

Reputation: 131

1

For the long and ugly detail see: http://serverfault.com/questions/49765/how-does-ipv4-subnetting-work

– Zoredache – 2013-07-25T00:05:01.520

Answers

3

NOTE: DNS resolution occurs before any of the below in order to determine destination IP address.

If the request IP Address is on your local LAN, your router doesn't even get involved (aside from the switch part which is a series of ethernet ports).

Your local routing table (command line route print on win, plain route on lin) shows you the routing table that the OS uses to figure out what interface to send the packet out of depending on addressing. The IP stack will then do an arp request to find the MAC for the machine on the local network and establish direct communications through the switch.

If the IP address is foreign to your local network, then the OS routing table sends it to the gateway address, which is your router and your router uses a similar routing table to forward the packet to its gateway, ad nauseum till it gets to destination.

Fiasco Labs

Posted 2013-07-24T22:31:01.893

Reputation: 6 368

0

At a very simple level, you are right.

Take Google. When you request Google.com, your router first checks its own local tables, if there is no matching table (Host / IP) then it passes it to your modem. The modem then does essentially the same thing, and sends the request to its DNS server, which might be the ISPs or a third party, this is repeated until it reaches either a router that has the correct entry or reaches the iana root servers.

Austin T French

Posted 2013-07-24T22:31:01.893

Reputation: 9 766