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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-15-2006, 03:55 AM
|
#1
|
Member
Registered: Aug 2005
Location: California
Distribution: CentOS 5
Posts: 54
Rep:
|
banning multiple IP's with iptables
Hey guys. I'm running Fedora Core 5 and want to customize my IPTABLES firewall in order to bolster system security. I have two separate questions that aren't being answered by the tutorials I've read:
1. I want to ban an entire range of IP address within a given network, not just a single IP. There's got to be a way to do that w/o typing out 256 or more addresses and entering them in one-by-one! I typed the following:
-----
root# iptables -A INPUT -j DROP 123.456.789.0/24
Bad argument `123.456.789.0/24'
Try `iptables -h' or 'iptables --help' for more information.
root#
------
Where of course 123.456.789.0 is the class C network whose incoming packets I'm trying to stop at my firewall. It is to be completely prohibited from contacting the system in any way and any packets that do arrive from there are to go unacknowledged. I don't even want users on that network being able to view my web pages.
So what's wrong with my syntax? The tutorial I was using swears up and down that the command *should* work as advertised. Maybe iptables has changed since it was written, so can anyone tell me the correct syntax?
2. I entered a long list of individual IP addresses into the firewall using the command given above. I confirmed that they'd been loaded by running iptables -L. It showed me the rules as I expected to see. HOWEVER, the rules were all gone when I rebooted the entire system and ran iptables -L a second time. What do I need to do in order to make the iptables rules permanent so that they'll survive a system reboot?
Thanks in advance, Matt
|
|
|
05-15-2006, 07:12 AM
|
#2
|
Member
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536
Rep:
|
1. The ip address(es) is/are specified via the -s (source address) option, e.g.
Code:
iptables -A INPUT -s 123.456.789.0/24 -j DROP
2. Use iptables-save and iptables-restore. You need to redirect the input/output, e.g. 'iptables-save > /root/iptables.conf', and put 'iptables-restore < /root/iptables.conf' in your rc.local.
|
|
|
05-15-2006, 11:58 AM
|
#3
|
Member
Registered: Aug 2005
Location: California
Distribution: CentOS 5
Posts: 54
Original Poster
Rep:
|
re: banning multiple IP's with iptables
Thanks for your help. Apparently I was being tripped up by a simple typo.
One more question. I'd like to write a rule that says "Ban ALL connections from ALL systems, except for the ones explictly allowed to connect." I'd also like to write a rule that says, "If a system wants to connect to port 80, check the banned list. If it's not there, let it in."
Where in the iptables rule list would I put such rules - the beginning or the end? I'm afraid of guessing wrong and locking myself out of my own server. Does iptables look at the "allow" section before it looks at the "deny" section (the way TCP wrappers does), or does it just apply the rules sequentially?
Thanks
|
|
|
05-15-2006, 12:06 PM
|
#4
|
Member
Registered: Aug 2005
Location: California
Distribution: CentOS 5
Posts: 54
Original Poster
Rep:
|
One more thing...when you say put that command in rc.local, do you mean simply edit the file and type in a line that says "iptables-restore" after running the command above?
|
|
|
05-15-2006, 01:17 PM
|
#5
|
Senior Member
Registered: Nov 2004
Distribution: Mint, MX, antiX, SystemRescue
Posts: 2,337
|
Quote:
Originally Posted by cylarz
I'd like to write a rule that says "Ban ALL connections from ALL systems, except for the ones explictly allowed to connect." I'd also like to write a rule that says, "If a system wants to connect to port 80, check the banned list. If it's not there, let it in."
|
Ccheck post #2 in this thread: http://www.linuxquestions.org/questi...d.php?t=438127 for my iptables script. I think it doeas a lot of what you are wanting to do. Basically, just set your default policy to DROP, and then add ACCEPT rules for those you want ot allow in.
|
|
|
05-15-2006, 01:31 PM
|
#6
|
Member
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536
Rep:
|
Yes, the kernel applies the rules sequentially.
haertig has covered the rest.
As for rc.local, yeah, just would type the line in somewhere, but if you use haertig's script, you don't need iptables-{save,restore} anymore.
Last edited by ioerror; 05-15-2006 at 02:11 PM.
|
|
|
05-22-2006, 03:42 PM
|
#7
|
Member
Registered: Jan 2006
Location: Finland
Distribution: Mainly Gentoo
Posts: 119
Rep:
|
I might add a quick note:
is there any difference between 0.0.0.0/24 and the one I've been using; e.g. -m iprange --src-range 1.1.1.1-2.2.2.2 -j LOG?
|
|
|
All times are GMT -5. The time now is 04:15 AM.
|
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
|
|