All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Newkirk <netfilter@newkirk.us>
To: William Olbrys <william_olbrys@student.uml.edu>,
	netfilter@lists.netfilter.org
Subject: Re: ip range generic matches
Date: Wed, 26 Feb 2003 03:31:32 -0500	[thread overview]
Message-ID: <200302260331.32469.netfilter@newkirk.us> (raw)
In-Reply-To: <7dfe27f780.7f7807dfe2@student.uml.edu>

On Wednesday 26 February 2003 01:23 am, William Olbrys wrote:
> is there a syntax to to create a generic match for a range of ips
> instead of the whole thing?
>
> ex.: $IPTABLES -t filter -A FORWARD -s 10.1.2.0-10.1.5.255 -j ACCEPT
>
> i tried to do this and it gave me an error about not being able to
> find the host. is there a workaround?
>
> will olbrys

Using a mask value.  You won't get that particular range into a single 
rule with a mask though. 10.1.2.0/21 or 10.1.2.0/255.255.248.0 will 
match 10.1.0.0 through 10.1.7.255, for example.  Your simplest rules for 
an accurate match to the range you listed above are:

$IPTABLES -A FORWARD -s 10.1.2.0/23 -j ACCEPT
$IPTABLES -A FORWARD -s 10.1.4.0/23 -j ACCEPT

where the first will match 10.1.2.0-10.1.3.255 and the second will match 
10.1.4.0-10.1.5.255.  Keep in mind that the mask used in an iptables 
rule doesn't have to have any real meaning outside the rule - it's not 
the subnet mask, just specifying which bits are fixed and which are 
variable to match the rule.  

It's also handy sometimes to know that you can use non-contiguous bits in 
the mask: 10.1.1.1/255.255.0.1 is valid, and will match all odd numbers 
in the last octet, throughout the whole 10.1.x.y address range. 
(obviously this mask can't be expressed as an integer, and cannot be a 
valid subnet mask)  You can accomplish really interesting things with 
this, like routing odd vs even DHCP-assigned IP's out different routes 
with the MARK target.  (often closer to an even distribution than trying 
to split into 2 fixed ranges of IPs :^)  It can also be convenient for 
DROPping some broadcasts - 10.1.1.255/0.0.0.255 will match ANY address 
that ends in a 255.

j



      parent reply	other threads:[~2003-02-26  8:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-26  6:23 ip range generic matches William Olbrys
2003-02-26  6:44 ` hanxin
2003-02-26  8:27 ` Esteban
2003-02-26  8:31 ` Joel Newkirk [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200302260331.32469.netfilter@newkirk.us \
    --to=netfilter@newkirk.us \
    --cc=netfilter@lists.netfilter.org \
    --cc=william_olbrys@student.uml.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.