What information does a router use to send a packet?

Most home routers use a special-case of NAT called PAT.

You'll also see it referred to as NAPT, or IP Masquerading. All three of the latter terms mean the same thing in general use. (The acronyms - Network Address Translation / Port Address Translation / Network Address Port Translation)

When the packet goes out from your internal machine, the source address is rewritten as you are aware. The source port is also changed, usually to a high number, and the router keeps an address translation table.

For example, let's say you have a client machine that goes to www.google.com. Your computer (e.g., 192.168.1.100) looks that address up and makes a TCP connection to 72.14.204.147 on port 80 from your internal IP address, using a random source port.

To your computer, the connection looks like this:

192.168.1.100:37641 <--> 72.14.204.147:80

Your computer sends the packet to the router, which picks a new random high port and rewrites the packet. Each outbound connection gets its own port on the router. The router then forwards the packet on to your ISP after adding it to its connection table:

PrivateIP PrivatePort PublicIP PublicPort Remote RemotePort ------------- ---------- ----------- ----------- ---------- ----------- 192.168.1.100 37641 *10.6.23.5 59273 72.14.204.147 80

*For example purposes, I used an address starting with 10, but these aren't publicly routable. The table is also somewhat oversimplified.

To google, the connection looks like this:

10.6.23.5:59273 <--> 72.14.204.147:80

Google will send it's reponse to 10.6.23.5 on port 59273. Your router then looks up that information in the table and forwards the packet on to 192.168.1.100:37641.

If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

A network router plays a crucial role in how data packets travel to and from a computer to host across the Internet. Routers serve as the junction point between the computers in a network and an Internet connection source. Computers transmit data to each other over network connections in data packets, and the router's job is to make sure those data packets get where they are supposed to go.

Packets

  1. A packet is a small data unit that's sent from one device to another over a network. Packets break up larger files into small pieces to reduce the amount of work needed if any information gets lost on its way from one system to another. Packets include a checksum that is used to determine if the packet has been corrupted and contains bad data, meaning that it needs to be sent again until it's correct. If files were sent whole, any errors would break the entire file. Additionally, packets are helpful for when a network becomes overloaded and the router has to turn down packets for transfer at a later time.

Routers

  1. A router is the traffic-control center device that handles the packet transfer process between networks. Essentially, routers determine where to send a data packet and then forward it to the next network point. According to Cisco, routers connect networks and are often confused with other hardware called switches that create networks. The routers commonly found in home and small office networks are actually hybrid devices that combine the functionality of a router, network switch and Wi-Fi adapter into a single unit. The router just handles the data path selection and the data transmission.

Router Path

  1. An incoming data packet has to get to the computer that requested it -- that's one of the router's jobs. The router discovers all of the computers and devices connected to the network and acts as the gatekeeper. If the packet is coming from an outside host, the router directs the packet from the modem to the computer that's supposed to receive the data. Additionally, the router also handles sending the outgoing packet requests to the modem.

Router Transmission

  1. The router's next job after determining the path it's going to send a data packet is to transmit the packet to its next stop on its destination. When dealing with a host across the Internet, the router transmits the incoming data that it receives from the modem to the computer or from the computer to the modem, which sends the information across the Internet to the host.

Previously, we looked at a simplified IP packet, with fields for the source and destination addresses as well as the data it transports.

Previously, we looked at a simplified IP packet, with fields for the source and destination addresses as well as the data it transports. In a real IP packet header there are several other fields.

What information does a router use to send a packet?

  • IHL indicates the header length.
  • Packets use Type of Service to request special treatment (e.g. being put at the front of any queues).
  • The identification, flags, and fragmentation offset fields keep track of each fragment when an IP packet is split up into smaller packets.
  • The time to live is set when the IP packet is sent off, and the number is reduced by 1 each time the packet goes through a router. When the time to live gets to 0, the packet is deleted. This stops packets from circulating in a loop.

You can find all the details about the header of IPv4 packets as well as the header of IPv6 packets on Wikipedia.

Routers and routing

Routers got their name because they route IP Packets across networks: a router device connects different links. It examines IP packet headers, looking at the destination address and consulting a routing table of known networks. The table indicates which connections to send the packet on as the next link. The connections on a router are called interfaces: through the router, they interface between different link types.

What information does a router use to send a packet?

In the animation, an IP packet arrives at a router, which compares the packet’s destination address with the networks in the routing table. The packet is identified as belonging to network A, so the router routes it out of interface 1.

Often, routers learn how to reach distant networks by exchanging information with their neighbouring routers and building their own routing tables. This exchange of information to learn about other networks is called a routing protocol. You can find more information about routing protocols on Wikipedia.

Note: the term ‘routing protocol’ can be easily confused with routed protocol. IP is a routed protocol: routers examine IP packets and route them out of an interface based on the destination IP address.

Routing on Home and Small Business Networks

A home or small-business network usually has a single LAN, which a router connects to an ISP.

  • Each of the network’s devices, including the actual interface on the router for the LAN, will have a 192.168.1.X address. The internal LAN’s network address is therefore 192.168.1.0.

  • The Router’s WAN interface has the address 82.5.6.11, which is part of the ISP’s 82.0.0.0 network.

So the router is connected to two different IP networks, which are automatically placed into the routing table. The default network, 0.0.0.0, gets configured so it sends data out via the WAN interface and onto the next router.

Each router examines and sends each IP packet individually — this is called packet switching. If the network changes, due to congestion or faults, routers can use an alternative interfaces to reach a destination. So packets may travel over different routes to reach the same destination.

Possible point of confusion: despite the fact that this is called ‘packet switching’, no switch devices are involved. Switches switch data frames between ports, whereas routers route IP packets between interfaces.

Telephone systems use circuit switching: they send an initial packet to the destination, and along its path, this first packet reserves capacity on all of the links it uses. It sets up a fixed route on each router specifically for this connection. This creates a guaranteed connection from end to end for the duration of the call. If capacity is unavailable, then no connection is made and the system terminates the call.

The internet

The internet is the interconnection of all the different networks that we have discussed, and that people have created and are using in different capacities. For example:

  • Home users with single LANs
  • Users around the world connecting to ISPs through smartphones
  • Small and large companies with LANs and WANs
  • Governments and ISPs with WANs that span the globe

ISPs interconnect with other ISPs, and this connects everything together into a gigantic WAN. This is the internet, which you’ll learn more about next week.

What information does a router use to send a packet?

It’s estimated that almost 50% of the world’s population has access to the internet.

Next up

In the next step, we’ll show you how you can see the routers that your IP packets pass through on the way to a web server.

Questions

  • Can you guess where fragmented IP packets are reassembled, and why that location?
  • What do you think happens if a fragment of an IP packet fails to arrive?
  • If a large corporation has multiple connections to the internet via different ISPs, how does it choose which way to send traffic?

Join in the conversation in the comments below to share your ideas.