I have server A with IP 192.0.2.2, which does not have a connection to the internet so it must pass all internet http traffic to a squid proxy on server B with ip 192.0.2.3 listening on port 8080.
I used the following rule which does establish a connection to the squid proxy, however I get back a 400 bad request error when I initiate a wget:
iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination IP:8080
wget external.example.net/v4/Picture/pic1.jpg --2015-09-05 18:42:01-- http://external.example.net/v4/Picture/pic1.jpg Resolving external.example.net... 188.8.131.52, 184.108.40.206, 220.127.116.11, ... Connecting to external.example.net|18.104.22.168|:80... connected. HTTP request sent, awaiting response... 400 Bad Request 2015-09-05 18:42:01 ERROR 400: Bad Request.
When I check the squid log I see the domain is missing from the url.
1 192.0.2.2 NONE/400 1186 GET /v4/Picture/pic1.jpg - NONE/- -
If I use bash http_proxy instead of the iptables rule I can successfully download the image and squid logs the complete url
export http_proxy=http://192.0.2.3:8080 wget external.example.net/v4/Picture/pic1.jpg
2015-09-05 18:55:48-- http://external.example.net/v4/Picture/pic1.jpg Connecting to 192.0.2.3:8080... connected. Proxy request sent, awaiting response... 200 OK Length: 83760 (82K) [image/jpeg] Saving to: `pic1.jpg'
7 22.214.171.124 TCP_HIT/200 84455 GET http://external.example.net/v4/Picture/pic1.jpg - NONE/- image/jpeg
Why doesn't my first request work?