I am facing issues with Port forwarding in CENT OS 6.5.
i need to forward all incoming traffic from port 80 to 3128. like setting up a transparent proxy server. what ever i tried it didn't worked. My Transparent proxy server IP is 10.5.255.252
Please see my configuration below.
<code>
[root@xxxxxxhost xx-yy]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DNAT tcp -- anywhere 10.5.255.252 multiport dports http,https to:10.5.255.252:3128
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- 10.5.0.0/16 anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@xxxxxxhost xx-yy]# iptables-save
*nat
:PREROUTING ACCEPT [18:3530]
:POSTROUTING ACCEPT [9:540]
:OUTPUT ACCEPT [228:14574]
-A PREROUTING -d 10.5.255.252/32 -p tcp -m multiport --dports 80,443 -j DNAT --to-destination 10.5.255.252:3128
-A POSTROUTING -s 10.5.0.0/16 -o eth0 -j MASQUERADE
COMMIT
[root@xxxxxxhost xx-yy]# cat /proc/sys/net/ipv4/ip_forward
1
[root@xxxxxxhost xx-yy]# wget 127.0.0.1
--2014-03-12 04:05:51-- http://127.0.0.1/
Resolving 127.0.0.1... 127.0.0.1
Connecting to 127.0.0.1|127.0.0.1|:80... failed: Connection refused.
[root@xxxxxxhost xx-yy]# wget 127.0.0.1:3128
--2014-03-12 04:05:55-- http://127.0.0.1:3128/
Resolving 127.0.0.1... 127.0.0.1
Connecting to 127.0.0.1|127.0.0.1|:3128... connected.
HTTP request sent, awaiting response... ^C
[root@xxxxxxhost xx-yy]#
</code>
if you see above the wget request to localhost on port 80 is refused, but the request for 3128 port is accepted. so its not working :(
Even tried the below rules.
<code>
iptables -t nat -D PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
iptables -t nat -A PREROUTING -d 10.5.255.252 -p tcp -m tcp --dport 80 -j DNAT --to-destination 10.5.255.252:3128
iptables -t nat -A POSTROUTING -d 10.5.255.252 -p tcp --dport 3128 -j SNAT --to-source 10.5.255.252
</code>
But Nothing worked. Could you please help me to solve this.
Appreciate your help.