(no subject)
This being my first firewall, I would like those of you who are more experienced and have the time to take a look and point the mistakes I did (and perhaps some improvements would be appreciated)
The box is intended to act as a www and mail server and to masquerade an internal network with private ip's
The rules I'm not sure of are commented (and I have some questions for the masquerade, but I'll RTFM on this one - still I must ask if I did the masq rules correctly in the firewall below)
thanks a lot,
petre
#!/bin/sh
IPEXT="193.xxx.xxx.xxx"
IPT="/usr/sbin/iptables"
echo "Cleaning ..."
for i in filter nat mangle
do
$IPT -t $i -F
$IPT -t $i -X
done
echo "Initial rules ..."
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD DROP
#loopback
$IPT -A INPUT -i lo -p all -j ACCEPT
$IPT -A OUTPUT -o lo -p all -j ACCEPT
echo -e "\nMASQUERADING ...\n"
echo "Masquerading 192.168.20.0/24"
# set up masquerading for everything not destined to the localnets $IPT -t nat -A POSTROUTING -s 192.168.20.0/24 -o eth1 -j MASQUERADE $IPT -t nat -A POSTROUTING -d 192.168.20.0/24 -o eth1 -j MASQUERADE
$IPT -A FORWARD -s 192.168.20.0/24 -j ACCEPT
$IPT -A FORWARD -d 192.168.20.0/24 -j ACCEPT
#echo "FWD: Allow all connections OUT and only existing and related ones IN"
#$IPT -A FORWARD -i eth0 -s 192.168.20.0/24 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT #$IPT -A FORWARD -i eth1 -o eth0 -d 192.168.20.0/24 -j ACCEPT
#$IPT -A FORWARD -i eth0 -s 192.168.10.5 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT #$IPT -A FORWARD -i eth1 -o eth0 -d 192.168.10.5 -j ACCEPT
$IPT -A FORWARD -j LOG
$IPT -A FORWARD -j DROP
echo -e "- Enabling SNAT (MASQUERADE) funtionality on eth0" $IPT -t nat -A POSTROUTING -o eth0 -j MASQUERADE echo -e "\nDone.\n"
###
echo "no snmpd access from the exterior"
$IPT -A INPUT -p udp -s 0/0 --dport 161 -j DROP
#cut all which appears to be loopback talking to eth's $IPT -A INPUT -p all -s localhost -i eth+ -j DROP
#cut all syn's except those for incoming http & ssh & smtp & pop3 #$IPT -A INPUT -i eth0 -p tcp --syn --destination-port 80 -j ACCEPT #$IPT -A INPUT -i eth0 -p tcp --syn --destination-port 22 -j ACCEPT #$IPT -A INPUT -i eth0 -p tcp --syn --destination-port 25 -j ACCEPT #$IPT -A INPUT -i eth0 -p tcp --syn --destination-port 110 -j ACCEPT #$IPT -A INPUT -p tcp --tcp-flags ALL SYN -j DROP
echo "Syn flood protection..."
$IPT -N DoS
$IPT -A INPUT -j DoS
$IPT -A DoS -p icmp --icmp-type echo-request \
-m limit --limit 10/s -j RETURN
$IPT -A DoS -p icmp --icmp-type echo-request \
-m limit -j LOG --log-level warn \
--log-prefix "DoS (PING)" \
--log-tcp-options \
--log-ip-options$IPT -A DoS -p icmp --icmp-type echo-request -j REJECT
#cut access from private addresses to eth1
$IPT -A INPUT -i eth0 -s 10.0.0.0/8 -j DROP
$IPT -A INPUT -i eth0 -s 172.16.0.0/12 -j DROP
$IPT -A INPUT -i eth0 -s 192.168.0.0/16 -j DROP
echo "cut ssh except from trusted hosts"
echo "allow from"
echo " - 1"
$IPT -A INPUT -i eth0 -p tcp -s 193.xxx.xxx.x -d $IPEXT --dport 22 -j ACCEPT
echo " - 1"
$IPT -A INPUT -i eth0 -p tcp -s 193.xxx.xxx.xxx -d $IPEXT --dport 22 -j ACCEPT
echo " - 3"
$IPT -A INPUT -i eth0 -p tcp -s 193.xxx.xxx.xxx -d $IPEXT --dport 22 -j ACCEPT
echo " - 4"
$IPT -A INPUT -i eth0 -p tcp -s 193.xxx.xxx.xx -d $IPEXT --dport 22 -j ACCEPT echo "cut all"
$IPT -A INPUT -i eth0 -p tcp --dport 22 -j DROP
Quoted 6 lines · On Saturday 08 June 2002 1:01 pm, [email protected] wrote:
echo "Cleaning ..."
for i in filter nat mangle
do
$IPT -t $i -F
$IPT -t $i -X
done
-F is a good idea, but you can't do -X (delete chain) on the built-in chains; only user-defined ones.
Quoted 4 lines
echo "Initial rules ..."
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD DROP
I would recommend setting default policy on your INPUT chain to DROP as well, and then allow in only what you want...
Quoted 2 lines
$IPT -t nat -A POSTROUTING -s 192.168.20.0/24 -o eth1 -j MASQUERADE $IPT -t nat -A POSTROUTING -d 192.168.20.0/24 -o eth1 -j MASQUERADE
No, you only want the first one of these rules. I'm assuming that eth1 is
your external interface.
Quoted 2 lines
echo -e "- Enabling SNAT (MASQUERADE) funtionality on eth0" $IPT -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Maybe I'm wrong in thinking that eth1 is your external interface ? Please
can you tell us what eth0and eth1 are connected to (and where networks 192.168.20.0 and 192.168.10.0 are connected ?
The rest looks pretty good to me.
Antony.
eth0 - connects to the internet
eth1 - internal network with private ip addresses
eth2 - internal network with routable ip's
What I want to do - eth0 has a routable ip and masquerades the internal network which enters eth1 (or eth2, I haven't plug in the cable yet :D); eth0:1 will route the network with valid ineternet ip addresses which enters eth2 to the internet (speaking of which, I assume I must input rules for eth0:1's ip address too, but in the iptables syntax is it allowed to refer to the alias as eth0:1 or I must use only its ip?)
thanks,
petre
please enlighten me on the masquerading rules
Quoting Antony Stone <[email protected]>:
Quoted 43 lines · On Saturday 08 June 2002 1:01 pm, [email protected] wrote:
Quoted 7 lines
echo "Cleaning ..."
for i in filter nat mangle
do
$IPT -t $i -F
$IPT -t $i -X
done-F is a good idea, but you can't do -X (delete chain) on the built-in chains;
only user-defined ones.
Quoted 4 lines
echo "Initial rules ..."
$IPT -P INPUT ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -P FORWARD DROPI would recommend setting default policy on your INPUT chain to DROP as well,
and then allow in only what you want...
Quoted 2 lines
$IPT -t nat -A POSTROUTING -s 192.168.20.0/24 -o eth1 -j MASQUERADE $IPT -t nat -A POSTROUTING -d 192.168.20.0/24 -o eth1 -j MASQUERADE
No, you only want the first one of these rules. I'm assuming that eth1 is
your external interface.
Quoted 2 lines
echo -e "- Enabling SNAT (MASQUERADE) funtionality on eth0" $IPT -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Maybe I'm wrong in thinking that eth1 is your external interface ? Please
can you tell us what eth0and eth1 are connected to (and where networks 192.168.20.0 and 192.168.10.0 are connected ?
The rest looks pretty good to me.
Antony.
Quoted 3 lines · On Saturday 08 June 2002 3:54 pm, [email protected] wrote:
eth0 - connects to the internet
eth1 - internal network with private ip addresses
eth2 - internal network with routable ip's
Okay - I understand that. I very much hope you mean that you have a public
IP on eth0, and your ISP has given you another batch of IP addresses to go on the machines on eth2, and the ISP is routing these to you via the address on eth0 ?
It would not be a good setup if you were trying to put a public IP on eth0
which is from the same subnet as the routable IPs on eth2. It's possible to
do this, but a lot more technically challenging...
Quoted 2 lines
What I want to do - eth0 has a routable ip and masquerades the internal network which enters eth1
Okay, no problem.
Quoted 1 line
(or eth2, I haven't plug in the cable yet :D);
Don't understand. If eth2 has routable IPs (by which I assume you mean IP
addresses which have been assigned to you, not ones from the ranges 10.x.y.z, 172.16.a.b, 192.168.c.d), then why would you want to masquerade them behind eth0 ?
Quoted 2 lines
eth0:1 will route the network with valid internet ip addresses which enters eth2 to the internet
No, I do not understand what you mean by this. What are you trying to use
eth0:1 for ?
Quoted 3 lines
(speaking of which, I assume I must input rules
for eth0:1's ip address too, but in the iptables syntax is it allowed to refer to the alias as eth0:1 or I must use only its ip?)
You cannot use the name "eth0:1" in netfilter rules. It doesn't like the
colon. You can, however, use "eth0", which is the real interface these
packets are coming in on, and/or you can use the destination IP address, which will identify where they were headed.
So iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT will allow SSH packets which are sent to the address you've put on eth0:1 (it will also allow packets sent to the address you've put on eth0, eth0:2, etc...)
iptables -A INPUT -i eth0 -d a.b.c.d -p tcp --dport 22 -j ACCEPT will allow SSH packets coming in on eth0, eth:1, eth0:2 etc provided the destination address is a.b.c.d
Hope this explains how you can work with eth0:1 and netfilter rules.
Give us some more detail on the actual addresses you intend to put on eth0, eth1 and eth2, and the subnets attached to these interfaces (you can obfuscate any public IPs you've been given so long as it's still possible to tell one subnet from the others), and we might be able to help some more.
.
Antony.
eth0 - 193.231.237.x
eth1 - used to route 80.96.x.0/24
eth2 - used to masquerade 192.168.10.0/24
theoretically that would be the ip setup; however, I have another 193.231.237.x2 ip which I'd like to use especially because the two 193.231.237.x`s ips are in different cbq classes
Quoting Antony Stone <[email protected]>:
Quoted 6 lines · On Saturday 08 June 2002 3:54 pm, [email protected] wrote:
Quoted 4 lines
eth0 - connects to the internet
eth1 - internal network with private ip addresses
eth2 - internal network with routable ip's
Quoted 7 lines
Okay - I understand that. I very much hope you mean that you have a public
IP on eth0, and your ISP has given you another batch of IP addresses to go on
the machines on eth2, and the ISP is routing these to you via the address on
eth0 ?
yes
Quoted 4 lines
It would not be a good setup if you were trying to put a public IP on eth0
which is from the same subnet as the routable IPs on eth2. It's possible todo this, but a lot more technically challenging...
3 eth`s for 3 different subnets
Quoted 4 lines
Quoted 2 lines
What I want to do - eth0 has a routable ip and masquerades the internal network which enters eth1
Okay, no problem.
good :-)
Quoted 8 lines
Quoted 1 line
(or eth2, I haven't plug in the cable yet :D);
Don't understand. If eth2 has routable IPs (by which I assume you mean IP
addresses which have been assigned to you, not ones from the ranges 10.x.y.z,
172.16.a.b, 192.168.c.d), then why would you want to masquerade them behind
Quoted 8 lines
eth0 ?
Quoted 2 lines
eth0:1 will route the network with valid internet ip addresses which enters eth2 to the internet
No, I do not understand what you mean by this. What are you trying to use
eth0:1 for ?
eth0 - 193.231.237.x routes the subnet 80.69.x.0/24 which enters the router via eth1
eth0:1 would route 192.168.10.0/24 which enters the router via eth2
basically that's the idea which I have in mind ... why an alias on eth0 ? ip`s for the eth0 are in different cbq classes at my ISP
Quoted 31 lines
Quoted 3 lines
(speaking of which, I assume I must input rules
for eth0:1's ip address too, but in the iptables syntax is it allowed to refer to the alias as eth0:1 or I must use only its ip?)You cannot use the name "eth0:1" in netfilter rules. It doesn't like the
colon. You can, however, use "eth0", which is the real interface these
packets are coming in on, and/or you can use the destination IP address, which will identify where they were headed.So iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT will allow SSH packets which are sent to the address you've put on eth0:1 (it will also allow packets sent to the address you've put on eth0, eth0:2, etc...)
iptables -A INPUT -i eth0 -d a.b.c.d -p tcp --dport 22 -j ACCEPT will allow
SSH packets coming in on eth0, eth:1, eth0:2 etc provided the destination address is a.b.c.d
Hope this explains how you can work with eth0:1 and netfilter rules.
Give us some more detail on the actual addresses you intend to put on eth0,
eth1 and eth2, and the subnets attached to these interfaces (you can obfuscate any public IPs you've been given so long as it's still possible to
tell one subnet from the others), and we might be able to help some more.
.
Antony.