<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bits &#124; andy smith&#039;s blog &#187; IPTables/Netfilter</title>
	<atom:link href="http://andys.org.uk/bits/category/security/iptablesnetfilter/feed/" rel="self" type="application/rss+xml" />
	<link>http://andys.org.uk/bits</link>
	<description>random stuff from the mind of a twenty-something professional geek</description>
	<lastBuildDate>Sat, 21 Jan 2012 18:36:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>IPv6 for a Linux generation</title>
		<link>http://andys.org.uk/bits/2010/02/07/ipv6-for-an-linux-generation/</link>
		<comments>http://andys.org.uk/bits/2010/02/07/ipv6-for-an-linux-generation/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 23:35:04 +0000</pubDate>
		<dc:creator>Andy Smith</dc:creator>
				<category><![CDATA[IPTables/Netfilter]]></category>
		<category><![CDATA[IPv6]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://andys.org.uk/bits/?p=33</guid>
		<description><![CDATA[IPv6 is nothing new &#8211; it was finally standardised back in 1998 in RFC 2460, and virtually all operating systems have supported it now for at least 5 years, so most people are in a position to give it a try. If you&#8217;re one of the lucky ones, your ISP might provide native IPv6 connectivity [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/IPv6">IPv6</a> is nothing new &#8211; it was finally standardised back in 1998 in <a href="http://tools.ietf.org/html/rfc2460">RFC 2460</a>, and virtually all operating systems have supported it now for at least 5 years, so most people are in a position to give it a try.</p>
<p>If you&#8217;re one of the lucky ones, your ISP might provide native IPv6 connectivity (like <a href="http://www.aaisp.net.uk/kb-broadband-ipv6.html">AAISP</a>), but for most of us, the main way to get connected to the rest of the IPv6 Internet is to use something we&#8217;ve already got &#8211; IPv4. And we&#8217;re going to tunnel over it.</p>
<p><span id="more-33"></span>The first thing we need to do is choose a tunnel broker, which is a fancy name for someone who&#8217;ll provide us with an IPv4 endpoint we can tunnel IPv6 over. Wikipedia <a href="http://en.wikipedia.org/wiki/List_of_IPv6_tunnel_brokers">has a list</a>, but the main, globally available ones are <a href="http://tunnelbroker.net/">Hurricane Electric</a> and <a href="http://www.sixxs.net/">SixXS</a>. Either of these will do, and some people prefer HE over SixXS, but that&#8217;s a purely personal choice &#8211; in my experience, both work equally as well. For this example, though, we&#8217;ll go with HE &#8211; so head on over to <a href="http://tunnelbroker.net/">http://tunnelbroker.net/</a> and create an account.</p>
<h2>My first tunnel</h2>
<p>Once you&#8217;ve created your account, log in and create a tunnel. For some reason, it always seems to pick their New York POP, so you might want to manually choose one geographically closer (in my case &#8211; and for our example &#8211; London, UK)</p>
<div id="attachment_34" class="wp-caption aligncenter" style="width: 439px"><a href="http://andys.org.uk/bits/wp-content/uploads/2010/02/tunnel1.png"><img class="size-full wp-image-34" title="Creating a tunnel" src="http://andys.org.uk/bits/wp-content/uploads/2010/02/tunnel1.png" alt="" width="429" height="502" /></a><p class="wp-caption-text">Creating a tunnel</p></div>
<p>The IP address you use as your local end of the tunnel will need to be a public IP address. It&#8217;s possible to use a machine behind a NAT device if it&#8217;s in a DMZ-style setup where all the traffic destined for the public IP address gets forwarded by the NAT device to the machine behind it, but your mileage may vary.</p>
<p>Once created, view the tunnel details, which should look something like this:-</p>
<div id="attachment_35" class="wp-caption aligncenter" style="width: 460px"><a href="http://andys.org.uk/bits/wp-content/uploads/2010/02/tunnel2.png"><img class="size-full wp-image-35" title="Editing the tunnel details" src="http://andys.org.uk/bits/wp-content/uploads/2010/02/tunnel2.png" alt="Editing the tunnel details" width="450" height="324" /></a><p class="wp-caption-text">Editing the tunnel details</p></div>
<p style="text-align: left;">Our tunnel has been created! At the bottom of the page, you&#8217;ll notice a little drop-down that generates the commands needed to bring up the tunnel. For this example, we&#8217;re using <a href="http://en.wikipedia.org/wiki/Iproute2">iproute2</a>, so the commands go something like this:-</p>
<p>&nbsp;</p>
<blockquote>
<pre>ip tunnel add he-ipv6 mode sit remote 216.66.80.26 local 192.0.2.1 ttl 255
ip link set he-ipv6 up
ip addr add 2001:470:1f08:810::2/64 dev he-ipv6
ip route add ::/0 dev he-ipv6</pre>
</blockquote>
<p>The first command creates an IPv6-in-IPv4 tunnel between us and HE, and the second command brings up that tunnel. The third command adds our IPv6 address to our end of the tunnel, and finally the fourth command sets the IPv6 default route to be down our newly-created tunnel.</p>
<p>And that&#8217;s it &#8211; we&#8217;re now connected to the global IPv6 internet. To test it, let&#8217;s try pinging something:-</p>
<blockquote>
<pre>mordor:~# <strong>ping6 -c 3 www.he.net</strong>
PING www.he.net(he.net) 56 data bytes
64 bytes from he.net: icmp_seq=1 ttl=58 time=375 ms
64 bytes from he.net: icmp_seq=2 ttl=58 time=257 ms
64 bytes from he.net: icmp_seq=3 ttl=58 time=255 ms</pre>
<pre>--- www.he.net ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 255.562/296.218/375.628/56.158 ms</pre>
</blockquote>
<p>If you see something like the above, then give yourself a pat on the back, because it&#8217;s working!</p>
<h2>Next steps</h2>
<p>HE by default assigns you a <strong>/64</strong> network, which is <a href="http://www.ripe.net/docs/ipv6policy.html#assignment_size">the smallest size intended to be allocated</a>. This gives you <strong>18,446,744,073,709,551,616</strong> IPs, and whichever way you look at it that&#8217;s a lot of addresses. With this in mind, you might be wondering why HE will give you a <strong>/48</strong> (that&#8217;s <em><strong>1,208,925,819,614,629,174,706,176</strong></em> IPs!). The reason is that each network is intended to have a /64, and a /48 allows you to carve up that space into a total of <strong>65,536</strong> separate /64 networks. Now this obviously sounds like overkill to the average user, but autoconfiguration tools such as <a href="http://en.wikipedia.org/wiki/Radvd">radvd</a> won&#8217;t work with networks smaller than /64, again because of the intentions mentioned previously. This means that if you have more than one network at home (say, a wired network and a wireless network, currently with separate IPv4 networks for each), you can assign a /64 to each one.</p>
<p>With this is mind, let&#8217;s ask HE for a /48 by clicking on <strong>Allocate</strong> in the &#8216;Routed /48&#8242; section. After a few seconds, you&#8217;ll see something like this:-</p>
<div id="attachment_37" class="wp-caption aligncenter" style="width: 456px"><a href="http://andys.org.uk/bits/wp-content/uploads/2010/02/tunnel4.png"><img class="size-full wp-image-37" title="Allocating our /48" src="http://andys.org.uk/bits/wp-content/uploads/2010/02/tunnel4.png" alt="" width="446" height="51" /></a><p class="wp-caption-text">Allocating our /48</p></div>
<p>In our example, we&#8217;ve been allocated <code>2001:470:90d3::/48</code>, and now it&#8217;s time to plan our IP schema.</p>
<h2>Laying it out</h2>
<p>Taking my own home network as an example, I have three networks &#8211; one for general use (the &#8216;<em>LAN</em>&#8216;), one for guest use over wireless (the &#8216;<em>WLAN</em>&#8216;), and finally a DMZ (the&#8230; er, &#8216;<em>DMZ</em>&#8216;). We could lay these out like this:-</p>
<ul>
<li>LAN &#8211; <code>2001:470:90d3:<strong><span style="color: #008000;">1</span></strong>::/64</code></li>
<li>DMZ &#8211; <code>2001:470:90d3:<span style="color: #008000;"><strong>2</strong></span>::/64</code></li>
<li>WLAN &#8211; <code>2001:470:90d3:<strong><span style="color: #008000;">3</span></strong>::/64</code></li>
</ul>
<p>Nice and simple, and easy to remember. Assuming all three networks are connected to the same gateway machine, we can give the gateway the first IP in the range &#8211; <code>2001:470:90d3:<strong><span style="color: #008000;">1::1</span></strong></code>, <code>2001:470:90d3:<strong><span style="color: #008000;">2::1</span></strong></code> and <code>2001:470:90d3:<strong><span style="color: #008000;">3::1</span></strong></code>.</p>
<h2>Routing things further</h2>
<p>Before we start, we need to enable IP forwarding for IPv6:-</p>
<blockquote>
<pre>sysctl -w net.ipv6.conf.all.forwarding=1</pre>
</blockquote>
<p>You&#8217;ll probably want to add this somewhere so it gets activated on bootup &#8211; under Debian this would be in <code>/etc/sysctl.conf</code> (which already has the entry, albeit commented out).</p>
<p>One way to provide connectivity to machines on the individual networks is to manually give each machine an IPv6 address, and to route it through our gateway:-</p>
<blockquote>
<pre>ip addr add 2001:470:90d3:1::2/64 dev eth0
ip route add ::/0 via 2001:470:90d3:1::1 dev eth0</pre>
</blockquote>
<p>Again, all being well, you should now be able to route to the wider IPv6 Internet from our newly-configured IPv6 node. More importantly, this also means that the wider IPv6 Internet can route back to you &#8211; which brings us to&#8230;</p>
<h2>Security, not obscurity</h2>
<p>Don&#8217;t be fooled into thinking that because of the immense range of possible IPv6 addresses that securing your new IPv6 setup isn&#8217;t required &#8211; IPv6 is no exception when it comes to the Internet Bad Guys, so implementing firewall rules is of the utmost importance.</p>
<p>The problem with IPv4 and NAT is that it&#8217;s allowed people to become somewhat complacent about security, because machines behind a NAT device are naturally unreachable from the global Internet. IPv6 does not have NAT, which means you don&#8217;t have this (rather lazy) safety net, so we have to do it properly.</p>
<p>Luckily, if you&#8217;re familiar with <a href="http://www.netfilter.org/projects/iptables/index.html">iptables</a>, you&#8217;ll be glad to know that there&#8217;s an IPv6 equivalent &#8211; and it&#8217;s called (predicatably) <a href="http://www.centos.org/docs/4/html/rhel-rg-en-4/s1-ip6tables.html">ip6tables</a>. The syntax is identical, and in fact the only noticeable difference is that you&#8217;re using IPv6 addresses and networks instead of IPv4 ones.</p>
<p>A quick example would go something like this:-</p>
<blockquote>
<pre><em># Clear our INPUT, OUTPUT and FORWARD chains</em>
ip6tables -F INPUT
ip6tables -F OUTPUT
ip6tables -F FORWARD

<em># Allow packets related to existing connections</em>
ip6tables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
ip6tables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT

<em># Allow link-local (for neighbour discovery)</em>
ip6tables -A INPUT -s fe80::/10 -j ACCEPT

<em># Allow SSH inbound to our gateway from our LAN</em>
ip6tables -A INPUT -i lan -s 2001:470:90d3:1::/64 -p tcp
   -m tcp --dport 22 -j ACCEPT

<em># Allow all outbound from our networks</em>
ip6tables -A FORWARD -i lan -s 2001:470:90d3:1::/64 -j ACCEPT
ip6tables -A FORWARD -i dmz -s 2001:470:90d3:2::/64 -j ACCEPT
ip6tables -A FORWARD -i wlan -s 2001:470:90d3:3::/64 -j ACCEPT

<em># Allow all outbound from our gateway</em>
ip6tables -A OUTPUT -j ACCEPT

<em># Allow SSH and HTTPS inbound to our DMZ</em>
ip6tables -A FORWARD -i he-ipv6 -d 2001:470:90d3:1::/64 -p tcp
   -m multiport --dports 22,443 -j ACCEPT

<em># Set the default policy to drop</em>
ip6tables -P INPUT DROP
ip6tables -P FORWARD DROP
ip6tables -P OUTPUT DROP</pre>
</blockquote>
<p>So there you have it &#8211; IPv6 firewalling needn&#8217;t be difficult. If you want to make something more complex, you might want to take a look at my previous post about <a href="http://andys.org.uk/bits/2010/01/27/iptables-fun-with-mark/">iptables and the &#8216;mark&#8217; target</a>, which also applies to ip6tables.</p>
<h2>IPv6 &#8211; automatically</h2>
<p>Just like DHCP for IPv4, there are autoconfiguration mechanisms for IPv6 &#8211; radvd and DHCPv6. Radvd is the older of the two, but both can be used for the same purpose. Configuration of radvd is relatively straightforward, and if we wanted to provide autoconfiguration on our example LAN, we can do something like this:-</p>
<blockquote>
<pre>interface lan
{
      AdvSendAdvert on;
      MinRtrAdvInterval 3;
      MaxRtrAdvInterval 10;
      AdvDefaultPreference low;
      AdvHomeAgentFlag off;

      prefix 2001:470:90d3:2::/64
      {
            AdvOnLink on;
            AdvAutonomous on;
            AdvRouterAddr off;
      };
};</pre>
</blockquote>
<h2>Where next?</h2>
<p>This only covers the start &#8211; there&#8217;s more involved in bringing an IPv6 network up to scratch, like setting up forward and reverse <a href="http://www.linuxjournal.com/article/6541">DNS</a>, and <a href="http://tldp.org/HOWTO/Linux+IPv6-HOWTO/chapter-hints-daemons.html">configuring</a> <a href="http://www.linuxjournal.com/article/5451">various</a> <a href="http://www.bieringer.de/linux/IPv6/IPv6-HOWTO/IPv6-HOWTO-7.html">daemons</a> to talk over IPv6 as well as IPv4. If you&#8217;re interested, you might find some of the following links useful reading:-</p>
<ul>
<li><a href="http://tldp.org/HOWTO/Linux+IPv6-HOWTO/index.html">Peter Bieringer&#8217;s Linux IPv6 Howto</a></li>
<li><a href="http://www.ipv6.org.uk/">IPv6 in the UK</a></li>
<li><a href="http://tools.ietf.org/html/rfc2460">RFC 2460 &#8211; IPv6 Specification</a></li>
<li><a href="http://www.deepspace6.net/">Deep Space 6</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://andys.org.uk/bits/2010/02/07/ipv6-for-an-linux-generation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>IPTables: Fun with MARK</title>
		<link>http://andys.org.uk/bits/2010/01/27/iptables-fun-with-mark/</link>
		<comments>http://andys.org.uk/bits/2010/01/27/iptables-fun-with-mark/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 13:52:45 +0000</pubDate>
		<dc:creator>Andy Smith</dc:creator>
				<category><![CDATA[IPTables/Netfilter]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[group]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[mark]]></category>
		<category><![CDATA[netfilter]]></category>

		<guid isPermaLink="false">http://andys.org.uk/bits/?p=10</guid>
		<description><![CDATA[One thing that&#8217;s always bugged me about IPTables is the lack of a way to use groups when writing rules, which can complicate things if you&#8217;ve got a potentially large rulebase. One way round this is to use something like fwbuilder, which gives you a graphical interface not unlike Checkpoint&#8216;s SmartDashboard GUI for their Firewall-1 [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that&#8217;s always bugged me about <a href="http://www.netfilter.org">IPTables</a> is the lack of a way to use groups when writing rules, which can complicate things if you&#8217;ve got a potentially large rulebase. One way round this is to use something like <a href="http://www.fwbuilder.org">fwbuilder</a>, which gives you a graphical interface not unlike <a href="http://www.checkpoint.com/">Checkpoint</a>&#8216;s <a href="http://www.checkpoint.com/products/smartcenter/smartcenter_management.html">SmartDashboard</a> GUI for their Firewall-1 devices. The downside to this, though, is that the resulting IPTables ruleset is far from legible &#8211; which, to be fair, isn&#8217;t the goal of fwbuilder &#8211; and this makes hacking about with the rules nearly impossible.</p>
<p>So what options are there? One way is to repeat the same rule for different sources or destinations, but this can quickly get messy, especially if there&#8217;s multiple ports involved. If there was a way we could group things together and keep them tidy, maintaining the rulebase would be a lot easier. This is where <strong>MARK</strong> comes in.</p>
<p><span id="more-10"></span>The MARK target lets us set a 32-bit value (or 0xFFFFFFFF) on a packet, which we can then look for later with the <strong>mark</strong> match. This in itself can be useful, but where it gets really handy is adding the values together.</p>
<h3>Starting out</h3>
<p>To start off with, here&#8217;s an example</p>
<blockquote>
<pre># Create a new chain, which will in effect be our source 'group'
iptables -N <span style="color: #000080;">S-TRUSTED</span>
# Add our sources
iptables -A <span style="color: #000080;">S-TRUSTED</span> -s 192.168.1.1/32 -j MARK --set-xmark <span style="color: #008000;">0x8/0x0</span>
iptables -A <span style="color: #000080;">S-TRUSTED</span> -s 192.168.2.0/24 -j MARK --set-xmark <span style="color: #008000;">0x8/0x0</span>
iptables -A <span style="color: #000080;">S-TRUSTED</span> -s 192.168.3.3/29 -j MARK --set-xmark <span style="color: #008000;">0x8/0x0</span>

# Create a chain for the destination group
iptables -N <span style="color: #000080;">D-DMZ</span>
# Add our DMZ machines
iptables -A <span style="color: #000080;">D-DMZ</span> -d 10.1.1.1/32 -j MARK --set-xmark <span style="color: #008000;">0x4/0x0</span>
iptables -A <span style="color: #000080;">D-DMZ</span> -d 10.1.2.0/24 -j MARK --set-xmark <span style="color: #008000;">0x4/0x0</span>

# Create a chain for the services
iptables -N <span style="color: #000080;">D-SRV-MGMT</span>
# Add our service
iptables -A <span style="color: #000080;">D-SRV-MGMT</span> -p tcp -m tcp --dport 22 -j MARK --set-xmark <span style="color: #008000;">0x2/0x0</span>
iptables -A <span style="color: #000080;">D-SRV-MGMT</span> -p tcp -m tcp --dport 80 -j MARK --set-xmark <span style="color: #008000;">0x2/0x0</span></pre>
</blockquote>
<p>So what we have now are three chains, which do the following</p>
<ul>
<li>If the source matches, add <span style="color: #008000;"><strong>0&#215;8</strong></span> to the packet mark</li>
<li>If the destination matches, add <span style="color: #008000;"><strong>0&#215;4</strong></span> to the packet mark</li>
<li>If the service matches, add <span style="color: #008000;"><strong>0&#215;2</strong></span> to the packet mark</li>
</ul>
<p>If you know your hexadecimal, you&#8217;ll already know that if all of these are true, we&#8217;ll come out with <strong><span style="color: #008000;">0xE</span></strong> (or 14, in decimal).</p>
<h3>Making the rule</h3>
<p>Hopefully you&#8217;ll see where we&#8217;re going with this with the next example, which is our actual rule</p>
<blockquote>
<pre># Create a new chain for our rule and add it to our FORWARD chain
iptables -N <span style="color: #000080;">R-ALLOW-DMZ-MGMT</span>
iptables -A FORWARD -j <span style="color: #000080;">R-ALLOW-DMZ-MGMT</span>
# Zero out the packet mark to make sure no previous rules interfere
iptables -A <span style="color: #000080;">R-ALLOW-DMZ-MGMT</span> -j MARK --set-xmark <span style="color: #008000;">0x0/0x0</span>
# Jump to our 'source group' chain
iptables -A <span style="color: #000080;">R-ALLOW-DMZ-MGMT</span> -j <span style="color: #000080;">S-TRUSTED</span>
# Jump to our 'destination group' chain
iptables -A <span style="color: #000080;">R-ALLOW-DMZ-MGMT</span> -j <span style="color: #000080;">D-DMZ</span>
# Jump to our 'service group' chain
iptables -A <span style="color: #000080;">R-ALLOW-DMZ-MGMT</span> -j <span style="color: #000080;">D-SRV-MGMT</span>
# If the packet mark matches <strong><span style="color: #008000;">0xE</span></strong>, then ACCEPT
iptables -A <span style="color: #000080;">R-ALLOW-DMZ-MGMT</span> -m mark --mark <span style="color: #008000;">0xE</span> -j <span style="color: #000080;">ACCEPT</span></pre>
</blockquote>
<p>And there we have it &#8211; if the packet matches the source, destination and service, the packet mark will be <strong><span style="color: #008000;">0xE</span></strong>. If, say, it matches everything except the destination, it&#8217;ll come out as <strong><span style="color: #008000;">0xC</span></strong>, which won&#8217;t match and so netfilter will carry on along the rest of the rules. If you want processing to stop here, you could always add a <strong>LOG</strong> and <strong>REJECT</strong>/<strong>DROP</strong> target at the end of the <strong><span style="color: #000080;">R-ALLOW-DMZ-MGMT</span></strong> chain.</p>
<h3>Negation</h3>
<p>Sometimes we want to be able to say &#8216;everything but that particular network&#8217;, whether it be for accepting or dropping packets. We can do that with this, too</p>
<blockquote>
<pre># Add a new chain for negating the source
iptables -N <span style="color: #000080;">S-NEGATE</span>
# XOR the current packet mark with <strong><span style="color: #008000;">0x8</span></strong> - our 'source match' identifier
iptables -A <span style="color: #000080;">S-NEGATE</span> -j MARK --xor-mark <span style="color: #008000;">0x8</span></pre>
</blockquote>
<p>To use it, simply drop it in the <strong><span style="color: #000080;">R-ALLOW-DMZ-MGMT</span></strong> rule above after the jump to the <strong><span style="color: #000080;">S-TRUSTED</span></strong> chain, and if <span style="color: #000080;"><strong>S-TRUSTED</strong></span> matched, it won&#8217;t any more, and vice versa. To negate the destination and service matches, you&#8217;ll need to create similar chains for (for example) <strong><span style="color: #000080;">D-NEGATE</span></strong> and <strong><span style="color: #000080;">D-SRV-NEGATE</span></strong>, replacing the <strong><span style="color: #008000;">0&#215;8</span></strong> with <strong><span style="color: #008000;">0&#215;4</span></strong> and <strong><span style="color: #008000;">0&#215;2</span></strong> respectively.</p>
<h3>Things to note</h3>
<p>One downside of this method is that because of the way IPTables works, if you want to use the same set of networks and hosts as a source and a destination, you&#8217;ll need to duplicate them, but match on the source or destination as appropriate. Using the example given above, if we wanted a group with the same entries as <strong><span style="color: #000080;">S-TRUSTED</span></strong>, but matching on traffic going to them, we&#8217;d need to create another group (for example, <strong><span style="color: #000080;">D-TRUSTED</span></strong>), which will be identical save for the IP matches (which will need changing to <strong>-d</strong>) and the mask (which will need setting to <strong><span style="color: #008000;">0&#215;4</span></strong> instead of <strong><span style="color: #008000;">0&#215;8</span></strong>).</p>
<p>Also, be careful if you&#8217;re using packet marks to do something outside of netfilter (say, for <a href="http://lartc.org/">traffic control</a> &#8211; which I&#8217;ll cover in a future post). One way round this is the facility to save the current packet mark to the current connection mark, or vice versa &#8211; if you go down this path then having a look at the iptables manpage for the MARK and CONNMARK targets will be useful.</p>
<h3>Conclusions</h3>
<p>This is an effective way of grouping hosts, networks and services within IPTables. It can be quite a bit of work to start with to add all the groups, but once in place it makes writing rules a lot more logical.</p>
<h3>Taking things further</h3>
<p>One way which you could take this further would be to group interfaces together in a similar fashion, say by adding <strong><span style="color: #008000;">0&#215;10</span></strong> to the packet, and then matching on <strong><span style="color: #008000;">0x1E</span></strong> rather than <strong><span style="color: #008000;">0xE</span></strong>.</p>
<p>Usefully, if you send the packet out to syslog with the <strong><span style="color: #000080;">LOG</span></strong> target, netfilter will print out the current packet mark at the end of the log message as <strong><span style="color: #ff0000;">MARK=0xN</span></strong>, which can be useful when debugging.</p>
]]></content:encoded>
			<wfw:commentRss>http://andys.org.uk/bits/2010/01/27/iptables-fun-with-mark/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

