How packets reaches Destination through proxy serv

2019-06-26 07:58发布

问题:

I am confused about how packets from my machine reaches their destination through proxy servers. my machine has a private ip for intranet and we have a proxy server with public ip to talk to world.

so we have three addresses here.

1) my private ip address
2) proxy server address
3) destination address (google.com)

now in the tcp packet that I send I have source and destination port to distinguish the various programs (like mozilla , chrome , ie) on my machine and destinations.

in the ip network layer I have source and destination address.

I don't know whether http also has addresses.

so when my packet leaves my machine, what address would it be containing. so that it reaches my proxy server through gateways in between. ?

once it reaches proxy server, NAT can be used to send it to destination. but I am confused about how it reaches proxy server.

EDIT: should my packet contain address of my proxy server (local private one) to reach it? I can change my proxy server by configuring my browser. how does my packet once it leaves my machine knows which proxy server it would go?

回答1:

The packet doesn't reach the target at all. The data inside it reaches the target as part of a new connection between the proxy and the server, in completely new packets, whose size and number may be different from those in the downstream connection. From the server TCP's point of view it is connected to the proxy, not the downstream client.



回答2:

HTTP sits on top of TCP/IP (along with FTP, SMTP etc)

You configure the proxy server on your PC, so all requests are sent through the proxy (unless they're recognised as local addresses).

When you request a page from "www.google.com:80"

  • your computer looks up the DNS servers for the IP address for the host name
  • your computer figures out that it's not a local IP (it's on a different subnet to the default gateway)
  • Then it says "Hey, gateway/proxy, get me the page from google" (passing the IP address and port for google. HTTP layer will contain headers such as "method=GET", full URL with path & parameters etc)