How to forward http request to a proxy server?
I have an Internet Linux server and my client computer (running windows) accesses internet via a SSH tunnel to the the server.
Now for some reason this server can only accesses internet by a http proxy with port 8118 (running on another server). As a result, my client computer lost its Internet connection.
I've tried to redirect port 80 to 8118 by add a OUTPUT rule into nat table (iptables), but it doesn't works.
How to make my client computer online?
Solution 1:
You should be able to use iptables for this but you probably just want to forward all the 80 traffic to the proxy with a forwarding rule. Try this:
First make sure forwarding is allowed:
cat /proc/sys/net/ipv4/ip_forward
It should return 1
, if not, as root run:
echo 1 > /proc/sys/net/ipv4/ip_forward
Now you need to set up rules for the NAT table, you need to forward the right port and masquerade.
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination [server_ip]:8118
iptables -t nat -A POSTROUTING -p tcp -d [server_ip] --dport 8118 -j MASQUERADE
And you also need to add a rule for forwarding:
iptables -A FORWARD -p tcp -d [server_ip] --dport 80 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT