What order ? I'm confused ...
Hi all ,
I run Iptables 1.2.9 on a 2.4.24 kernel :
I dont understand the way a (network) packet follows through the iptables rules .
For example , for the INPUT table , i have this set of rules (in this order) :
#========================================
iptables -P INPUT DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth0 -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8090 -j ACCEPT iptables -A INPUT -p tcp --dport 8080 -j ACCEPT iptables -A INPUT -p tcp --dport 10080 -j ACCEPT iptables -A INPUT -p tcp --dport 9000 -j ACCEPT iptables -A INPUT -p icmp -j ACCEPT
iptables -A INPUT -j REJECT
iptables -A INPUT -j LOG --log-level info --log-prefix "iptables_rktmb : " iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT iptables -A INPUT -i ppp0 -m unclean -j DROP
#========================================
well , my questions are :
If a packet arrives ( fromt the Net , ppp0 interface ) , what rule does he meet first ? ( "iptables -P INPUT DROP" or "iptables -A INPUT -i ppp0 -m unclean -j DROP")
I am tempted to answer : "iptables -A INPUT -i ppp0 -m unclean -j DROP" ... so that the filtering process begins from the last rule to the first . Am I right ?
So .
On the other hand , when i read man iptables about logging ( LOG target ) : i see that
the LOG target should be _after_ the DROP ( or REJECT ) so that I understand that if the packet comes from the net , it meets the first rule first and the last one at last .
What's the truth ?
i put the rule about the "unclean" stuff at the end because i read somewhere in a tutorial that its best place is there ...
Signature · 3 lines
Rakotomandimby Mihamina Andrianifaharana Tel : +33 2 38 76 43 65 http://stko.dyndns.info/site_principal/Members/mihamina
Quoted 30 lines · Rakotomandimby Mihamina
Hi all ,
I run Iptables 1.2.9 on a 2.4.24 kernel :I dont understand the way a (network) packet follows through the iptables rules .
For example , for the INPUT table , i have this set of rules (in this order) : #========================================
iptables -P INPUT DROPiptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth0 -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8090 -j ACCEPT iptables -A INPUT -p tcp --dport 8080 -j ACCEPT iptables -A INPUT -p tcp --dport 10080 -j ACCEPT iptables -A INPUT -p tcp --dport 9000 -j ACCEPT iptables -A INPUT -p icmp -j ACCEPTiptables -A INPUT -j REJECT
iptables -A INPUT -j LOG --log-level info --log-prefix "
iptables_rktmb: " iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT iptables -A INPUT -i ppp0 -m unclean -j DROP
#========================================
Quoted 5 lines
well , my questions are :
If a packet arrives ( fromt the Net , ppp0 interface ) , what rule does he meet first ? ( "iptables -P INPUT DROP" or "iptables -A INPUT -i ppp0 -m unclean -j DROP")
The -P is the chain Policy, and doesn't really count as a rule. It tells the
system what to do with a packet which doesn't match any of the rules.
The -A means Append, and therefore the rules you have listed above will be held in the chain in the order you have shown them (a quick "iptables -L INPUT -n -v" will confirm this).
Packets are tested against each rule in turn in a chain, starting with the first, until it matches, and then the target for rule is used (eg ACCEPT).
Quoted 3 lines
I am tempted to answer : "iptables -A INPUT -i ppp0 -m unclean -j DROP" ... so that the filtering process begins from the last rule to the first . Am I right ?
No.
Quoted 7 lines
So .
On the other hand , when i read man iptables about logging ( LOG target ) :
i see that the LOG target should be _after_ the DROP ( or REJECT ) so that I understand that if the packet comes from the net , it meets the first rule first and the last one at last .What's the truth ?
That depends on what you want to log.
If you want to log a packet before ACCEPTing or DROPping it, the LOG rule must come before the ACCEPT or DROP rule (otherwise the packet never reaches the LOG rule).
If on the other hand, you want to log packets which didn't get matched by any of the rules, then you put the LOG rule at the end, and it sees all the packets which didn't match your rules (just before they are dealt with by the default policy DROP).
Quoted 2 lines
i put the rule about the "unclean" stuff at the end because i read somewhere in a tutorial that its best place is there ...
I disagree. The effect of this is that you are accepting all packets for TCP
ports 20, 21, 25, 80, etc.... whether they are unclean or not. I think it
is better to throw out the unclean packets before ACCEPTing the clean packets going to the ports you want.
Regards,
Antony.
Signature · 9 lines
There are two possible outcomes:
If the result confirms the hypothesis, then you've made a measurement.
If the result is contrary to the hypothesis, then you've made a discovery.
- Enrico Fermi
Please reply to the list;
please don't CC me.Quoted 7 lines · Antony Stone
Quoted 3 lines
If a packet arrives ( fromt the Net , ppp0 interface ) , what rule does he meet first ? ( "iptables -P INPUT DROP" or "iptables -A INPUT -i ppp0 -m unclean -j DROP")
The -P is the chain Policy, and doesn't really count as a rule. It tells the system what to do with a packet which doesn't match any of the rules.
Quoted 6 lines
The -A means Append, and therefore the rules you have listed above will be held in the chain in the order you have shown them (a quick "iptables -L INPUT -n -v" will confirm this).
Packets are tested against each rule in turn in a chain, starting with the first, until it matches, and then the target for rule is used (eg ACCEPT).
Great ! :-) ... i got it .
Quoted 1 line
That depends on what you want to log.
The best is to log the packets that are going to be dropped either to report a disfunction of the FW or to be aware of new kinds of "attacks" ( why not ) and so that i can send my logs to developpers ...
Quoted 4 lines
If on the other hand, you want to log packets which didn't get matched by any of the rules, then you put the LOG rule at the end, and it sees all the packets which didn't match your rules (just before they are dealt with by the default policy DROP).
so that i keep that philosophy ...
Quoted 4 lines
I disagree. The effect of this is that you are accepting all packets for TCP ports 20, 21, 25, 80, etc.... whether they are unclean or not. I think it is better to throw out the unclean packets before ACCEPTing the clean packets going to the ports you want.
Well , i disagree too , but as well as i did not know the "order" i did not put it the right place . :-)
Now i know so i put it where it should :-)
Thanks for your quick answers
I give you my final script for i single box with ppp0 connected to the net , with no routing nor nat , but serving http on all the open ports you see .
What's your comments ? ( be nice :-) )
#==============================================
#!/bin/zsh
#echo "1" >| /proc/sys/net/ipv4/ip_forward
# REMISE a ZERO des regles de filtrage
iptables -F
iptables -X
# Je veux que les connexions entrantes soient bloquées par défaut iptables -P INPUT DROP
# here i DROP all unclean so that i can sleep quietly ;-) iptables -A INPUT -i ppp0 -m unclean -j DROP
# Je veux que les connexions destinées a etre forwardees
# soient bloquées par défaut iptables -P FORWARD DROP
# Je veux que les connexions sortantes soient rejetées par défaut iptables -P OUTPUT DROP
iptables -A INPUT -i lo -j ACCEPT
#iptables -A INPUT -i eth0 -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A OUTPUT -o eth0 -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# i got an FTP server , is it worth to open 21 ?
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 25 -j ACCEPT
#all these are my HTTP serving ports
# 1 Apache , 3 Zope and 1 Icecast
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8090 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp --dport 10080 -j ACCEPT
iptables -A INPUT -p tcp --dport 9000 -j ACCEPT
iptables -A INPUT -p icmp -j ACCEPT
#with these , i allow my dyndns updating #the 4 adresses are my ISP DNS adresses
#
#I dont know what port to put here , i tried with 80 #and it worked , so i kept it .
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT iptables -A OUTPUT -d 193.252.19.4 -p ALL -j ACCEPT ; iptables -A OUTPUT -d 193.252.19.3 -p ALL -j ACCEPT ; iptables -A OUTPUT -d 80.10.246.1 -p ALL -j ACCEPT iptables -A OUTPUT -d 80.10.246.132 -p ALL -j ACCEPT
iptables -A INPUT -j LOG --log-level info --log-prefix "dropped : "
iptables -A INPUT -j REJECT
#needed or not ? should it be sooner in the rules or #is it OK here ?
iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT
#===================================================
What about that last line ? it's about DoS Attacks ... is it good , according to you ?
Signature · 3 lines
Rakotomandimby Mihamina Andrianifaharana Tel : +33 2 38 76 43 65 http://stko.dyndns.info/site_principal/Members/mihamina
Packet traverses rules. Its kinda simple. Policy / chain set to DROP (my default policy). Unless there are aditional rules in the chain the packet will get lost in outer space ;) Depends on what the packet is destined to do :)
Example: Someone wants to see my web - port 80 tcp. Unless there are aditional rules that tell what can happen with packet, it gets lost. Example $IPT -P INPUT DROP
$IPT -P OUTPUT DROP
$IPT -P FORWARD DROP
To allow www on to the box itselfe:
$IPT -A INPUT -p tcp -i $IF_NET --dport 80 -j ACCEPT
To forward tcp packets that come to port 80 to another box:
$IPT -t nat -A PREROUTING -p tcp -d $IP_NET --dport 80 -j DNAT --to-destination xxx.xxx.xxx.xxx:80
$IPT -A FORWARD -p tcp -d xxx.xxx.xxx.xxx --dport 80 -j ACCEPT
And so on and on and on :)
Klemen Kecman
Sting d.o.o.
----- Original Message -----
From: "Rakotomandimby Mihamina" <[email protected]>
To: <[email protected]>
Sent: Tuesday, January 13, 2004 12:57 PM
Subject: What order ? I'm confused ...
Quoted 4 lines
Hi all ,
I run Iptables 1.2.9 on a 2.4.24 kernel :I dont understand the way a (network) packet follows through the iptables
rules .
Quoted 2 lines
For example , for the INPUT table , i have this set of rules (in this
order) :
Quoted 18 lines
#========================================
iptables -P INPUT DROPiptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth0 -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8090 -j ACCEPT iptables -A INPUT -p tcp --dport 8080 -j ACCEPT iptables -A INPUT -p tcp --dport 10080 -j ACCEPT iptables -A INPUT -p tcp --dport 9000 -j ACCEPT iptables -A INPUT -p icmp -j ACCEPTiptables -A INPUT -j REJECT
Quoted 8 lines
iptables -A INPUT -j LOG --log-level info --log-prefix "
iptables_rktmb: " iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT iptables -A INPUT -i ppp0 -m unclean -j DROP
#========================================well , my questions are :
If a packet arrives ( fromt the Net , ppp0 interface ) , what rule does he
meet first ?
Quoted 1 line
( "iptables -P INPUT DROP" or "iptables -A INPUT -i ppp0 -m unclean -j
DROP")
Quoted 2 lines
I am tempted to answer : "iptables -A INPUT -i ppp0 -m unclean -j DROP"
...
Quoted 5 lines
so that the filtering process begins from the last rule to the first . Am I right ?
So .
On the other hand , when i read man iptables about logging ( LOG target )
: i see that
Quoted 1 line
the LOG target should be _after_ the DROP ( or REJECT ) so that I
understand that if the packet comes from the net ,
Quoted 5 lines
it meets the first rule first and the last one at last .
What's the truth ?
i put the rule about the "unclean" stuff at the end because i read
somewhere in a tutorial that its best place is there ...
Quoted 6 lines
--
Rakotomandimby Mihamina Andrianifaharana
Tel : +33 2 38 76 43 65
http://stko.dyndns.info/site_principal/Members/mihamina