2

I don't understand basic routing concept. Namely, how does remote internet server construct packet when sending it to my local IP address.

Consider real life example. I am connected to the Internet through my provider. Provider gives me and other clients ip addresses from private range 10.100.251.1-255. Suppose that provider gives me ip address 10.100.251.4 dynamically. I wan't open stackoverflow.com(151.101.65.69) site in browser. Heap of gateways exists between me and stackoverflow.com. Last gateway that connects me with external Internet is 85.112.122.13. When I open stackoverflow.com in browser my computer constructs packet with destination address is 151.101.65.69, looks up gateway for this address in routing table and sends packet to gateway. This first gateway does the same and forwards my packet to second gateway, and so on until packet arrives to last gateway 85.112.122.13. Let suppose for simplicity that 85.112.122.13 sends may packet to stackoverflow.com directly. Now stackoverflow.com gets my packet and wants to send me response. But I don't understand how does it do this. All that stackoverflow.com can get from packet is source ip address (10.100.251.4). But this ip address is private and no routers in the internet knows where to send packets for this. Where am I wrong and how internet server sends response to private ip address?

2
  • You forgot to consider NAT, I guess.
    – Daniel B
    Jul 30, 2019 at 11:22
  • @DanielB NAT is precisely the answer to this question, that OP seems to not know about.
    – Darkhogg
    Jul 30, 2019 at 11:24

1 Answer 1

2

One of those gateways – usually the 1st or 2nd – is configured to overwrite the source IP address of all outgoing packets; it "masquerades" the private addresses using its own public address. (This is known as source NAT.)

So stackoverflow.com just sends replies to the NAT gateway's global address and doesn't know your private IP address at all. (And if you check various "what is my IP" websites, you will always see a public address belonging to that gateway.)

The same router also keeps track of every connection, so whenever it receives a packet to its global address, it can look up which host originally initiated the connection and translate the destination address back to the original private address. (In other words, it performs stateful NAT – the information is kept in a "state table" or "conntrack table".)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .