Skip to contentSkip to conversation

multiple source

DISCUSSION azeem ahmad 2 participants 3 messages Mar 31, 2004

lore
Share & tools
lore
#0 lore raw

hi all
i want to make such a setup that the two ip 192.168.0.2 and 192.168.0.102 from my lan should be MASQUERADEd and all the other addresses should be redirected to the proxy working on the same machine on port 8080, so i made the following rules but these are not working. if i dont add rules in PREROUTING and only add rules in POSTROUTING then both ips (.0.2 and .0.102) MASQUERADEs very well but i also want the other sources to be REDIRECTed to the proxy so if i start redirection then it redirects all the sources including the two (.0.2 and .0.102) which i dont want. wot should i do plz help me out

###################################################################################
#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -F
iptables -t nat -F

MASQs="192.168.0.2 192.168.0.102"
PROTs="tcp udp"

for MASQ in $MASQs;
do
iptables -t nat -A POSTROUTING -s $MASQ -o ppp0 -j MASQUERADE
done

for MASQ in $MASQs;
do

	for PROT in $PROTs;
	do
		iptables -t nat -A PREROUTING -s ! $MASQ -p tcp --dport 80 -j REDIRECT 

--to-port 8080
done
done

###################################################################################
Chain PREROUTING (policy ACCEPT)

target     prot opt source               destination
REDIRECT   tcp  -- !192.168.0.2          anywhere           tcp dpt:http redir ports 8080
REDIRECT   tcp  -- !192.168.0.2          anywhere           tcp dpt:http redir ports 8080
REDIRECT   tcp  -- !192.168.0.102        anywhere           tcp dpt:http redir ports 8080
REDIRECT   tcp  -- !192.168.0.102        anywhere           tcp dpt:http redir ports 8080

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination

MASQUERADE  all  --  192.168.0.2          anywhere
MASQUERADE  all  --  192.168.0.102        anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
#####################################################################################

Regards
Azeem

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

#1 lore raw
Quoted 4 lines · azeem ahmad

hi all
i want to make such a setup that the two ip 192.168.0.2 and 192.168.0.102 from my lan should be MASQUERADEd and all the other addresses should be redirected to the proxy working on the same machine on port 8080

Please see my response to the last qiuestion on the list, which should tell you how to do what you want:
http://lists.netfilter.org/pipermail/netfilter/2004-March/051649.html

Quoted 6 lines

MASQs="192.168.0.2 192.168.0.102"

for MASQ in $MASQs;
do
iptables -t nat -A POSTROUTING -s $MASQ -o ppp0 -j MASQUERADE
done

The reason why this doesn't work is that it creates two rules for you; the first one says "for any address other than 192.168.0.2, MASQUERADE", the second one says "for any address other than 192.168.0.102, MASQUERADE". Every single address will match at least one of those rules, therefore everything gets MASQUERADEd.

Regards,

Antony.

Signature · 6 lines
The first fifty percent of an engineering project takes ninety percent of the 
time, and the remaining fifty percent takes another ninety percent of the 
time.

                                                     Please reply to the list;
                                                           please don't CC me.
#2 lore raw
Quoted 7 lines · Antony Stone
Quoted 6 lines

MASQs="192.168.0.2 192.168.0.102"

for MASQ in $MASQs;
do
iptables -t nat -A POSTROUTING -s $MASQ -o ppp0 -j MASQUERADE
done

Quoted 5 lines

The reason why this doesn't work is that it creates two rules for you; the first one says "for any address other than 192.168.0.2, MASQUERADE", the second one says "for any address other than 192.168.0.102, MASQUERADE". Every single address will match at least one of those rules, therefore everything gets MASQUERADEd.

Sorry! I quoted the wrong section from your rules to give this explanation.

I should have quoted this loop instead (the one with the negation):

Quoted 5 lines

for MASQ in $MASQs;
do

    iptables -t nat -A PREROUTING -s ! $MASQ -p tcp --dport 80 -j REDIRECT

--to-port 8080
done

Hopefully you can see the logic of what I explained earlier, and how it applies to these two rules, even though I misquoted previously.

Oops :)

Antony.

Signature · 7 lines
How I want a drink, alcoholic of course, after the heavy chapters involving 
quantum mechanics.

 - 3.14159265358979

                                                     Please reply to the list;
                                                           please don't CC me.