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.
|
 |
03-30-2009, 03:48 PM
|
#1
|
Member
Registered: Nov 2003
Posts: 810
Rep:
|
Blocking an ip address range within iptables
Hi there --
I am setting up a iptables firewall on one of our servers, and I would like to block a range of addresses from getting into the system. I am using a script that does a BLACKIN and BLACKOUT methodology for specific addresses. One example is the following:
Code:
$IPTABLES -A BLACKIN -s 202.109.114.147 -j DROP
...
$IPTABLES -A BLACKOUT -d 202.109.114.117 -j DROP
What would be the correct syntax to use if I wanted to block an entire remote subnet from getting into the server? Thanks.
|
|
|
03-30-2009, 04:30 PM
|
#2
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Rep: 
|
Good news -- iptables supports netmasks. From man iptables(8):
Quote:
-s, --source [!] address[/mask]
Source specification. Address can be either a network name, a
hostname (please note that specifying any name to be resolved
with a remote query such as DNS is a really bad idea), a network
IP address (with /mask), or a plain IP address. The mask can be
either a network mask or a plain number, specifying the number
of 1’s at the left side of the network mask. Thus, a mask of 24
is equivalent to 255.255.255.0. A "!" argument before the
address specification inverts the sense of the address. The flag
--src is an alias for this option.
|
|
|
|
03-31-2009, 12:41 AM
|
#3
|
LQ Guru
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870
|
Also, if you literally want to use ranges (instead of subnets), you can do like:
Code:
$IPTABLES -A BLACKIN -m iprange --src-range 202.109.114.117-202.109.114.147 -j DROP
|
|
|
03-31-2009, 01:33 PM
|
#4
|
Member
Registered: Nov 2003
Posts: 810
Original Poster
Rep:
|
Hi there --
Thanks for your reply. I went ahead with the iprange option using the following syntax:
Code:
$IPTABLES -A BLACKIN -m iprange --src-range xxx.xxx.xxx.0-xxx.xxx.xxx.255 -j DROP
...
$IPTABLES -A BLACKOUT -m iprange --dst-range xxx.xxx.xxx.0-xxx.xxx.xxx.255 -j DROP
I ran the script with no apparent error messages. The output of the iptables -vnL command in regards to the above example showed the following:
Quote:
Chain BLACKIN (1 references)
pkts bytes target prot opt in out source destination
0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 source IP range xxx.xxx.xxx.0-xxx.xxx.xxx.255
Chain BLACKOUT (0 references)
pkts bytes target prot opt in out source destination
0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 destination IP range xxx.xxx.xxx.0-xxx.xxx.xxx.255
|
Unless I am mistaken, is that the correct output? Thanks.
|
|
|
03-31-2009, 02:55 PM
|
#5
|
LQ Guru
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870
|
Looks good to me.
|
|
|
All times are GMT -5. The time now is 10:48 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
|
|