Skip to contentSkip to conversation

Defining ip range in a rule

DISCUSSION McDouglas 4 participants 4 messages Mar 20, 2006

lore
Share & tools
lore

McDouglas

author
#0 lore raw

Hi,

I'd like to ask how to define an ip address range in a rule. I don't mean using subnet mask but rather for example making a rule which will block port 110 for the 10.10.2.50-10.10.2.150 ip range.

Thank you.

Signature · 13 lines
Tisztelettel:

Gregorics Tamás

Szervízmunkatárs
M&M Computer Kft.
7623 Pécs, Mártírok u.42.
Tel.: +36-72/516-511
Fax: +36-72/516-529
Mobil: +36-30-943-6784
e-mail: [email protected]

http://www.mmcomputer.hu 
#1 lore raw
Quoted 7 lines · McDouglas

Hi,

I'd like to ask how to define an ip address range in a rule. I don't mean using subnet mask but rather for example making a rule which will block port 110 for the 10.10.2.50-10.10.2.150 ip range.

Thank you.

The iprange match is in most newer kernels. If it is missing in yours, you may need to patch. You may also need to check to see if it is included in activated in your kernel.

The man page will have more information but the syntax is:

iptables -A FORWARD -m iprange --[src|dst]-range x.x.x.x-y.y.y.y

Or at least so I recall. Good luck - John

Signature · 8 lines
John A. Sullivan III
Open Source Development Corporation
+1 207-985-7880
[email protected]

If you would like to participate in the development of an open source
enterprise class network security management system, please visit
http://iscs.sourceforge.net
#2 lore raw
In reply to McDouglas

Hi McDouglas,

Quoted 3 lines · McDouglas

Hi,

I'd like to ask how to define an ip address range in a rule. I don't mean using subnet mask but rather for example making a rule which will block port 110 for the 10.10.2.50-10.10.2.150 ip range.

If your kernel is compiled with CONFIG_IP_NF_MATCH_IPRANGE=y then check below Example.

iptables -I PREROUTING -t nat -m iprange --src-range

			       ^^^^^^^^^^^^^^^^^^^^^^	

10.10.2.50-10.10.2.150 -p tcp --dport 80 -j DNAT --to ^^^^^^^^^^^^^^^^^^^^^^^^^
10.10.2.1:3128

Hardik Dalwadi.

#3 lore raw
In reply to McDouglas
Quoted 6 lines

I'd like to ask how to define an ip address range in a rule. I don't mean using subnet mask but rather for example making a rule which will block port 110 for the 10.10.2.50-10.10.2.150 ip range.

for i in IpListDelimitedwithSpace
do
iptables -A INPUT -p tcp --dport 110 -s $i -J DROP

done

Askar.