1

Allow me to elaborate.

It recently struck me that, if you want to visit a machine, you need to know its IP address. Fair enough. But if it was behind a router, then you will have to have the router properly configured to forward your packet to the target machine, which can be accomplished by using a port number, again, fair enough.

But it begs a slightly more complicated question, what if your target machine is behind 2 or more tiers of routers? How does that work?

I'm sure it works, since machines like that can browse internet without any problem.

Help? Please?

3
  • 1
    Ports are a layer 4 feature, so they have nothing to do with routing.
    – Ron Trunk
    Oct 2 '16 at 12:23
  • Then both routers need to be properly configured.
    – user253751
    Nov 3 '16 at 3:01
  • Did any answer help you? If so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer.
    – Ron Maupin
    Aug 15 '17 at 4:15
1

Router learn about routes in three ways:

  1. Directly connected networks
  2. Manually configured static routes
  3. Dynamically through routing protocols

A router, receiving a packet on an interface will look at the destination address of the packet (as Ron Trunk pointed out, ports have nothing to do with the routing decisions), and it will look in its routing table to see if it knows how to forward the packet toward its destination.

If the router doesn't find any sort of match in its routing table, it will discard the packet.

If the router finds a match, even if it is only a default route, it will forward the packet out the new interface toward its destination. The interface towards the packet destination can be connected to another router, and the new router will repeat what the first router did. This router lookup and forward goes on until the packet gets to the network where the destination host is.

0

Thats a good question!

This is your situation if im not wrong: (Router A)[10.10.10.1][Gig0/1]-----------[10.10.10.2][Gig0/1](Router B)

If you add another Router (Router C) to the equation, you end up with this:

(Router A)[10.10.10.1][Gig0/1]-----------[10.10.10.2][Gig0/1](Router B)[Gig0/2][10.20.20.1]---------(Router C)[Gig0/2][10.20.20.2]

Now lets add the servers:

(Server 1)[20.10.10.1][Gig0/2]----[Gig0/2][20.10.10.2](Router A)[10.10.10.1][Gig0/1]-----------[Gig0/1][10.10.10.2](Router B)[10.20.20.1][Gig0/2]---------[Gig0/2][10.20.20.2](Router C)[Gig0/1][30.10.10.2]-----[Gig0/1][30.10.10.1](Server 2)

If (Server 2) wants to send a packet to (Server 1) then (Router C) will have to know what to do with that. Routers have IP tables, which they populate with routing protocols (you can read more about them:RIP, OSPF, BGP.. others), in this case one of those protocols will be in charge of letting each router know which network is connected to who. In this example Router C will know that in orther to get to the 20.10.10.0/24 network it has to send that traffic to Router B and that is how Internet works! (basic example)

I hope I explained myself

0

Based on your mention of ports I will assume that when you say "router" you actually mean "NAT box". In the home and small buisness markets boxes that come configured by default as NAT boxes are sold as "routers".

So you have your client machine and you have two NAT boxes between your client machine and the Internet. Your client wants to retrive a web page from a server on the Internet.

What happens is.

  • Your client sends the intital packet with it's interface IP (most likely a private IP) as source IP, a random source port and the destination IP and port of the server. It sends the packet to it's default gateway which points at the inside interface of the Inner NAT box.
  • The packet hits the Inner NAT box. This changes the source IP to it's outer address (likely another private address) and possiblly changes the source Port. It then creates an entry it's NAT mapping table and forwards the packet to it's default gateway which points at the Outer NAT box.
  • The packet hits the Outer NAT box. This changes the source IP to it's outer address (this time a public address) and possiblly changes the source Port. It then creates an entry it's NAT mapping table and forwards the packet to it's default gateway which points at a router at the ISP.
  • The ISPs deliver the packet through their (non NAT) routers to the server. This routing may depend on statically configured routes, routing protocols or some combination of both.
  • The server receives the packet and crafts a reply, in the reply the source IP/port is swapped with the destination IP/port. So the destination now points back at the outer NAT box.
  • The ISPs deliver the packet through their (non NAT) routers to the outer NAT box. This routing may depend on statically configured routes, routing protocols or some combination of both.
  • The outer NAT box looks up the packet's IPs and Ports in it's NAT mapping table and performs a reverse translation. The destination now points at the inner NAT box and the packet is sent there.
  • The inner NAT box looks up the packet's IPs and Ports in it's NAT mapping tables and performs a reverse translation. The destination now points at the client and the packet is sent there.
  • The client receives the reply and communication continues back and forth.

If you wanted to run a server behind two NAT boxes you would have to manually configure port forwarding rules in both NAT boxes so the outer NAT box would point the traffic at the inner NAT box, then the inner NAT box would point it at the client.

0

You were on target until the fourth sentence:

But if it was behind a router, then you will have to have the router properly configured to forward your packet to the target machine, which can be accomplished by using a port number

The last part of that sentence is inaccurate, namely, "which can be accomplished using a port number." Port numbering is not required for your packet to reach the endpoints NIC card. The port number comes into play within the endpoint (computer) as the packet gets consumed (routed to / unpackaged) by a particular application.

IP addressing is how packets are forwarded through an IP based network. That's it. Each router in the path simply has a route to the endpoints address, or it doesn't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.