LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Forward port 80 for all traffic except to certain host/network (https://www.linuxquestions.org/questions/linux-networking-3/forward-port-80-for-all-traffic-except-to-certain-host-network-772787/)

fantasygoat 12-01-2009 04:52 PM

Forward port 80 for all traffic except to certain host/network
 
I have an application which checks websites for new content, and it runs on several servers. So, to lower bandwidth costs I've put a Squid server in front of them and used iptables to forward all calls on port 80 to it.

iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to x.x.x.x:3128

The problem I have is that there are a couple of servers which do other tasks that are dependent on source IP, so they won't accept connections from the Squid server. So, for those ones, I don't want it to forward to Squid.

How would I format my iptables call to forward everything unless the destination address or net is X?

iptables is a bit of a mystery to me.

deadeyes 12-02-2009 10:51 AM

Quote:

Originally Posted by fantasygoat (Post 3776245)
I have an application which checks websites for new content, and it runs on several servers. So, to lower bandwidth costs I've put a Squid server in front of them and used iptables to forward all calls on port 80 to it.

iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to x.x.x.x:3128

The problem I have is that there are a couple of servers which do other tasks that are dependent on source IP, so they won't accept connections from the Squid server. So, for those ones, I don't want it to forward to Squid.

How would I format my iptables call to forward everything unless the destination address or net is X?

iptables is a bit of a mystery to me.

-d <ip-address> Match destination IP address
http://www.linuxhomenetworking.com/w...Using_iptables

This is a very good guide.

fantasygoat 12-02-2009 02:22 PM

I've read that and I'm still not sure how I should structure the commands.

Perhaps like this?

iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to x.x.x.x:3128
iptables -t nat -A OUTPUT -p tcp --dport 80 -d y.y.y.y -j ACCEPT

fantasygoat 12-04-2009 12:08 PM

As an update, I dug through the documentation for iptables and discovered the "-d" parameter will accept a NOT parameter in the form of "!". So the appropriate command is:

iptables -t nat -A OUTPUT -p tcp --dport 80 -d ! y.y.y.y -j DNAT --to x.x.x.x:3128


All times are GMT -5. The time now is 12:04 PM.