LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 06-02-2009, 06:37 PM   #1
hsegtreas
Member
 
Registered: May 2004
Distribution: Slackware 9.1
Posts: 47

Rep: Reputation: 15
iptables: why use both -p and -m to match the target protocol?


The title is the question.. I've seen it a few times, what's the difference between, ie:
iptables -A INPUT -p udp --dport 1234 -j ACCEPT
iptables -A INPUT -p udp -m udp --dport 1234 -j ACCEPT

The second line has -m specified. It looks like it's the same, but is there an actual difference?
My guess is that when specifying -m, instead of just trusting the IP stack on the protocol, iptables will also analyze the packet headers (?) But then is that really more secure, and does it takes significantly more processor power? Is it worth it?.. Or am i just way off and there's no difference whatsoever?

I'm kinda curious about that.. Does Anyone know?

Thanks,

Vincent
 
Old 06-02-2009, 07:19 PM   #2
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Quote:
It looks like it's the same, but is there an actual difference?
No. As noted in the iptables man page, specifying the protocol with -p
implicitly loads the match extensions for that protocol, so, e.g., the following are
equivalent:
Code:
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp        --dport 22 -j ACCEPT
From the man page:
Quote:
...
iptables can use extended packet matching modules. These are loaded in
two ways: implicitly, when -p or --protocol is specified, or with the
-m or --match options, followed by the matching module name;
...
 
Old 06-02-2009, 08:20 PM   #3
hsegtreas
Member
 
Registered: May 2004
Distribution: Slackware 9.1
Posts: 47

Original Poster
Rep: Reputation: 15
heh I guess that people who wrote the examples i've seen use the -m out of a habit of loading other modules.. Or maybe just because they don't know its useless..
Anyways, Thanks for the clear explanation Berhanie!

Vincent
 
Old 06-02-2009, 10:25 PM   #4
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Quote:
-m out of a habit of loading other modules
It's also for consistency of syntax.

Last edited by Berhanie; 06-03-2009 at 07:25 AM.
 
  


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
iptables: No chain/target/match by that name - with 2.6.17.7 tp11235 Linux - Kernel 10 03-24-2010 02:15 AM
iptables: No chain/target/match by that name serpentor Linux - Server 4 02-05-2009 10:02 AM
iptables: No chain/target/match by that name qanopus Linux - Networking 6 01-04-2009 09:10 PM
kernel update and "iptables: No chain/target/match by that name" thewtex Linux - Networking 4 04-03-2007 06:10 AM
"iptables: No chain/target/match by that name" error PennyroyalFrog Linux - Security 2 11-28-2004 01:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:53 PM.

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