Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

networking question

Status
Not open for further replies.

electroRF

Member
Say that PC-A and PC-B are connected to a router, and they both surf to CNN.com.

PC-A IP Address is 10.0.0.3
PC-B
IP Address is 10.0.0.5

Router's WAN IP Address is 12.345.678.9

when CNN replies with a packet to PC-A, it sends it to the Router's WAN IP Address 12.345.678.9 on port 80 (not on other port, correct?), right?

How does the Router knows to forward this packet to PC-A and not to PC-B?

Thank you.
 
Router does IP address translation. It keeps an IP address translation table in its memory as well as physical # of each corresponding port connection. Router knows which port to send out to because it mapped the IP address(s) assigned to each physical port.

It is up to the router to manage any IP address conflicts (two devices having same IP addr). If you assign fixed IP addresses it will warn you of conflict. If you have DHCP active then it coordinates a new IP address assignment to one of the conflict address devices to give it a new IP address that is not in conflict with existing active devices. Sometimes when a computer on the network has been asleep for some time and other new devices come online during the sleep period the DHCP may have reassigned the sleeping computer's IP address to someone else via DHCP assignments. When computer comes out of sleep with it original IP address still active it will be in conflict. The router will have to reassign a new IP address to one of the conflict devices. Most router will try to not to use a previously assigned IP even though it has been inactive for some time until it runs out of available IP addresses. It reassigned the oldest inactive IP address.

For the router, managing the flash memory area for address translation is one of the toughest jobs for its software. I have seen many routers (usually cheap ones) that work fine for six months until the allocated memory area for translation table is full. It must then decide what to throw out to free table memory and defragment its memory space. This is where router software screws up and you begin getting lockups and dropped connections. Doing a hard reset and router reconfiguration wipes the memory clean and router can start over new again.

If you put an unmanaged 4x switch on a router port the router just assigns multiple IP originator addresses to the port (as needed) to the switch. It is up to switch to route the IP addresses on its ports. A switch does not assign IP addresses like a router can (DHCP) on initial connect.

As far as the WAN knows, it just looks like it is talking to a single computer with multiple browser windows open.
 
Last edited:
Hi RC,
Thank you very much.

I read your detailed post several times and there're some matters I did not understand.

Router does IP address translation. It keeps an IP address translation table in its memory as well as physical # of each corresponding port connection. Router knows which port to send out to because it mapped the IP address(s) assigned to each physical port.
You mean that the Router stores in Table the following?
IP - - - - - - - - - Port - - - - -Switch physical Port
10.0.0.3 - - - - 80 - - - - - 1
10.0.0.5 - - - - 80 - - - - - 2
(that is in the case where these two PCs - A, B - surf the web)

Understanding the above (if it's indeed correct, as I'm not sure I followed you),

How does the Router knows to transfer packet from CNN to PC-A (10.0.0.3) and not to PC-B (10.0.0.5)?
 
when CNN replies with a packet to PC-A, it sends it to the Router's WAN IP Address 12.345.678.9 on port 80 (not on other port, correct?)
No, PC-A connects to port 80 at CNN, but it connects from a random port at the PC-A side.
 
Hi RC,
Thank you very much again for the so detailed post!

I think you didn't reach the crucial point of decision - when the Router gets a packet from CNN that is meant for PC-A, how does the Router (or the Switch) know to transfer that Packet to PC-A and not to other PC on the subnetwork?

(As the CNN server sends the packet to the Router IP Address, and not to PC-A IP Address).

Router does IP address translation. It keeps an IP address translation table in its memory as well as physical # of each corresponding port connection. Router knows which port to send out to because it mapped the IP address(s) assigned to each physical port.

It is up to the router to manage any IP address conflicts (two devices having same IP addr). If you assign fixed IP addresses it will warn you of conflict. If you have DHCP active then it coordinates a new IP address assignment to one of the conflict address devices to give it a new IP address that is not in conflict with existing active devices. Sometimes when a computer on the network has been asleep for some time and other new devices come online during the sleep period the DHCP may have reassigned the sleeping computer's IP address to someone else via DHCP assignments. When computer comes out of sleep with it original IP address still active it will be in conflict. The router will have to reassign a new IP address to one of the conflict devices. Most router will try to not to use a previously assigned IP even though it has been inactive for some time until it runs out of available IP addresses. It reassigned the oldest inactive IP address.

For the router, managing the flash memory area for address translation is one of the toughest jobs for its software. I have seen many routers (usually cheap ones) that work fine for six months until the allocated memory area for translation table is full. It must then decide what to throw out to free table memory and defragment its memory space. This is where router software screws up and you begin getting lockups and dropped connections. Doing a hard reset and router reconfiguration wipes the memory clean and router can start over new again.

If you put an unmanaged 4x switch on a router port the router just assigns multiple IP originator addresses to the port (as needed) to the switch. It is up to switch to route the IP addresses on its ports. A switch does not assign IP addresses like a router can (DHCP) on initial connect.

As far as the WAN knows, it just looks like it is talking to a single computer with multiple browser windows open.
 
Hi RC,
Thank you very much again for the so detailed post!

I think you didn't reach the crucial point of decision - when the Router gets a packet from CNN that is meant for PC-A, how does the Router (or the Switch) know to transfer that Packet to PC-A and not to other PC on the subnetwork?

(As the CNN server sends the packet to the Router IP Address, and not to PC-A IP Address).

Hi.. as RC explained the process is very simple.

When your router sends a packet to CNN it puts a source port(random number) and destination port(80) then CNN web server replies with the same port number(random number) into destination port. When your router receives the packet it checks the destination port which will be the same (some random number) and this port identifies which pc requested this packet.

In this way both pc can ask for CNN but the packets random port number will be different and thus identifiable.


simple diagram, SRC=source, DST=destination
acl4.png
 
Last edited:
I could explain in reams exactly how these devices and their protocols work, but I'll try and keep it really simple for ya :)

The Router part of your "Router" maintains a table that maps internal and external IP Addresses and IP Ports. Whenever anything on the "Inside" of your Routers WAN port communicates with the "outside", that is beyond your Router's Wan Port, the Router keeps a note of it. The Router at Cnn does the same. When it responds to your Router, your Router looks at the note it made earlier and forwards this traffic back to the device that started the conversation, in your case PC-A. The processes are known as Network Address Translation (NAT) and Port Address Translation (PAT).
 
Hi.. as RC explained the process is very simple.

When your router sends a packet to CNN it puts a source port(random number) and destination port(80) then CNN web server replies with the same port number(random number) into destination port. When your router receives the packet it checks the destination port which will be the same (some random number) and this port identifies which pc requested this packet.

In this way both pc can ask for CNN but the packets random port number will be different and thus identifiable.


simple diagram, SRC=source, DST=destination
View attachment 82934
Hi SK,

Thanks a lot!

I understood you :)

There's something I don't agree with in the diagram you posted.

The PC's local IP Address is 192.168.0.50.
The PC's random port is 1029.

When the Server sends packet to the PC, the DEST IP Address of this packet should NOT be the PC's, but it SHOULD be the Router's WAN IP Address.

Say that the Router's address is 192.168.0.1 and the Router's WAN IP Address 12.34.233.2, then the Packet from Server to PC should be with:
Dest IP: 12.34.233.2 (NOT 192.168.0.50)
Dest Port: 1029

Am I correct?
 
There is a critical part missing from this discussion. A unique MAC address is assigned to each interface assigned by the manufacturer.

NAT basically pairs the WAN IP address to the MAC address/LAN IP address as it passes through the router.
Kida like packet from 192.168.1.3:80 MAC addr 63 goes to the router, and it gets changed to the wan IP address keeping the MAC address of the router.

Mac addresses are the long hex number on the interface. Usually justa buch of capital eltters from A-F and numbers or a set of multiple pairs of 2 hex digits separated by a colon.

When a packet coming in, wants port 80, the router administrator has assigned what LAN IP address and port should respond to a port 80 request.

At least this is how I understand it. There are a bunch of RFC (Request for comment) defining the protocols.

IP addresses can be public or private. There are three sets of private addresses. 10.x.x.x is one of them, 192.168.x.x is another and there is one more set.

Aside:
So, cable modem BIND the MAC address to the service address at install hence the need to MAC address cloning.

DSL modems typically use PPOE for authentication.
If you bridge a DSL modem, the telephone line goes to a DSLAM and then likely the info gets transmitted via ATM which is a normal telco protocol. The ATM receiver could be in another state and that pool of IP addresess are coming from a large "body of water" and not a "small pool". This is causing problems with online gambling.

It plays some very tricky games to allow you to connect to it to configure the modem.

Now as I understand things right a reverse ping to your IP address is actually stopping very short of the telco lines. A forward PING tests the DSLAM and ATM circuits.

When you don't bridge your connection, I think, the IP address resides at the DSL modem.
 
The process that is used is called masquerading. Without going into details, the router re-writes packets in such a way that for the outside world the connections look like as if they originated from the router, so CNN thinks that it communicates with the router.

Technical details. Each packet has 4 numbers - src IP, src port, dst IP, and dst port. It's easy to write in this form:

src IP:src Port -> dst IP: dst Port

Your computer has IP 10.0.0.3 and assigns a random src port to the socket, say 10001 so src becomes 10.0.0.3:10001 and sends it to CNN port 80 - 157.166.226.25

Packet from a computer to the router with this info: 10.0.0.3:10001 -> 157.166.226.25:80

Your router gets the packet and does masquerading. First, it assign a random port number for this connection (if not done already), say 20001. And it uses its own IP address 12.35.78.9 (cannot be 12.35.678.9). It rewrites the packed so that the source becomes 12.35.78.9:20001. It remembers that packets from 10.0.0.3:10001 were masquraded as 12.35.78.9:20001 in a special masquerading table.

Packet from router to CNN with this info: 12.35.78.9:20001 -> 157.166.226.25:80

CNN receives the packed, and it thinks it's originating from the router, so it responds

Packet from CNN to the router with this info: 157.166.226.25:80 -> 12.35.78.9:20001

Router receives this packet and looks it up in its masqueradig table. It finds out that this needs to be translated to 10.0.0.3:10001.

Packet from the router to the computer with this info: 157.166.226.25:80 -> 10.0.0.3:10001

The computer receives this packed and it thinks it came directly from CNN - it doesn't need to know about the router.

At the same time, there could be a parallel converation with other computer with IP 10.0.0.4

Packet from a computer to the router with this info: 10.0.0.4:10001 -> 157.166.226.25:80
Packet from router to CNN with this info: 12.35.78.9:20002 -> 157.166.226.25:80

Note: router assigns a different local port for this connection (20002) and inserts it into its masquerading table.

Packet from CNN to the router with this info: 157.166.226.25:80 -> 12.35.78.9:20002
Packet from the router to the computer with this info: 157.166.226.25:80 -> 10.0.0.4:10001

Hope this makes sense.
 
Hi SK,

Thanks a lot!

I understood you :)

There's something I don't agree with in the diagram you posted.

The PC's local IP Address is 192.168.0.50.
The PC's random port is 1029.

When the Server sends packet to the PC, the DEST IP Address of this packet should NOT be the PC's, but it SHOULD be the Router's WAN IP Address.

Say that the Router's address is 192.168.0.1 and the Router's WAN IP Address 12.34.233.2, then the Packet from Server to PC should be with:
Dest IP: 12.34.233.2 (NOT 192.168.0.50)
Dest Port: 1029

Am I correct?
Hi.. This diagram is just an example to show a packet contents e.g ip, ports etc.. this diagram is doing routing its not natting, so things go directly from ip to ip. Something like how your isp communicates with your router. Networking is very interesting and believe me its simple you just have to know few rules. Keep on Networking:).

Regards.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top