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:
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... 60.192.194.32, 61.54.192.95, 77.36.14.19, ...
Connecting to external.example.net|60.192.194.32|: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
wget:
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'
Squid log
7 1.2.3.4 TCP_HIT/200 84455 GET http://external.example.net/v4/Picture/pic1.jpg - NONE/- image/jpeg
Why doesn't my first request work?