This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ip range in paket filter rule?

is it possible to define an ip-range in a paket filter rule?
for example: 

allow ftp for 10.0.0.1-10.0.0.10 to any

if it isn't possible is there a workaround or do i have to define 254 network-devices and add them to different network groups?!


This thread was automatically locked due to age.
Parents
  • You're going to have to 'rough it' a little;
    by using subnetworks, you can do ranges based on power of 2. Then you make a Network group comprised of that subnetwork plus a few individual nodes. That's an inconvenience right now for those needing that functionality...
Reply
  • You're going to have to 'rough it' a little;
    by using subnetworks, you can do ranges based on power of 2. Then you make a Network group comprised of that subnetwork plus a few individual nodes. That's an inconvenience right now for those needing that functionality...
Children
  • So for 10.0.0.1-10, you pull out the Binary Calculator (as somebody else posted a while back, see Network Calculators) and see that a mask of 248 gives you a range of IPs from 1 to 7; so make a Network definition net-1-7, 10.0.0.0, subnet 255.255.255.248; then a net-8 (10.0.0.8), net-9 (10.0.0.9), and net-10 (10.0.0.10), all subnet 255.255.255.255. Finally a network group net-1-10, which is an aggregation of those network definitions.

    It ain't pretty, but it keeps your math skills sharp (until Astaro gets around to implementing decimal IP ranges...)
  • thanks a lot.
    a small example just to see if i'm right now:

    i want to add the ip's 10.0.0.21 - 10.0.0.30 to one group

    therefor i define the networks
    10.0.0.21/29 + 10.0.0.28/32 + 10.0.0.29/32 + 10.0.0.30/32
    is it right to start with 10.0.0.21/29 or 10.0.0.20/29 to get 10.0.0.21 as the first ip. 10.0.0.20 is also in use in another group.

    i'm not sure because you wrote 10.0.0.0/29 for net-1-7
  • enough with theoretical examples, here's something practical:

    i want to define a network group for the range 192.168.2.221 - 162.168.2.252 so how would the definitions look like?

    thanks for help
  • When they don't start at 0 it requires more work, but you can still do it. [And I suspect it's quicker for the iptables engine to process than a series of individual IPs, but they probably used a binary search in the code of the network stack for iptables, so it may not be so bad for performance to use all individual IPs, except for you who has to enter them! You might see a timing difference for skillions of packets.]

    To get a "power of 2" range, we 'walk forward' from 21 to 24 (as a beginner, you can enter the numbers in decimal and convert to binary; many operating system calculators support that function, and I'm sure there's a way to do that in Bash too). We see that:

    24     11000
    25     11001
    26     11010
    27     11011

    Do we see a pattern here? 110xx, where xx permutes over all combinations. So a mask of 255.255.255.24 with IP 10.0.0.24 covers the range of IPs from 10.0.0.24 to 10.0.0.27, inclusive.

    Unfortunately, for the other power of two ranges 'nearby' they include IPs we don't want. So we make a net-24-27 using the mask above; and net-21, net-22, net-23, net-28, net-29, and net-30 all with a mask of 32 (a network of one IP).

    Some Cisco router manuals include these IP ranges in handy tables (sort of like a mechanical engineer's log table reference manuals; wait a minute; we could build a mechanical engine to build these IP ranges! D'oh!! Mr.Babbage already thought of that some years back...); I could not easily locate any on the 'net. You could write a spreadsheet macro (I did in eleven lines using a function called DEC2BIN) that will list out the binary values for a decimal range (again, you can construct a loop in Bash to do the same thing). Then you identify a block of IPs whose leading bits don't change and whose trailing bits permute over all combinations (or locate tables of IP ranges and masks where they already did it for you).

    So for your example (and I like your tone: "enough with your uninteresting example, how about my MUCH more interesting one..." -just teasing), we can see that 192.168.2.224/255.255.255.224 generates a range from .224 to .239 inclusive, .240/255.255.255.240 generates a range from 240 to 247 inclusive, then for the 'straggler' IPs from .221-223 and .248-.252 you will have to generate individual IP addresses for each IP; bundle them all together in a network group.

    There's another way to find encompassing binary IP ranges involving binary logs, but this approach I find easier to follow.

    P.S. Probable typo in your post above; 162.168.2.252...

    Disclaimer: Due to the banal nature of performing these mundane calculations, it will not shock me if somebody finds an error in my math; that's why they generate the tables...
  • can i say:

    192.0.0.0/4 = 192.0.0.0 to 223.255.255.255
    128.0.0.0/2 = 128.0.0.0 to 191.255.255.255

    in yes, how can i write 1.0.0.0 to 126.255.255.255???

    TIA

    Gilera
  • 192/4=11000000-11001111=192-207
    (use binary calculator software)

    Your /2 calculation is correct.

    How? Difficultly.

    One way to cheat is to use a mask of 0/1 (that's networks 0-128), and then make a network definition 128...  (127 is loopback) and always add rules to exclude it.

    Failing that, you will have to make a network range from 0 to 64 (0/2) and then the smaller power of 2 ranges going from 65-126, and put them together as a network definition. That's a bit of work. If you want, I'll check your figures...

    Some people find it easier just to make the individual /8 definitions and group them. That might slow things down a tad in the iptables, but I think most people won't notice...