Skip to contentSkip to conversation

Trying to setup two ethernet cards with two websites

DISCUSSION JUSTIN GERRY 2 participants 2 messages Dec 31, 2002

lore
Share & tools
lore
#0 lore raw

I am attempting to setup two websites with two ip address, each one on a different ethernet card/interface.

It only seems to work for the first rule (first listed ip address) that gets matched up, so I can get one website to work but not the other. How do I write this so it covers both address and allows httpd to go to either interface or either address? Can I write a single rule to match a range of ip addresses (.93 and .94) instead of writing one for each individual address?

This is what I have so far for testing.....

IF1="eth0"
IF2="eth1"
IP2="172.30.12.93"
IP1="172.30.12.94"
UNPRIVPORTS="1024:65535"

iptables -F
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A INPUT -i $IF1 -p tcp --sport $UNPRIVPORTS -d $IP1 --dport 80 -m state --state NEW -j ACCEPT
iptables -A INPUT -i $IF2 -p tcp --sport $UNPRIVPORTS -d $IP2 --dport 80 -m state --state NEW -j ACCEPT
iptables -A INPUT -i $IF1 -p tcp --sport $UNPRIVPORTS -d $IP1 --dport 80 -j ACCEPT
iptables -A INPUT -i $IF2 -p tcp --sport $UNPRIVPORTS -d $IP2 --dport 80 -j ACCEPT
iptables -A OUTPUT -o $IF2 -p tcp ! --syn -s $IP2 --sport 80 --dport $UNPRIVPORTS -j ACCEPT
iptables -A OUTPUT -o $IF1 -p tcp ! --syn -s $IP1 --sport 80 --dport $UNPRIVPORTS -j ACCEPT

Thanks,
Justin

#1 lore raw
Quoted 18 lines · JUSTIN GERRY

I am attempting to setup two websites with two ip address, each one on a different ethernet card/interface.

It only seems to work for the first rule (first listed ip address) that gets matched up, so I can get one website to work but not the other. How do I write this so it covers both address and allows httpd to go to either interface or either address? Can I write a single rule to match a range of ip addresses (.93 and .94) instead of writing one for each individual address?

This is what I have so far for testing.....

IF1="eth0"
IF2="eth1"
IP2="172.30.12.93"
IP1="172.30.12.94"
UNPRIVPORTS="1024:65535"

Quoted 6 lines

iptables -F
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

the two below...

Quoted 4 lines

iptables -A INPUT -i $IF1 -p tcp --sport $UNPRIVPORTS -d $IP1 --dport 80 -m state --state NEW -j ACCEPT
iptables -A INPUT -i $IF2 -p tcp --sport $UNPRIVPORTS -d $IP2 --dport 80 -m state --state NEW -j ACCEPT

...are included in these two, so you won't need both. You probably don't want those below, as they accept anything regardless to state.

Quoted 4 lines

iptables -A INPUT -i $IF1 -p tcp --sport $UNPRIVPORTS -d $IP1 --dport 80 -j ACCEPT
iptables -A INPUT -i $IF2 -p tcp --sport $UNPRIVPORTS -d $IP2 --dport 80 -j ACCEPT

are these really nessecary? with -P DROP, this'll deny any outgoing connections at all, regardless of protocol. It'll even drop ICMP packets, something you probably don't want.

Quoted 4 lines

iptables -A OUTPUT -o $IF2 -p tcp ! --syn -s $IP2 --sport 80 --dport $UNPRIVPORTS -j ACCEPT
iptables -A OUTPUT -o $IF1 -p tcp ! --syn -s $IP1 --sport 80 --dport $UNPRIVPORTS -j ACCEPT

To allow for multiple hosts in a rule, you can specify a mask (or number of bits). For instance:

# iptables -s 10.0.0.0/31
will match 10.0.0.0 and 10.0.0.1. .93 and .94, however, overlaps this and needs to be allowed for specifically.

so - try first with -P OUTPUT -j ACCEPT, and no rules in the OUTPUT chain. It shouldn't be any problem then.

roy