Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
04-09-2010, 02:01 PM
|
#1
|
|
Member
Registered: Jan 2010
Location: Kurgan, Russia
Distribution: Slackware, Ubuntu
Posts: 334
Rep:
|
iptables issue
Hi guys.
I've consulted the iptables documentation, but the question is still actual. I wonder if the firewall has some parameter, which can handle multiple IP-addresses in the rule.
To make the problem more clear, I can show an example from OpenBSD's firewall - pf (from the oficial FAQ). OpenBSD's pf has a tool called 'tables' - it can store many addresses in one table:
Code:
table <goodguys> { 192.0.2.0/24 }
table <rfc1918> const { 192.168.0.0/16, 172.16.0.0/12, \
10.0.0.0/8 }
table <spammers> persist
block in on fxp0 from { <rfc1918>, <spammers> } to any
pass in on fxp0 from <goodguys> to any
Now let's go back to iptables.
Say, I'd like to restrict access to my webserver from 1.1.1.1, 2.2.2.2 and 3.3.3.3.
Do I have any opportunity to do it with one line ?
Code:
iptables -A INPUT -p tcp -d <my_webserver_ip> --dport 80 -s 1.1.1.1 -j DROP
iptables -A INPUT -p tcp -d <my_webserver_ip> --dport 80 -s 2.2.2.2 -j DROP
iptables -A INPUT -p tcp -d <my_webserver_ip> --dport 80 -s 3.3.3.3 -j DROP
^^ this doesn't look nice :-) But as far as i remember, there is not any option which could be useful to me (something like -m multiport --dport port1, port2, port3 but according to IP-addresses).
So, if there is, let me know please.
Regards, Lexus45 
Last edited by Lexus45; 04-09-2010 at 02:02 PM.
|
|
|
|
04-09-2010, 02:17 PM
|
#2
|
|
Senior Member
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571
Rep:
|
Make DEFAULT rule DROP, allow only what you need.
|
|
|
|
04-09-2010, 02:44 PM
|
#3
|
|
Senior Member
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833
Rep: 
|
Nimnull already gave the best solution in this particular situation but what you're asking for as far as I know, except for specifying networks there is no good way to do. You can of course use netmask and cidr notation.
|
|
|
|
04-10-2010, 01:17 AM
|
#4
|
|
Guru
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870
|
Quote:
Originally Posted by Lexus45
this doesn't look nice :-)
|
Uh, okay, but it's a firewall script – not ASCII artwork.
Seriously, though, are you really wanting to do this for purely cosmetic reasons?
Quote:
Originally Posted by nimnull22
Make DEFAULT rule DROP, allow only what you need.
|
Always good advice. Of course, he might already be doing that (which would make these akin to exceptions).
Last edited by win32sux; 04-10-2010 at 01:22 AM.
|
|
|
|
04-10-2010, 02:55 AM
|
#5
|
|
Member
Registered: Jan 2010
Location: Kurgan, Russia
Distribution: Slackware, Ubuntu
Posts: 334
Original Poster
Rep:
|
Quote:
Originally Posted by nimnull22
Make DEFAULT rule DROP, allow only what you need.
|
Of course, I do it :-)
(Even more, iptables - was the first thing I started learning about Linux. But it was some years ago...) :-)
Besides, the idea could be used not only with -j DROP in INPUT chain of the 'filter' table, but also in SNAT or REDIRECT or something else.
That's why I wonder...
Quote:
Originally Posted by rweaver
You can of course use netmask and cidr notation.
|
Sure, I know about netmasks :-) Nevertheless, thanks for advice ;-D
There may be situations when the addresses belong to different subnets (as in my example).
That's why I wonder.
Quote:
Originally Posted by win32sux
Uh, okay, but it's a firewall script – not ASCII artwork. 
|
Quote:
Originally Posted by win32sux
Seriously, though, are you really wanting to do this for purely cosmetic reasons?
|
I think it's much of pure interest...
I don't have really serious problems because of the absence of such a feature in iptables.
But I think it could be rather nice to have one.
So, as I was sure and as I also see from our discussion, iptables seems not to have such a feature.
Last edited by Lexus45; 04-10-2010 at 02:57 AM.
|
|
|
|
04-11-2010, 01:35 AM
|
#6
|
|
Member
Registered: Jul 2003
Location: NY
Distribution: None (src & compile)
Posts: 249
Rep:
|
I think what you are wanting to do is provided by an iptables friend called 'ipset'. I used to have it here for awhile, but at each new kernel updated they (kernel devs) seemed to break something and I got sick and tired of patching it and my patch-o-matic iptables extensions all the time to keep it working when I didn't use it that much. So I let it go. Maybe it's still around and buildable, depending on what kernel version you have going. I see the -m match for it is still in the iptables man page:
Quote:
set
This modules macthes IP sets which can be defined by ipset(8).
|
but I can't say if it fully works now or will meet your needs. The URL for it escapes me ATM, but it's on the Netfilter ftp server (where the iptables source is). Maybe ftp://ftp.netfilter.org/ ?
|
|
|
|
04-11-2010, 04:17 AM
|
#7
|
|
Member
Registered: Jan 2010
Location: Kurgan, Russia
Distribution: Slackware, Ubuntu
Posts: 334
Original Poster
Rep:
|
jayjwa, an interesting note, thanks.
So I think, it's better not to change anything because my problem is not serious. :-)
|
|
|
|
04-11-2010, 05:17 AM
|
#8
|
|
Senior Member
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 3,692
|
Quote:
Originally Posted by Lexus45
I wonder if the firewall has some parameter, which can handle multiple IP-addresses in the rule.
|
Not, as far as I know, a firewall parameter...
Quote:
Code:
iptables -A INPUT -p tcp -d <my_webserver_ip> --dport 80 -s 1.1.1.1 -j DROP
iptables -A INPUT -p tcp -d <my_webserver_ip> --dport 80 -s 2.2.2.2 -j DROP
iptables -A INPUT -p tcp -d <my_webserver_ip> --dport 80 -s 3.3.3.3 -j DROP
^^ this doesn't look nice :-)
|
I'm with win32sux on this; if there was ever an area in function has to take priority over pretty looking code, this (security, generally) is it.
Having said that, it seems that modules like blockhosts, fail2ban, denyhosts, sshban could do what you say that you want. These are things that are aimed at working with dynamic ip lists, but there doesn't seem to be a reason that they cannot be used with a short, static, list of bad guys. It would be more of an issue if there were hundreds of them, rather than three...
But you have to question whether this is a worthwhile objective - there is a little messy complexity, and you have succeeded in putting it somewhere other than in the basic iptables set of rules, which does keep iptables looking clean. But does it make things any more secure?
The difficulty with any of these measures is that if they don't work quickly, they can increase your susceptibility to DoS and more specifically DDoS attacks.
So would you want to clean up your iptables rules, at the expense of increasing you susceptibility to a particular type of attack (if that is what it would do)? Well, I don't think, put like that, it would be a worthwhile objective.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:26 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|