LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-21-2012, 10:55 AM   #1
johnnygear
LQ Newbie
 
Registered: Apr 2012
Posts: 6

Rep: Reputation: Disabled
iptables question: --dports option and context


Hi All,

Hoping someone has a little more experience with iptables than I - shouldn't be too hard.

I am just wondering if anyone can confirm whether or not the --dports option only works in some contexts or whether it can be used in place of the usual --dport option as a valid way to consolidate many rules into single multi-port rules.

eg.

iptables -A INPUT -p tcp -m tcp --dports 135,137,138,139 -m recent --name portscan --set -j DROP

Thanks,

Johnny
 
Old 04-21-2012, 09:29 PM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
What you are looking for is the multiport module...
Heres one I prepared earlier.
Code:
iptables -A lan-to-net -p tcp -m multiport --dports 1863,5222 -m comment --comment "Accept MSN XMPP(FB)" -j ACCEPT
You can also specify a range as such:
Code:
iptables -A INPUT -p tcp --dport 4000:4010 -j ACCEPT

Last edited by fukawi1; 04-21-2012 at 09:31 PM.
 
Old 04-21-2012, 10:11 PM   #3
johnnygear
LQ Newbie
 
Registered: Apr 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fukawi1 View Post
What you are looking for is the multiport module...
Heres one I prepared earlier.
Code:
iptables -A lan-to-net -p tcp -m multiport --dports 1863,5222 -m comment --comment "Accept MSN XMPP(FB)" -j ACCEPT
You can also specify a range as such:
Code:
iptables -A INPUT -p tcp --dport 4000:4010 -j ACCEPT
Thanks for that. I have done some reading on the multiport module and think I now have a decent grasp of it's functionality.

I have revised my rule below for anyone interested. Let me know if I am missing something.

iptables -A INPUT -p tcp -m multiport --dports 135:139 -m recent --name portscan --set -j DROP

Regards,

Johnny
 
Old 04-21-2012, 10:17 PM   #4
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 193Reputation: 193
You don't HAVE to use the multiport module to specify a range. But you do to specify none sequential ports.
Code:
iptables -A input -p tcp --dport 1000 -j ACCEPT # Valid
iptables -A input -p tcp --dport 1000:1100 -j ACCEPT # Valid
iptables -A input -p tcp --dport 1000,1010,1020 -j ACCEPT # Not Valid

iptables -A input -p tcp -m multiport --dports 1000,1010,1020 -j ACCEPT # Valid
iptables -A input -p tcp -m multiport --dports 1000:1100 -j ACCEPT # Valid
 
Old 04-21-2012, 10:18 PM   #5
johnnygear
LQ Newbie
 
Registered: Apr 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by fukawi1 View Post
You don't HAVE to use the multiport module to specify a range. But you do to specify none sequential ports.
Code:
iptables -A input -p tcp --dport 1000 -j ACCEPT # Not Valid
iptables -A input -p tcp --dport 1000:1100 -j ACCEPT # Valid
iptables -A input -p tcp --dport 1000,1010,1020 -j ACCEPT # Not Valid

iptables -A input -p tcp -m multiport --dports 1000,1010,1020 -j ACCEPT # Valid
iptables -A input -p tcp -m multiport --dports 1000:1100 -j ACCEPT # Valid
Thanks for the clarification. I greatly appreciate it.

Regards,

Johnny
 
  


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
Adding an option for 7zip to the Compress context menu in KDE4 Cultist Linux - Software 3 10-06-2011 06:23 AM
missed Unmount option in Nautilus' context menu jorgemarmo Linux - Desktop 1 07-08-2010 06:28 AM
Question about an iptables option kaplan71 Linux - Software 1 01-21-2009 05:18 PM
Remove 'Move to Trash' option from Konqueror context menu. arizonagroovejet Linux - Software 2 08-02-2008 05:12 PM
how to add konsole context menu option kahn Linux - Software 1 12-01-2007 09:08 AM

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

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