Skip to contentSkip to conversation

Arbitrary Netmasks

DISCUSSION Filipe Almeida 3 participants 5 messages May 28, 2002 – May 29, 2002 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

I usually use:

iptables -A FORWARD -s 0.0.0.255/0.0.0.255 -j DROP iptables -A FORWARD -d 0.0.0.255/0.0.0.255 -j DROP iptables -A FORWARD -s 0.0.0.0/0.0.0.255 -j DROP iptables -A FORWARD -d 0.0.0.0/0.0.0.255 -j DROP

to stop routing of broadcasted packets. This works assuming you only have 256 sized classes.

Quoted 11 lines · Thomas Heinz

Hi

Netfilter supports arbitrary netmasks for IP addresses which is more powerful than just those IP/x (0 <= x <= 32) expressions.
For example one could use IP/255.0.255.255 (IP/23.13.42.0 would also work ;-).

Are masks that cannot be expressed in the IP/x schmeme (at least not in one rule) used in practise? Are they used at all in firewall rulesets?

Thomas

#4 lore raw
In reply to a message not in the archive

Hi,

(removed netfilter-devel from the headers, this is not a development Q)

Quoted 6 lines

Netfilter supports arbitrary netmasks for IP addresses which is more powerful than just those IP/x (0 <= x <= 32) expressions.
For example one could use IP/255.0.255.255 (IP/23.13.42.0 would also work ;-).

Are masks that cannot be expressed in the IP/x schmeme (at least not in one rule) used in practise? Are they used at all in firewall rulesets?

They are used in practise. I have been using them with ipfwadm, and I am using them with iptables.

What I use them for, is "statistical multiplexing" based on one or more of the low bits (but not the lowest!) of IP addresses. For example, I have a dual-processor system with two squid processes, and want to distribute a number of incoming clients evenly (and deterministically) over the two squid processes. For godgiven reasons, under light load, the "even" client IPs are preferred over the "odd" client IPs. To get a good distribution for both light load and full load, I look at the second lowest bit of the client IP address to determine where to REDIRECT to, like this:

iptables -t nat -A PREROUTING -s 0.0.0.0/0.0.0.2 -j REDIRECT --to-port 1234 iptables -t nat -A PREROUTING -s 0.0.0.2/0.0.0.2 -j REDIRECT --to-port 1235

Another real world example I have seen in use in Cisco access-lists, where the noncontigous mask works just like in iptables, is to pick out "the same local ip" in a range of subnets. Imagine you have a number of LANs with IP addresses 10.23.x.y/16, and y==1 is your default gateway in every LAN. Given 10.23.0.1/255.255.0.255, you have a single-rule expression for "all gateways in my LANs", which is preferrable (if you manage to keep to the scheme!) to a sequential list of rules, one per LAN.

best regards
Patrick

#2 lore raw
In reply to Filipe Almeida

Which is not generally a valid thing to assume.. the .255 and/or .0 address may be in use on larger networks, especially if addresses are assigned dynamically using a large DHCP scope..

Quoted 9 lines · Filipe Almeida

I usually use:

iptables -A FORWARD -s 0.0.0.255/0.0.0.255 -j DROP iptables -A FORWARD -d 0.0.0.255/0.0.0.255 -j DROP iptables -A FORWARD -s 0.0.0.0/0.0.0.255 -j DROP iptables -A FORWARD -d 0.0.0.0/0.0.0.255 -j DROP

to stop routing of broadcasted packets. This works assuming you only have 256 sized classes.

#5 lore raw
In reply to a message not in the archive
Quoted 4 lines · Thomas Heinz

Netfilter supports arbitrary netmasks for IP addresses which is more powerful than just those IP/x (0 <= x <= 32) expressions. For example one could use IP/255.0.255.255 (IP/23.13.42.0 would also work ;-).

Yes, this is the fastest method when matching filter expressions..

Quoted 3 lines

Are masks that cannot be expressed in the IP/x schmeme (at least not in one rule) used in practise? Are they used at all in firewall rulesets?

Not in real life networks, but such masks are useful in certain types of expressions, for example load balancing based on destination, or as wildcard matches for matching "all your routers / servers / whatever" assuming you have a well structured addressing scheme in your own networks..

Regards
Henrik

#3 lore raw
In reply to Henrik Nordstrom

True.
I attach interface (-i/-o) matches so I will only filter my networks. I wrote those lines of the top of my head so I forgot the -i/-o.

Quoted 15 lines · Henrik Nordstrom

Which is not generally a valid thing to assume.. the .255 and/or .0 address may be in use on larger networks, especially if addresses are assigned dynamically using a large DHCP scope..

Quoted 9 lines · Filipe Almeida

I usually use:

iptables -A FORWARD -s 0.0.0.255/0.0.0.255 -j DROP iptables -A FORWARD -d 0.0.0.255/0.0.0.255 -j DROP iptables -A FORWARD -s 0.0.0.0/0.0.0.255 -j DROP iptables -A FORWARD -d 0.0.0.0/0.0.0.255 -j DROP

to stop routing of broadcasted packets. This works assuming you only have 256 sized classes.