LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-11-2008, 07:23 AM   #1
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Custom chains in Iptables


I have a question related to the general functioning of iptables. I know that when a packet is processed by the firewall/iptables, the rules in a chain are applied in order. If the packet matches the first rule, an action is taken otherwise it is subjected to the next rule.

Some targets - like ACCEPT and DROP - will cause the packet to stop traversing that specific chain, whereas some other targets - like LOG - may take an action on the packet, after which the packet will continue passing through the rest of the rules.

Based on this little knowledge, I don't understand how the following setup (created by firestarter) works. It defines a custom chain called INBOUND, referenced by the INPUT chain:
Code:
Chain INPUT (policy DROP 89 packets, 13385 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     tcp  --  *      *       XXX.XXX.XXX.XX       0.0.0.0/0           tcp flags:!0x17/0x02 
  379 73149 ACCEPT     udp  --  *      *       XXX.XXX.XXX.XX       0.0.0.0/0           
    0     0 ACCEPT     tcp  --  *      *       XXX.XXX.XXX.XX       0.0.0.0/0           tcp flags:!0x17/0x02 
    0     0 ACCEPT     udp  --  *      *       XXX.XXX.XXX.XX       0.0.0.0/0           
  466 33353 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
   31  1891 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 10/sec burst 5 
26762   13M DROP       all  --  eth0   *       0.0.0.0/0            255.255.255.255     
76073 6836K DROP       all  --  *      *       0.0.0.0/0            XXX.XXX.XXX.255     
    0     0 DROP       all  --  *      *       255.255.255.255      0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0             
   90  9150 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID 
    0     0 LSI        all  -f  *      *       0.0.0.0/0            0.0.0.0/0           limit: avg 10/min burst 5 
14287 9704K INBOUND    all  --  eth0   *       0.0.0.0/0            0.0.0.0/0           
 7785 4819K INBOUND    all  --  eth1   *       0.0.0.0/0            192.168.0.1         
    0     0 INBOUND    all  --  eth1   *       0.0.0.0/0            XXX.XXX.XXX.XXX     
    0     0 INBOUND    all  --  eth1   *       0.0.0.0/0            192.168.0.255       
   89 13385 LOG_FILTER  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   89 13385 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0           LOG flags 0 level 6 prefix `Unknown Input'

Chain INBOUND (4 references)
 pkts bytes target     prot opt in     out     source               destination         
 5822  921K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
 1802  137K ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
    0     0 ACCEPT     tcp  --  *      *       192.168.0.10         0.0.0.0/0           tcp dpt:3551 
    0     0 ACCEPT     udp  --  *      *       192.168.0.10         0.0.0.0/0           udp dpt:3551 
    4   240 ACCEPT     tcp  --  *      *       192.168.0.4          0.0.0.0/0           tcp dpt:22 
    0     0 ACCEPT     udp  --  *      *       192.168.0.4          0.0.0.0/0           udp dpt:22 
 4897 1092K LSI        all  --  *      *       0.0.0.0/0            0.0.0.0/0
As you can see, in the middle of the INPUT chain there is a DROP target (marked in red) which drops all packets from anywhere to anywhere. After that, there are the rules that transfer control to the custom chain INBOUND. I don't understand how can a packet jump to the UNBOUND chain if it has been dropped by a preceeding rule.

Anyway, this setup works, as you can see from the packets and bytes count. Also notice that the count of the above mentioned DROP rule is zero. Maybe I'm missing something. Can you help me to understand?
 
Old 07-11-2008, 07:43 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
I'd assume that the actual command itself is more complex than the output provided. dig through the original script and find what's being run.
 
Old 07-11-2008, 08:04 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Original Poster
Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
I was just digging through it. Looking at the code that creates the "incriminated" DROP rule:
Code:
# Block Traffic with Stuffed Routing
#  Early versions of PUMP - (the DHCP client application included in RH / Mandrake) require
#  inbound packets to be accepted from a source address of 255.255.255.255.  If you have issues
#  with DHCP clients on your local LAN - either update PUMP, or remove the first rule below)
$IPT -A INPUT -s 255.255.255.255 -j DROP
$IPT -A INPUT -d 0.0.0.0 -j DROP
$IPT -A OUTPUT -s 255.255.255.255 -j DROP
$IPT -A OUTPUT -d 0.0.0.0 -j DROP
make me notice that the destination address is 0.0.0.0 instead of 0.0.0.0/0, as set in other rules. What does this mean? Maybe this is the reason why this rule apparently has not dropped any packet yet.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pppoe-start resets iptables chains homecsiga Linux - Networking 0 09-07-2007 08:27 PM
Iptables user-defined chains 0.o Linux - Networking 2 06-21-2007 07:50 AM
creation of new iptables chains !!!! gabsik Linux - Security 6 05-25-2006 06:57 PM
How to delete the one of iptables chains? 80mail Linux - Networking 1 12-21-2005 02:16 AM
how packets traverse thru iptables chains? hardigunawan Linux - Security 1 01-09-2003 01:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration