LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-08-2009, 09:15 AM   #1
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Rep: Reputation: 15
iptables question


Hi,

In the following rule, what does -m option do ? Why do we need it ?

-A INPUT -s 192.168.1.1 -p tcp -m tcp --dport 22 -j ACCEPT

I am not getting if "-m tcp" is really needed or not and its use ...

Thank you
 
Old 10-08-2009, 09:32 AM   #2
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,278

Rep: Reputation: 148Reputation: 148
its match whether it is tcp or udp packet,its not only for tcp & udp packet matching just check the man page there are examples about matching

Last edited by kirukan; 10-08-2009 at 09:43 AM.
 
Old 10-08-2009, 09:38 AM   #3
sang_froid
Member
 
Registered: Oct 2006
Posts: 179

Original Poster
Rep: Reputation: 15
-p tcp already does that job.... doesn't it ?

in that case, why do we still need -m option ?

Quote:
Originally Posted by kirukan View Post
its match whether it is tcp or udp packet
 
Old 10-08-2009, 10:31 AM   #4
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by sang_froid View Post
-p tcp already does that job.... doesn't it ?

in that case, why do we still need -m option ?
You don't need the -m option. -p implicitly loads the tcp module. Heres the extract from the manual

Code:
MATCH EXTENSIONS
       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; after these, various extra command line options become available, depending on the speā
       cific module.  You can specify multiple extended match modules in one line, and you can use the -h or --help options after  the  module  has  been
       specified to receive help specific to that module.

Just my opinion matching is a bad wording I'd rather say module but who cares.
 
Old 10-08-2009, 10:51 AM   #5
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
You don't need it when executing an iptables command (since the match module gets auto-loaded), but is anyone positive it's not needed in the actual configuration file? I don't ever edit that file manually (only with iptables-save) so I'm not sure.

Last edited by win32sux; 10-08-2009 at 10:53 AM.
 
Old 10-09-2009, 03:17 AM   #6
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by win32sux View Post
You don't need it when executing an iptables command (since the match module gets auto-loaded), but is anyone positive it's not needed in the actual configuration file? I don't ever edit that file manually (only with iptables-save) so I'm not sure.
Your absolute right win32sux. When adding the rule by hand -m tcp is not needed but when saving iptables rules its always added.
Did a trial run adding the iptables rule once with and once without -m tcp and iptables-save always prints the line with -m tcp

Empty iptables
Code:
# iptables-save
# Generated by iptables-save v1.4.2 on Fri Oct  9 10:09:12 2009
*filter
:INPUT ACCEPT [84697:13964056]
:FORWARD ACCEPT [90216:12884867]
:OUTPUT ACCEPT [29225:6783683]
COMMIT
# Completed on Fri Oct  9 10:09:12 2009
Now add the line with -m tcp option
Code:
# iptables -A INPUT -s 192.168.1.1 -p tcp -m tcp --dport 22 -j ACCEPT
# iptables-save
# Generated by iptables-save v1.4.2 on Fri Oct  9 10:09:38 2009
*filter
:INPUT ACCEPT [84787:13973745]
:FORWARD ACCEPT [90248:12890096]
:OUTPUT ACCEPT [29282:6790635]
-A INPUT -s 192.168.1.1/32 -p tcp -m tcp --dport 22 -j ACCEPT
COMMIT
# Completed on Fri Oct  9 10:09:38 2009
Now add the line without
Code:
# iptables -A INPUT -s 192.168.1.1 -p tcp --dport 22 -j ACCEPT
Producer:/home/ase# iptables-save
# Generated by iptables-save v1.4.2 on Fri Oct  9 10:10:12 2009
*filter
:INPUT ACCEPT [84877:13985121]
:FORWARD ACCEPT [90282:12897348]
:OUTPUT ACCEPT [29334:6796807]
-A INPUT -s 192.168.1.1/32 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -s 192.168.1.1/32 -p tcp -m tcp --dport 22 -j ACCEPT
COMMIT
# Completed on Fri Oct  9 10:10:12 2009
Both times its written with the -m tcp option
 
  


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 question ruben0076 Linux - Networking 2 01-16-2005 12:26 PM
iptables question iomari Linux - Security 4 01-13-2005 12:14 AM
iptables question enrique_arong Linux - Newbie 9 09-27-2004 02:53 PM
Iptables Question Neomaster Linux - Security 4 06-18-2003 08:24 AM
iptables question Ice9 Linux - Networking 1 02-20-2003 02:25 PM

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

All times are GMT -5. The time now is 03:41 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