<?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</title>
	<atom:link href="http://andys.org.uk/bits/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>Thu, 11 Mar 2010 13:29:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Streetview in the UK&#8230; updated!</title>
		<link>http://andys.org.uk/bits/2010/03/11/google-streetview-in-the-uk-updated/</link>
		<comments>http://andys.org.uk/bits/2010/03/11/google-streetview-in-the-uk-updated/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 13:28:46 +0000</pubDate>
		<dc:creator>Andy Smith</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[streetview]]></category>

		<guid isPermaLink="false">http://andys.org.uk/bits/?p=72</guid>
		<description><![CDATA[<p>So the little birdies were correct &#8211; Google have just updated Streetview for the UK. They&#8217;ve spent the last year or so photographing the length and breadth of the country, and now it&#8217;s all there to see, including such wonders as this blurry-faced chap:-</p>
<p></p>
<p>Yeah, that&#8217;s me, on my way out to work. I&#8217;ll ignore any [...]]]></description>
			<content:encoded><![CDATA[<p>So the little birdies were correct &#8211; Google have just updated Streetview for the UK. They&#8217;ve spent the last year or so photographing the length and breadth of the country, and now it&#8217;s all there to see, including such wonders as this blurry-faced chap:-</p>
<p><a href="http://maps.google.co.uk/maps?f=q&#038;source=s_q&#038;hl=en&#038;geocode=&#038;q=dn7+5hd&#038;sll=53.518804,-1.167422&#038;sspn=0.008586,0.01929&#038;ie=UTF8&#038;hq=&#038;hnear=Doncaster+DN7+5HD,+United+Kingdom&#038;ll=53.593766,-1.022694&#038;spn=0.00852,0.01929&#038;z=16&#038;layer=c&#038;cbll=53.593847,-1.022695&#038;panoid=Svai1LMmNEUAsYv4d8IQKg&#038;cbp=12,27.13,,0,18.31"><img class="aligncenter size-full wp-image-73" title="Google_Streetview_Bootham" src="http://andys.org.uk/bits/wp-content/uploads/2010/03/Clipboard01.jpg" alt="" width="631" height="471" /></a></p>
<p>Yeah, that&#8217;s me, on my way out to work. I&#8217;ll ignore any comments about my shirt&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://andys.org.uk/bits/2010/03/11/google-streetview-in-the-uk-updated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iproute2: Life after ifconfig</title>
		<link>http://andys.org.uk/bits/2010/02/24/iproute2-life-after-ifconfig/</link>
		<comments>http://andys.org.uk/bits/2010/02/24/iproute2-life-after-ifconfig/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 23:57:17 +0000</pubDate>
		<dc:creator>Andy Smith</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[ifconfig]]></category>
		<category><![CDATA[iproute2]]></category>

		<guid isPermaLink="false">http://andys.org.uk/bits/?p=56</guid>
		<description><![CDATA[<p>The standard network tools ifconfig, netstat and route will be familiar to anyone with more than a passing interest in UNIX or any of its derivations. Linux is no exception, and if you hop on to your nearest Linux machine, you&#8217;ll find these installed. However, for the past few years ifconfig and its ilk (often [...]]]></description>
			<content:encoded><![CDATA[<p>The standard network tools <em>ifconfig</em>, <em>netstat </em>and <em>route </em>will be familiar to anyone with more than a passing interest in UNIX or any of its derivations. Linux is no exception, and if you hop on to your nearest Linux machine, you&#8217;ll find these installed. However, for the past few years ifconfig and its ilk (often collectively referred to as <em>net-tools</em>) <a href="http://en.wikipedia.org/wiki/Ifconfig#Current_status">have been deprecated</a> in favour of the <strong>iproute2</strong> suite.</p>
<p><span id="more-56"></span>iproute2 is a suite of tools developed to unify the functions provided by the traditional tools in one place under the <code><strong>ip</strong></code> command. Interface configuration, routing and tunnelling can now all be configured and managed using the ip command.</p>
<h3>Interface configuration</h3>
<p>Historically, interfaces are managed using the <a href="http://en.wikipedia.org/wiki/Ifconfig">ifconfig</a> command, and to get an overview of the interfaces you&#8217;d type <code>ifconfig -a</code>. With iproute2, interfaces addressing is managed through the address subcommand &#8211; which, like the rest of the subcommands for iproute2 can be shortened Cisco IOS-style, as long as it&#8217;s unique. In theory this means you can use <code>ip a</code>, but the manual page refers to it as <code>ip addr</code>, which I&#8217;ll use here for clarity. So, the equivalent of <code>ifconfig -a</code> is the self-explanatory <code>ip addr show</code>, which if we&#8217;re not specifying a specific interface can be shortened to simply <code>ip addr</code>:-</p>
<blockquote>
<pre>[root@example ~]# <strong>ip addr</strong>
1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc
      pfifo_fast state DOWN qlen 1000
    link/ether 00:d0:b7:2d:ce:cf brd ff:ff:ff:ff:ff:ff
    inet 192.0.2.1/24 brd 192.0.2.255 scope global eth0</pre>
</blockquote>
<p>Most of this should be self-explanatory, and everything you would see with <code>ifconfig -a</code> you&#8217;ll see with <code>ip addr</code>.</p>
<p>Bringing up <strong>eth0</strong> on a Linux box would usually consist of doing the following:-</p>
<blockquote>
<pre>[root@example ~]# <strong>ifconfig eth0 up</strong>
[root@example ~]# <strong>ifconfig eth0 192.0.2.1 netmask 255.255.255.0</strong></pre>
</blockquote>
<p>With iproute2, control of interfaces themselves &#8211; both physical and logical &#8211; is through the <strong>link</strong> subcommand. Bringing up eth0 can be done with:-</p>
<pre>
<blockquote>
<pre>[root@example ~]# <strong>ip link set eth0 up</strong></pre>
</blockquote>
</pre>
<p>Managing the addresses on an interface is through the aforementioned addr subcommand, so using our example again, we&#8217;d do something like this to add an IP to eth0:-</p>
<pre>
<blockquote>
<pre>[root@example ~]# <strong>ip addr add 192.0.2.1/24 dev eth0</strong></pre>
</blockquote>
</pre>
<p>I&#8217;ve used CIDR notation in this example, but you can use the normal dotted quad format for the netmask if you wish.</p>
<p>This also makes adding multiple IP addresses to interfaces really easy. To add <strong>192.0.2.2</strong> to our example eth0 interface, you&#8217;d just do:-</p>
<pre>
<pre>
<blockquote>
<pre>[root@example ~]# <strong>ip addr add 192.0.2.2/24 dev eth0</strong></pre>
</blockquote>
</pre>
</pre>
<p>Showing the addresses on our eth0 interface only will show that both the addresses are now there:-</p>
<blockquote>
<pre>[root@example ~]# <strong>ip addr show dev eth0</strong>
2: eth1: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc
      pfifo_fast state DOWN qlen 1000
    link/ether 00:d0:b7:2d:ce:cf brd ff:ff:ff:ff:ff:ff
    inet 192.0.2.1/24 brd 192.0.2.255 scope global eth1
    inet 192.0.2.2/24 scope global secondary eth1
</pre>
</blockquote>
<p>Removing an IP from an interface is also straightforward:-</p>
<blockquote>
<pre>[root@example ~#] <strong>ip addr del 192.0.2.2/24 dev eth0</strong>
</pre>
</blockquote>
<p>Querying the interface again shows that 192.0.2.2 is no longer assigned to eth0:-</p>
<blockquote>
<pre>[root@example ~]# <strong>ip addr show dev eth0</strong>
2: eth1: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc
      pfifo_fast state DOWN qlen 1000
    link/ether 00:d0:b7:2d:ce:cf brd ff:ff:ff:ff:ff:ff
    inet 192.0.2.1/24 brd 192.0.2.255 scope global eth1</pre>
</blockquote>
<h3>Routing</h3>
<p>Using <code>netstat -rn</code> is pretty much burned into the brains of most UNIX engineers, but luckily the iproute2 method is just as snappy. Routing management is handled with the <strong>route</strong> subcommand, and in line with <strong>addr</strong> and <strong>link</strong>, it can be shortened &#8211; <code>ip r</code> will work, but I usually settle for <code>ip ro</code>. The full command for showing the routing table is <code>ip route show</code>, but as with <code>ip addr</code> you can drop the <strong>show</strong> if you want to show the entire routing table:-</p>
<blockquote>
<pre>[root@example ~]# <strong>ip ro</strong>
192.0.2.0/24 dev eth0  proto kernel  scope link  src 192.0.2.1
default via 192.0.2.254 dev eth0
</pre>
</blockquote>
<p>Adding and removing routes is accomplished with <code>ip ro add</code> and <code>ip ro del</code> respectively:-</p>
<blockquote>
<pre>[root@example ~]# <strong>ip ro add 10.0.0.0/16 via 192.0.2.253</strong>
[root@example ~]# <strong>ip ro del 10.0.0.0/16 via 192.0.2.253</strong></pre>
</blockquote>
<p>One useful feature of <code>ip route</code> is the <strong>get</strong> function, which we can use to query the routing table for a particular network or address. In our example, querying for an address not on our local network shows that the route to it goes via our default gateway:-</p>
<blockquote>
<pre>[root@example ~]# <strong>ip ro get 1.2.3.4</strong>
1.2.3.4 via 192.0.2.254 dev eth0  src 192.0.2.1
    cache  mtu 1500 advmss 1460 hoplimit 64</pre>
</blockquote>
<h3>Neighbours</h3>
<p><code>arp -na</code> is the traditional way you&#8217;d query the ARP table on a UNIX machine. You can accomplish this with iproute2 using <code>ip neighbor</code> (or <code>ip neighbour</code> for us not from the US), with <code>ip n</code> being the shortened extreme:-</p>
<blockquote>
<pre>[root@example ~]# <strong>ip neigh</strong>
192.0.2.3 dev eth0 lladdr 00:02:a5:1f:cb:2d REACHABLE
192.0.2.254 dev eth0 lladdr 00:09:43:bc:aa:80 REACHABLE
</pre>
</blockquote>
<p>I&#8217;ll skip the example for this, but needless to say you can add and remove entries with <code>ip neigh add</code> and <code>ip neigh del</code> respectively.</p>
<h3>A little helping hand</h3>
<p>If you&#8217;re stuck, then the help argument can come in handy. If you specify help as an argument to ip itself, or to one of the subcommands, it&#8217;ll give you a quick overview of the options available. For example, for <strong>ip neighbor</strong>:-</p>
<blockquote>
<pre>[root@example ~]# <strong>ip neigh help</strong>
Usage: ip neigh { add | del | change | replace } { ADDR [ lladdr
          LLADDR ] [ nud { permanent | noarp | stale |
          reachable } ] | proxy ADDR } [ dev DEV ]
       ip neigh {show|flush} [ to PREFIX ] [ dev DEV ] [ nud STATE ]</pre>
</blockquote>
<h3>Not forgetting IPv6&#8230;</h3>
<p>I&#8217;ve purposely neglected to show any configuration of IPv6 addresses in this post, not because iproute2 can&#8217;t handle it, but for the exact opposite reason &#8211; the iproute2 suite will handle IPv6 addresses in exactly the same way as IPv4 addresses. All the commands used above can be used for both IPv4 and IPv6 configuration without any issues.</p>
<p>If there&#8217;s a reason you want to force the behaviour one way or the other, you can use the <code>-4</code> and <code>-6</code> switches. This isn&#8217;t needed normally, because when adding or removing an address, for example, iproute2 will happily recognise an IPv6 address instead of an IPv4 one. Where it does come in useful is if you want to limit the data returned in a query to just IPv6, or just IPv4. A real-world example of this is on one of my Linux machines, where ip -6 ro shows:-</p>
<blockquote>
<pre>[root@daedalus ~]# <strong>ip -6 ro</strong>
2001:470:XXXX:1::/64 dev eth0  proto kernel  metric 256  mtu 1500
  advmss 1440 hoplimit 0
fe80::/64 dev eth0  proto kernel  metric 256  mtu 1500 advmss 1440
  hoplimit 0
default via 2001:470:XXXX:1::1 dev eth0  metric 1  mtu 1500 advmss
  1440 hoplimit 0
</pre>
</blockquote>
<p>&#8230;which comes in handy if you&#8217;re only interested in the IPv6 routing table.</p>
<h3>What next?</h3>
<p>This post only really scratches the surface of iproute2 &#8211; I&#8217;ve just covered the iproute2 equivalents of the most-used commands. It&#8217;s capable of much, much more, such as <a href="http://www.deepspace6.net/docs/iproute2tunnel-en.html">setting up tunnels</a>, managing <a href="http://linux-ip.net/html/routing-tables.html">multiple routing tables</a> and configuring interfaces for multicast to name a few. I&#8217;ll be covering some of these in more depth in future posts.</p>
<h3>Further reading</h3>
<ul>
<li>The <a href="http://lartc.org/howto/">Linux Advanced Routing &amp; Traffic Control HOWTO</a>, which is probably <em>the</em> definitive guide when it comes to iproute2</li>
<li><a href="http://en.wikipedia.org/wiki/Iproute2">iproute2 on Wikipedia</a></li>
<li>The Linux Foundation&#8217;s <a href="http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2">iproute2 page</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://andys.org.uk/bits/2010/02/24/iproute2-life-after-ifconfig/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Great White North</title>
		<link>http://andys.org.uk/bits/2010/02/22/the-great-white-north/</link>
		<comments>http://andys.org.uk/bits/2010/02/22/the-great-white-north/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 18:51:43 +0000</pubDate>
		<dc:creator>Andy Smith</dc:creator>
				<category><![CDATA[Canada]]></category>

		<guid isPermaLink="false">http://andys.org.uk/bits/?p=52</guid>
		<description><![CDATA[<p>Sometimes, people decide to do something big, something life-changing, something that will undoubtedly cause a huge amount of upheaval in their life.</p>
<p>I&#8217;m talking about emigration.</p>
<p>For varying reasons, over the past year, me and Bec (my good lady wife) have decided that our medium-to-long term plans are to attempt to emigrate to Canada. We&#8217;re under no [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes, people decide to do something big, something life-changing, something that will undoubtedly cause a huge amount of upheaval in their life.</p>
<p>I&#8217;m talking about emigration.</p>
<p><span id="more-52"></span>For varying reasons, over the past year, me and Bec (my good lady wife) have decided that our medium-to-long term plans are to attempt to emigrate to Canada. We&#8217;re under no illusions &#8211; we&#8217;re aware of the many pitfalls and problems that may or may not arise. It&#8217;s certainly not going to be a walk in the park.</p>
<h3>So why?</h3>
<p>Why indeed &#8211; and let me be honest from the outset: I&#8217;ve never ever been to Canada. This may strike <span style="text-decoration: line-through;">some</span> <span style="text-decoration: line-through;">many</span> most people as completely insane &#8211; why would we want to go somewhere we&#8217;ve never been? It&#8217;s a good question, and one I don&#8217;t really have an answer for, other than</p>
<ul>
<li>it looks nice</li>
<li>we want somewhere better for our son to grow up</li>
<li>it&#8217;s not here</li>
</ul>
<p>The last point is the one that I do get a bit of stick about &#8211; the grass isn&#8217;t always greener on the other side, etc. &#8211; and I accept that the area of the UK in which I live probably colours my judgement somewhat. I was born, brought up and still live in Doncaster, in South Yorkshire, but it&#8217;s not a place I want to bring up my son.</p>
<p>So why Canada? Well, why not? Many of its cities score highly on various quality-of-life surveys, but most of all &#8211; it&#8217;s somewhere different. It&#8217;s true that I could relocate to another part of the UK, but if I&#8217;m going to go to the effort of moving within the UK, I may as well go the whole nine yards.</p>
<h3>It&#8217;s not gonna be easy</h3>
<p>Difficult isn&#8217;t the word. In fact, before we even think of emigrating, I need to find a job.</p>
<p>I work in the IT industry, and my current role means I have to be highly skilled across a number of disciplines. However, I effectively left school at the age of 16, and this means I didn&#8217;t go to university. No university obviously means no degree, which instantly puts me at a disadvantage, because it means I can&#8217;t apply for Permanent Residency as a<a href="http://www.cic.gc.ca/English/information/applications/skilled.asp"> Federal Skilled Worker</a>.</p>
<p>This leaves me with only one real option, which is to find a job. This too isn&#8217;t straightforward, because:-</p>
<ul>
<li>it has to be a job that they can&#8217;t find a Canadian citizen for,</li>
<li>it requires the company to apply for an <a href="http://www.cic.gc.ca/ENGLISH/work/employers/lmo-basics.asp">LMO</a>,</li>
<li>the company has to be willing to be involved in the immigration process, and</li>
<li>I need a work permit</li>
</ul>
<p>This makes our chances &#8211; if I&#8217;m honest with myself &#8211; vanishingly small. I wasn&#8217;t kidding when I said this wasn&#8217;t going to be easy &#8211; and this is all before even considering the emigration part itself.</p>
<h3>The beginning</h3>
<p>So, this really marks the beginning of something which might never come to fruition rather than a concrete plan of action. It&#8217;s my line in the sand &#8211; my mark to say that this is where I started.</p>
<p>I&#8217;ve started the ball rolling by applying for a handful of jobs, and sending my resume to recruitment agencies. Bearing in mind that I&#8217;m at a disadvantage already, I don&#8217;t expect to move from this point any time soon. In the meantime, though, I&#8217;ll post bits and bobs as and when I have something to say about it.</p>
<p>Watch this space!</p>
]]></content:encoded>
			<wfw:commentRss>http://andys.org.uk/bits/2010/02/22/the-great-white-north/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fixing Likewise startup scripts on Debian Squeeze</title>
		<link>http://andys.org.uk/bits/2010/02/11/fixing-likewise-startup-scripts-on-debian-squeeze/</link>
		<comments>http://andys.org.uk/bits/2010/02/11/fixing-likewise-startup-scripts-on-debian-squeeze/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 00:13:35 +0000</pubDate>
		<dc:creator>Andy Smith</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[chkconfig]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[likewise]]></category>
		<category><![CDATA[squeeze]]></category>
		<category><![CDATA[startup]]></category>

		<guid isPermaLink="false">http://andys.org.uk/bits/?p=47</guid>
		<description><![CDATA[<p>Just a quick one, this&#8230;</p>
<p>If you install Likewise Open on Debian Squeeze, you may notice that it doesn&#8217;t start on boot-up. The reason is because the new dependency-based boot sequence doesn&#8217;t like the init scripts Likewise provides.</p>
<p>Luckily, it&#8217;s pretty easy to fix. First, make sure you have chkconfig installed (apt-get install chkconfig if not), change [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick one, this&#8230;</p>
<p>If you install <a href="http://www.likewise.com/">Likewise Open</a> on <a href="http://www.debian.org/releases/squeeze/">Debian Squeeze</a>, you may notice that it doesn&#8217;t start on boot-up. The reason is because the new dependency-based boot sequence doesn&#8217;t like the init scripts Likewise provides.</p>
<p>Luckily, it&#8217;s pretty easy to fix. First, make sure you have <a href="http://articles.techrepublic.com.com/5100-10878_11-5033660.html">chkconfig</a> installed (<code>apt-get install chkconfig</code> if not), change into your <code>/etc/init.d</code> directory and do this:-</p>
<blockquote>
<pre>for INIT in lsassd lwiod eventlogd dcerpcd netlogond lwregd srvsvcd; do \
   echo "Fixing '${INIT}'..."; \
   sed -i -e 's/^#LWI_STARTUP_TYPE_SUSE#/#/g' \
      -e 's/Default-Start: 3 5/Default-Start: 2 3 4 5/g' \
      -e 's/Default-Stop: 0 1 2 6/Default-Stop: 0 1 6/g' ${INIT}; \
done</pre>
<pre>for INIT in lsassd lwiod netlogond eventlogd dcerpcd; do \
   echo "Disabling ${INIT}..."; \
   chkconfig -d ${INIT}; \
done</pre>
<pre>for INIT in dcerpcd eventlogd netlogond lwiod lsassd; do \
   echo "Re-enabling ${INIT}..."; \
   chkconfig -a ${INIT}; \
done</pre>
</blockquote>
<p>This uncomments the SUSE parts of the init scripts, which chkconfig wants. It then calls chkconfig to first delete each entry, and then re-add it to make sure everything&#8217;s okay. Reboot, and you should have working domain authentication without having to manually start it up.</p>
]]></content:encoded>
			<wfw:commentRss>http://andys.org.uk/bits/2010/02/11/fixing-likewise-startup-scripts-on-debian-squeeze/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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[<p>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.</p>
<p>If you&#8217;re one of the lucky ones, your ISP might provide native IPv6 connectivity (like [...]]]></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;">
<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><span style="font-size: x-small;"> </span></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 dmz -s 2001:470:90d3:1::/64 -j ACCEPT
ip6tables -A FORWARD -i lan -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>0</slash:comments>
		</item>
		<item>
		<title>GnuPG &#8211; RSA key-pair mini-Howto with stronger digests</title>
		<link>http://andys.org.uk/bits/2010/02/02/gnupg-rsa-key-pair-mini-howto/</link>
		<comments>http://andys.org.uk/bits/2010/02/02/gnupg-rsa-key-pair-mini-howto/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 15:19:16 +0000</pubDate>
		<dc:creator>Andy Smith</dc:creator>
				<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[gnupg]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[stronger digests]]></category>

		<guid isPermaLink="false">http://andys.org.uk/bits/?p=29</guid>
		<description><![CDATA[<p>(Note: This was originally posted on my previous blog, but I&#8217;ve noticed that it&#8217;s being linked to, so I&#8217;ve reposted it here)</p>
<p>I&#8217;m not a mathematician (or a cryptographer) so I&#8217;m happy to take this post&#8217;s word for it about a recent attack against SHA-1 (short PDF here). The post goes into detail about changing the [...]]]></description>
			<content:encoded><![CDATA[<p><em>(<strong>Note</strong>: This was originally posted on my previous blog, but I&#8217;ve noticed that it&#8217;s being linked to, so I&#8217;ve reposted it here)</em></p>
<p>I&#8217;m not a mathematician (or a cryptographer) so I&#8217;m happy to take <a href="http://www.debian-administration.org/users/dkg/weblog/48">this post</a>&#8217;s word for it about a recent attack against <a href="http://en.wikipedia.org/wiki/SHA-1">SHA-1</a> (short PDF <a href="http://http://eurocrypt2009rump.cr.yp.to/837a0a8086fa6ca714249409ddfae43d.pdf">here</a>). The post goes into detail about changing the preferred digests on a key, and is well worth a read.</p>
<p>The post also talks about using 2048-bit RSA keys, instead of the DSA/Elgamal default (which has a maximum size of 1024 bits). It goes into detail about how to migrate to an RSA key &#8211; if you&#8217;re going to migrate, I definitely recommend reading it.</p>
<p>However, I thought it would be nice to write a (very) quick guide on generating RSA private keys with GnuPG, as there are a few extra steps involved &#8211; but nothing complicated!<br />
<span id="more-29"></span><br />
<h2>Preparation</h2>
<p>The first thing mentioned in the post on Debian Administration is to set a couple of GnuPG config options to ensure that any digests generated by you are using the stronger SHA256, rather than SHA-1. Doing this is simple:-</p>
<blockquote>
<pre>cat &gt;&gt;~/.gnupg/gpg.conf &lt;&lt;EOF
personal-digest-preferences SHA256
cert-digest-algo SHA256
EOF</pre>
</blockquote>
<p>We&#8217;re now ready to generate our key.</p>
<h2>Generate our first key</h2>
<p>To start with, start the key generation as normal:-</p>
<blockquote>
<pre>[andys@sirius ~]$ <strong>gpg --gen-key</strong>
Please select what kind of key you want:
   (1) DSA and Elgamal (default)
   (2) DSA (sign only)
   (5) RSA (sign only)</pre>
</blockquote>
<p>(1) is the default, and generates a DSA key with an Elgamal subkey for encrypting. But for our RSA key, we need to choose (5).</p>
<p>Next, we&#8217;re asked for our key length. This is between 1024 and 4096 bits. The default is 2048, but for mine I&#8217;ve chosen 4096. A good overview of keys and key sizes can be found on pgp.net <a href="http://www.pgp.net/pgpnet/pgp-faq/pgp-faq-keys.html#key-size">here</a>.</p>
<blockquote>
<pre>RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) <strong>4096</strong>
Requested keysize is 4096 bits</pre>
</blockquote>
<p>The next question is about how long you want the key to be valid. Again, this is personal preference, and in this instance I&#8217;ve chosen &#8216;0&#8242; for &#8216;never expires&#8217;:-</p>
<blockquote>
<pre>Please specify how long the key should be valid.
         0 = key does not expire
      &lt;n&gt;  = key expires in n days
      &lt;n&gt;w = key expires in n weeks
      &lt;n&gt;m = key expires in n months
      &lt;n&gt;y = key expires in n years
Key is valid for? (0) <strong>0</strong>
Key does not expire at all
Is this correct? (y/N) <strong>y</strong></pre>
</blockquote>
<p>Next up is your user ID, which consists of your name, e-mail address and a comment. I tend to leave the comment field blank, but it&#8217;s there if you want it:-</p>
<blockquote>
<pre>You need a user ID to identify your key; the software constructs the
user ID from the Real Name, Comment and E-mail Address in this form:
    "Heinrich Heine (Der Dichter) &lt;heinrichh@duesseldorf.de&gt;"

Real name: <strong>Andy Smith</strong>
E-mail address: <strong>andy.smith@netprojects.org.uk</strong>
Comment: <em><strong>[Return]</strong></em>
You selected this USER-ID:
    "Andy Smith &lt;andy.smith@netprojects.org.uk&gt;"</pre>
<pre>Change (N)ame, (C)omment, (E)-mail or (O)kay/(Q)uit?</pre>
</blockquote>
<p>Select &#8216;O&#8217; to continue.</p>
<blockquote>
<pre>You need a Passphrase to protect your secret key.</pre>
</blockquote>
<p>You&#8217;re now being prompted to set a passphrase on the key. This can be as strong or as weak as you like, but considering the importance of your private key it&#8217;s best to secure it with a strong passphrase.</p>
<p>After supplying a passphrase, the actual key will be generated. RSA keys require quite a bit of entropy (&#8216;randomness&#8217;), and you&#8217;ll probably get a warning like this:-</p>
<blockquote>
<pre>Not enough random bytes available.  Please do some other work to give
the OS a chance to collect more entropy!  (Need 284 more bytes)</pre>
</blockquote>
<p>A good way to generate entropy is to create lots of I/O traffic (keyboard, mouse, network, disk, etc.). I found using <code>cat(1)</code> on files and redirecting the output to <code>/dev/null</code> worked quite well, especially if you use a block device of some sort (for example, I did <code>cat /dev/sdb &gt;/dev/null</code>, where <code>/dev/sdb</code> was a 1GB USB key).</p>
<p>Eventually &#8211; hopefully after not too much of a wait &#8211; gpg will report that it has completed generating the key, and you&#8217;ll have output a bit like this:-</p>
<blockquote>
<pre>gpg: key A0E6B93E marked as ultimately trusted
public and secret key created and signed.</pre>
<pre>gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
pub   <span style="color: #ff0000;">4096R</span>/<span style="color: #ff0000;">A0E6B93E </span>2009-05-08
 Key fingerprint = B2C5 59E3 E685 757A 45CD  7760 5BF3 1276 A0E6 B93E
uid                  Andy Smith &lt;andy.smith@netprojects.org.uk&gt;</pre>
<pre><span style="color: #ff0000;">Note that this key cannot be used for encryption.  You may want to use
the command "--edit-key" to generate a subkey for this purpose.</span></pre>
</blockquote>
<p>The key ID is now given, which in this case is A0E6B93E. We can also see (on the line that starts with &#8216;pub&#8217;) that the key is 4096 bits in size, and is an RSA key (denoted by the &#8216;R&#8217;). Sharp-eyed readers may have noticed that the key ID is actually the last 8 bytes<sup>[1]</sup> of the key&#8217;s fingerprint &#8211; this is because the key ID is just a shorter way of expressing the key fingerprint, and in itself isn&#8217;t guaranteed (or indeed intended) to be unique.</p>
<p>Also important is the last two lines, which point out that our brand spanking new key can&#8217;t be used to encrypt anything just yet.</p>
<h2>Adding encryption</h2>
<p>So without further ado, let&#8217;s create a subkey that lets us do encryption with our key:-</p>
<blockquote>
<pre>[andys@sirius ~]$ <strong>gpg --edit-key A0E6B93E</strong>
&lt;...version information...&gt;</pre>
<pre>Secret key is available.

pub  4096R/A0E6B93E  created: 2009-05-08  expires: never
  usage: SC
 trust: ultimate      validity: ultimate
[ultimate] (1). Andy Smith &lt;andy.smith@netprojects.org.uk&gt;

Command&gt;</pre>
</blockquote>
<p>Unsuprisingly, &#8216;addkey&#8217; is the command we want to generate a subkey, so that&#8217;s what we&#8217;ll run. Upon hitting enter, you&#8217;ll be prompted for the passphrase you set on your key earlier. Once given, you&#8217;ll be presented with a menu like this:-</p>
<blockquote>
<pre>Please select what kind of key you want:
 (2) DSA (sign only)
 (4) Elgamal (encrypt only)
 (5) RSA (sign only)
 (6) RSA (encrypt only)
Your selection?</pre>
</blockquote>
<p>Since it&#8217;s to complement our existing RSA key &#8211; which can already be used for signing &#8211; (6) is the option we want. Picking it brings us to a familiar prompt, wherein we&#8217;re asked for a key size:-</p>
<blockquote>
<pre>RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) <strong>4096</strong></pre>
</blockquote>
<p>The subkey&#8217;s size doesn&#8217;t have to match that of the parent key, but in this case I&#8217;ve gone for the same size, so 4096 it is. After picking a size, you&#8217;ll again be asked how long you want the key to be valid for. I&#8217;ve gone for 0 again, but again it doesn&#8217;t have to match that of the parent key. There is a slight difference, in that you&#8217;ll be prompted twice, just to make sure that you want to create the subkey:-</p>
<blockquote>
<pre>Really create? (y/N) <strong>y</strong></pre>
</blockquote>
<p>Now it&#8217;s time once more to play the entropy game. Use whatever you found worked for you earlier, and eventually you&#8217;ll see something like this:-</p>
<blockquote>
<pre>pub  4096R/A0E6B93E  created: 2009-05-08  expires: never
  usage: SC
                     trust: ultimate      validity: ultimate
sub  4096R/5D0CCD64  created: 2009-05-08  expires: never
  usage: E
[ultimate] (1). Andy Smith &lt;andy.smith@netprojects.org.uk&gt;</pre>
</blockquote>
<p>As you can see, I now have a subkey with a fingerprint ending in 5D0CCD64, which can be used for encryption &#8211; denoted by the &#8216;E&#8217; at the end of the line. Also noted is that the key is &#8216;ultimately trusted&#8217; by me, because it&#8217;s been added as a subkey to my key.</p>
<h2>Changing the digest settings</h2>
<p>As per the post linked to at the beginning, we can change the digest (or &#8216;hash&#8217;) that we prefer to receive signed data in. Without going into too much detail (you should read the post!), we can change these preferences:-</p>
<blockquote>
<pre class="terminal"><span class="input">Command&gt; <strong>setpref SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES
  CAST5 ZLIB BZIP2 ZIP Uncompressed</strong>
</span></pre>
</blockquote>
<p>Our preferences are confirmed back to us, and we&#8217;re asked to accept them:-</p>
<blockquote>
<pre class="terminal">Set preference list to:
     Cipher: AES256, AES192, AES, CAST5, 3DES
     Digest: SHA512, SHA384, SHA256, SHA224, SHA1
     Compression: ZLIB, BZIP2, ZIP, Uncompressed
     Features: MDC, Keyserver no-modify
Really update the preferences? (y/N) <strong><span class="input">y</span></strong></pre>
</blockquote>
<h2>Confirming our changes</h2>
<p>Since we&#8217;re now finished, we need to save the key to confirm our subkey:-</p>
<blockquote>
<pre>Command&gt; <strong>save</strong>
[andys@sirius ~]$ _</pre>
</blockquote>
<p>At this point, the key can now be used for signing and encryption. You can do other things, such as add a small photo to the key using the &#8216;addphoto&#8217; command, but two things you should do are to publish the key to a keyserver, and to generate a revocation certificate.</p>
<h2>Publishing your new key</h2>
<p>I won&#8217;t dwell too much on details, but in brief keyservers are exactly what they sound like &#8211; they serve keys out to users. Submitting your key to a keyserver allows other people to search for and download your public key from a keyserver. This saves you having to send a copy to everybody who wants it, for one.</p>
<p>Submitting is simple:-</p>
<blockquote>
<pre>[andys@sirius ~]$ <strong>gpg --keyserver keys.gnupg.net --send-key A0E6B93E</strong>
gpg: sending key A0E6B93E to hkp server keys.gnupg.net</pre>
</blockquote>
<p>Providing there are no errors, your key has been submitted to the keyserver at keys.gnupg.net.</p>
<h2>Revocation</h2>
<p>There&#8217;s a few reasons why you may no longer wish to use a key. It might have been compromised by a 3rd party, or it might simply be that you&#8217;ve forgotten the password. That&#8217;s why it&#8217;s <span style="text-decoration: line-through;">a good idea</span> imperative that you generate a revocation certificate <em>and store it somewhere safe and inaccessible to everyone but you!</em> A revocation certificate allows the holder of the certificate to revoke your key, and ideally the holder will be you and only you.</p>
<p>To generate a revocation certificate:-</p>
<blockquote>
<pre>[andys@sirius ~]$ <strong>gpg --gen-revoke A0E6B93E &gt;A0E6B93E-rev.asc</strong></pre>
</blockquote>
<p>This then gives us:-</p>
<blockquote>
<pre>sec  4096R/A0E6B93E 2009-05-08 Andy Smith &lt;andy.smith@netprojects.org.uk&gt;</pre>
<pre>Create a revocation certificate for this key? (y/N) <strong>y</strong></pre>
</blockquote>
<p>After answering in the affirmative, you&#8217;ll be prompted for a reason why you want to revoke the key. In my case, I&#8217;m going to choose (3), as the key was created for the purposes of this demonstration, but as you can see there are a number of other options to choose from:-</p>
<blockquote>
<pre>Please select the reason for the revocation:
  0 = No reason specified
  1 = Key has been compromised
  2 = Key is superseded
  3 = Key is no longer used
  Q = Cancel
(Probably you want to select 1 here)
Your decision? <strong>3</strong></pre>
</blockquote>
<p>You can now enter a description, which is fairly obvious:-</p>
<blockquote>
<pre>Enter an optional description; end it with an empty line:
&gt; <strong>Demonstration</strong>
&gt; <em><strong>[Return]</strong></em>
Reason for revocation: Key is no longer used
Demonstration</pre>
<pre>Is this okay? (y/N) <strong>y</strong></pre>
</blockquote>
<p>Answer yes, and you&#8217;ll again be prompted for your passphrase:-</p>
<blockquote>
<pre>You need a passphrase to unlock the secret key for
user: "Andy Smith &lt;andy.smith@netprojects.org.uk&gt;"
4096-bit RSA key, ID A0E6B93E, created 2009-05-08</pre>
<pre>ASCII armoured output forced.
Revocation certificate created.</pre>
<pre>Please move it to a medium which you can hide away; if Mallory gets
access to this certificate he can use it to make your key unusable.
It is smart to print this certificate and store it away, just in case
your media become unreadable.  But have some caution:  The print
system of your machine might store the data and make it available to
others!</pre>
</blockquote>
<p>At this point, you now have a revocation certificate in A0E6B93E-rev.asc. If you want to revoke this key now (which we do), then import it. It&#8217;s important to note that you <span style="text-decoration: underline;"><strong>don&#8217;t import the revocation certificate until you actually want to revoke the key</strong></span>. Anyway, here&#8217;s how:-</p>
<blockquote>
<pre>[andys@sirius ~]$ <strong>gpg --import &lt;A0E6B93E-rev.asc</strong></pre>
</blockquote>
<p>You won&#8217;t be asked to confirm this action, and you&#8217;ll immediately see the following:-</p>
<blockquote>
<pre>gpg: key A0E6B93E: "Andy Smith &lt;andy.smith@netprojects.org.uk&gt;" revocation certificate imported
gpg: Total number processed: 1
gpg:    new key revocations: 1
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u</pre>
</blockquote>
<p>This indicates that the key has now been revoked, which we can check by typing:-</p>
<blockquote>
<pre>[andys@sirius ~]$ <strong>gpg -k A0E6B93E</strong>
pub   4096R/A0E6B93E 2009-05-08 [revoked: 2009-05-08]
uid                  Andy Smith &lt;andy.smith@netprojects.org.uk&gt;</pre>
</blockquote>
<p>All that remains is for us to repeat the process we used earlier to submit our key to the keyserver, which this time will send the revoked version of the key:-</p>
<blockquote>
<pre>[andys@sirius ~]$ gpg --keyserver keys.gnupg.net --send-key A0E6B93E
gpg: sending key A0E6B93E to hkp server keys.gnupg.net</pre>
</blockquote>
<p>Our key will now appear to be revoked to anyone who looks for it.</p>
<h2>Summary</h2>
<p>That should just about cover the basics of generating an public/private RSA key pair with GnuPG. There&#8217;s a lot more that can be done with it, and having a good read about cryptography in general will help you get your head around some of the fruitier bits.</p>
<li> [1] &#8211; Thanks to Tero Pesonen who correctly pointed out that I&#8217;d originally put <em>8 <strong>bits</strong></em> when of course it&#8217;s the last <em>8 <strong>bytes</strong></em>. Cheers Tero!<br />
<h2>Further reading</h2>
<p>Thanks to <a href="http://www.fifthhorseman.net/">Daniel Kahn Gillmor</a> for his article &#8216;<a href="http://www.debian-administration.org/users/dkg/weblog/48">HOWTO prep for migration off of SHA-1 in OpenPGP</a>&#8216;, which details the digest steps above and was the inspiration for this article. Thanks also to Martin Krafft for his post &#8216;<span id="title"><a href="http://madduck.net/blog/2009.04.30:the-need-for-a-gpg-revocation-certificate/">The need for a GPG revocation certificate</a>&#8216;. </span></p>
<ul>
<li>The comp.security.pgp FAQ &#8211; <a href="http://www.pgp.net/pgpnet/pgp-faq/">http://www.pgp.net/pgpnet/pgp-faq/</a></li>
<li><a href="http://www.debian-administration.org/users/dkg/weblog/48">HOWTO prep for migration off of SHA-1 in OpenPGP</a> (Daniel Kahn Gillmor / Debian Administration)</li>
<li><span id="title"><a href="http://madduck.net/blog/2009.04.30:the-need-for-a-gpg-revocation-certificate/">The need for a GPG revocation certificate</a> (Martin Krafft)<br />
</span></li>
<li><a href="http://en.wikipedia.org/wiki/Pretty_Good_Privacy">Pretty Good Privacy</a> (Wikipedia)</li>
</ul>
</li>
]]></content:encoded>
			<wfw:commentRss>http://andys.org.uk/bits/2010/02/02/gnupg-rsa-key-pair-mini-howto/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Authenticating Active Directory users on Linux with Likewise Open</title>
		<link>http://andys.org.uk/bits/2010/01/28/likewise-open-and-linux/</link>
		<comments>http://andys.org.uk/bits/2010/01/28/likewise-open-and-linux/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 01:09:35 +0000</pubDate>
		<dc:creator>Andy Smith</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[UNIX]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[ad]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[likewise]]></category>
		<category><![CDATA[likewise open]]></category>

		<guid isPermaLink="false">http://andys.org.uk/bits/?p=20</guid>
		<description><![CDATA[<p>Historically, if you wanted to use Active Directory to authenticate users on a UNIX box, you were pretty much limited to using LDAP. This works fine for some people, but it&#8217;s not particularly elegant &#8211; especially if you&#8217;re having to create users home directories all the time, which negates some of the point of centralising [...]]]></description>
			<content:encoded><![CDATA[<p>Historically, if you wanted to use Active Directory to authenticate users on a UNIX box, you were pretty much limited to using <a href="http://www.openldap.org/lists/openldap-software/200010/msg00097.html">LDAP</a>. This works fine for some people, but it&#8217;s not particularly elegant &#8211; especially if you&#8217;re having to create users home directories all the time, which negates some of the point of centralising authentication to begin with.</p>
<p>I&#8217;m from a UNIX (mostly Linux) background, so I&#8217;m more at home using UNIX-alike platforms. That said, there&#8217;s a few things that Microsoft do that are particularly useful, and in my opinion AD is one of them (quiet at the back, there). Handily, there&#8217;s a project that can marry the two, and it goes by the name of <a href="http://www.likewise.com/">Likewise</a>.</p>
<p><span id="more-20"></span><a href="http://www.likewise.com/products/likewise_enterprise/index.php">Likewise Enterprise</a> is Likewise Software&#8217;s commercial offering, but they also provide an open-source edition in the form of <a href="http://www.likewise.com/products/likewise_open/index.php">Likewise Open</a>, which is what I&#8217;m going to focus on here. Conceptually, using Likewise is equivalent to binding a Windows machine to a domain, and the method of doing it is similar. The code is somewhat related to <a href="http://www.samba.org">Samba</a>, so some parts of it may be familiar to anyone who&#8217;s meddled around with Samba in any depth.</p>
<h3>Starting out</h3>
<p>First off, you&#8217;ll need the Likewise Open installer, which you can get from here (<a href="http://www.likewise.com/download/index.php">signup required</a>). Grab the installer for your particular distro or operating system &#8211; for this example I&#8217;m using a fresh Debian (lenny) GNU/Linux install, but the process is essentially the same for others, such as Solaris. One you&#8217;ve got it, installing it is just a matter of running it:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>chmod +x ./LikewiseIdentityServiceOpen-...-linux-i386-deb-installer</strong></span>
adtest:~# <span style="color: #008000;"><strong>./LikewiseIdentityServiceOpen-...-linux-i386-deb-installer</strong></span></pre>
</blockquote>
<p>Follow the prompts, and after a few seconds you&#8217;ll be returned to a prompt. Assuming the install completed successfully, in the case of Debian (or Ubuntu), running &#8216;<em>dpkg -l | grep likewise</em>&#8216; will show a few new packages have been installed (for RedHat/CentOS, replace &#8216;<em>dpkg -l</em>&#8216; with &#8216;<em>rpm -qa</em>&#8216;).</p>
<p>Before going any further, make sure your resolvers are set up correctly, and that the local machine&#8217;s time is synchronised &#8211; either against an external NTP source, or one of the domain controllers. You can check that DNS resolution is working correctly by running:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>host test.example.com</strong></span></pre>
</blockquote>
<p>&#8230;and all being well, you&#8217;ll see something like this:-</p>
<blockquote>
<pre>test.example.com          A     10.1.1.1
test.example.com          A     10.1.2.1</pre>
</blockquote>
<p>If you&#8217;re okay so far, configuring the machine to use AD requires one command:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>/opt/likewise/bin/domainjoin-cli join test.example.com andys</strong></span></pre>
</blockquote>
<p>After a few seconds, providing the local machine can see the domain controllers, you should be prompted for your domain password. As when binding a Windows machine to a domain, the account you use must have the right privileges, which usually means that it&#8217;s in the Domain Admins group or similar. So:-</p>
<blockquote>
<pre>Joining to AD Domain:   test.example.com
With Computer DNS Name: adtest.test.example.com

andys@TEST.EXAMPLE.COM's password: <span style="color: #008000;"><strong><em>&lt;domain password&gt;</em></strong></span></pre>
</blockquote>
<p>&#8230;wait a few seconds&#8230;</p>
<blockquote>
<pre>Warning: System restart required
Your system has been configured to authenticate to Active Directory
for the first time. It is recommended that you restart your system
to ensure that all applications recognize the new settings.

SUCCESS</pre>
</blockquote>
<p>Now, in my experience you don&#8217;t strictly need to reboot, however it&#8217;s a good idea to, so go ahead and reboot the machine.</p>
<h3>The basics</h3>
<p>Assuming the box rebooted, we can now test that AD integration is working. Log in, and at a prompt type:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>id TEST\\andys</strong></span></pre>
</blockquote>
<p>&#8230;replacing &#8216;<em>TEST\\andys</em>&#8216; with your domain and username. The double backslash is important, because most UNIX shells use &#8216;\&#8217; for escaping characters. If you want, you can also use the &#8216;<em>user@domain</em>&#8216; syntax. If all is well, you&#8217;ll see something like this:-</p>
<blockquote>
<pre>uid=2096628820(TEST\andys) gid=2096628225(TEST\domain^users)
groups=2096628225(TEST\domain^users),2096628224(TEST\domain^admins)</pre>
</blockquote>
<p>At this point I should offer a word of caution: Because the machine is now bound to the domain, it means users on the domain can log into it. Obviously this is the whole point, but it&#8217;s something to be mindful of, especially if the domain is used by many people.</p>
<p>The UIDs and GIDs may look ridiculously large, but don&#8217;t worry &#8211; UIDs under most UNIXen are 32-bit, so this will be fine. There&#8217;s also a good reason for it &#8211; Likewise guarantees that the IDs will be unique and consistent across all machines bound to the same domain. You&#8217;ll also notice that the user&#8217;s primary group is set to the primary group from AD, which is usually &#8216;<em>Domain Users</em>&#8216;.</p>
<p>The <em>domainjoin-cli</em> command also makes some changes to <strong>/etc/nsswitch.conf</strong> and the PAM configuration. On my example Debian box, having a peek at <strong>/etc/pam.d/common-auth</strong> reveals:-</p>
<blockquote>
<pre>auth    sufficient    /lib/security/pam_lsass.so
auth    required    pam_unix.so nullok_secure try_first_pass</pre>
</blockquote>
<p><strong>pam_lsass.so</strong> is the PAM shared library for the lsass &#8211; or <a href="http://en.wikipedia.org/wiki/Local_Security_Authority_Subsystem_Service">Local Security Authority Subsystem Service</a> &#8211; part of Likewise. The example above is simple enough, and accepts domain users, falling back to standard UNIX users if the given username isn&#8217;t a domain user.</p>
<h3>Making changes</h3>
<p>Likewise installs its configuration files in <strong>/etc/likewise</strong>. The one that&#8217;s probably of most interest is <strong>lsassd.conf</strong>, which controls how the lsass daemon <strong>lsassd</strong> handles users. Before going into any detail, you&#8217;ll notice that lsassd.conf is split into two sections &#8211; the first being for domain users (the <span style="color: #000080;">[auth provider:lsa-activedirectory-provider]</span> section), and the second being for &#8216;local&#8217; users (under <span style="color: #000080;">[auth provider:lsa-local-provider]</span>). The local users are usually just &#8216;<em>COMPUTER\Administrator</em>&#8216; and &#8216;<em>COMPUTER\Guest</em>&#8216; (where <em>COMPUTER</em> is the name of the local machine), and are synonymous to the <em>Administrator</em> and <em>Guest</em> accounts on Windows machines. Chances are you won&#8217;t need to touch the local users section, so we can safely ignore it.</p>
<p>There&#8217;s quite a few options to play with in lssasd.conf, but the main ones we&#8217;re interested in are:-</p>
<ul>
<li><strong>login-shell-template</strong>, which allows us to set the default shell for domain users. This is (by default) set to <strong>/bin/sh</strong>, so in many cases you might want to change it to <strong>/bin/bash</strong>.</li>
<li><strong>homedir-template</strong>, which specifies where domain users&#8217; home directories will be created. The default for this is <strong>%H/local/%D/%U</strong>, which in our example would expand to <strong>/home/local/TEST/andys</strong> for my account. Personally, I prefer to drop the &#8216;local&#8217; bit and use <strong>%H/%D/%U</strong>, which would change my home directory to <strong>/home/TEST/andys</strong>.</li>
<li><strong>require-membership-of</strong>, which lets us specify which groups are allowed to authenticate against this machine in a comma-separated list.</li>
</ul>
<p>It&#8217;s important to note that if you use the last option, <span style="color: #ff0000;"><span style="text-decoration: underline;">any domain user which isn&#8217;t a member of one of the specified groups will fail any PAM configuration that calls pam_lsass.so</span></span>.  This means that if you wanted to allow certains groups SSH access, whilst allowing a larger set of groups access to FTP, you don&#8217;t want to omit the FTP user groups from here. If you&#8217;re building this kind of setup, you&#8217;ll want to allow all the groups in lsassd.conf, and then build your PAM configuration to conditionally allow access based on group membership using <a href="http://www.kernel.org/pub/linux/libs/pam/Linux-PAM-html/sag-pam_group.html">pam_group</a>.</p>
<p>Once you&#8217;ve finished making your configuration changes, you&#8217;ll need to tell Likewise to reload the configuration:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>/opt/likewise/bin/lw-refresh-configuration</strong></span>
Configuration successfully loaded from disk.</pre>
</blockquote>
<p>It also doesn&#8217;t hurt (and I&#8217;ve sometimes found it neccessary) to clear the local AD cache:-</p>
<blockquote>
<pre>adtest:~# <span style="color: #008000;"><strong>/opt/likewise/bin/lw-ad-cache --delete-all</strong></span>
The cache has been emptied successfully.</pre>
</blockquote>
<p>&#8230;and that&#8217;s it! You should now have AD authentication working through PAM.</p>
<h3>Useful commands</h3>
<p>Likewise installs quite a few tools in <strong>/opt/likewise/bin</strong> (many of which are symlinks to <strong>lw-lsa</strong>), some of which come in handy for testing:-</p>
<ul>
<li><strong>lw-refresh-configuration</strong>, which as mentioned above reloads the <strong>lsassd</strong> configuration from <strong>lsassd.conf</strong>.</li>
<li><strong>lw-ad-cache</strong> (also partly mentioned above), which lets us manipulate the local AD cache. For example, <strong>lw-ad-cache &#8211;enum-users</strong> will list the users&#8217; details currently stored in the cache.</li>
<li><strong>lw-enum-users</strong>/<strong>lw-enum-groups</strong>, which predictably list all the users and groups in the domain.</li>
<li><strong>lw-get-status</strong>, which shows quite a bit of information about the domain itself.</li>
</ul>
<p>These are just a few, so it&#8217;s useful to have a poke about in <strong>/opt/likewise/bin</strong> and see what there is.</p>
<h3>Hints</h3>
<p>Because Likewise integrates itself via PAM, pretty much everything which can work with normal UNIX users can cope fine with domain users. For instance:-</p>
<ul>
<li>You can use the tilde (~) shortcut to go to a domain user&#8217;s home directory, for example <strong>cd ~andys@TEST</strong>. For some reason, the backslash notation doesn&#8217;t work here, and you may also notice that tab completion doesn&#8217;t work either.</li>
<li>With most things, you can refer to domain users as either <em>TEST\\andys</em>, <em>TEST.EXAMPLE.COM\\andys</em>, <em>andys@TEST</em> or <em>andys@TEST.EXAMPLE.COM</em>, including when logging in on the console or via SSH. There are exceptions (such as the previous point), but they&#8217;re few and far between.</li>
<li>Sudo happily works with domain groups &#8211; just remember to double-backslash.</li>
<li>You can use <strong>chown</strong> and <strong>chgrp</strong> in the ways you&#8217;d normally expect, using either the domain group names, or their GIDs.</li>
<li><strong><a href="http://www.suse.de/~agruen/acl/linux-acls/online/">ACLs</a></strong> (under Linux) also work, so if you&#8217;ve mounted a partition with the &#8216;<strong>acl</strong>&#8216; option, you can use <strong>setfacl</strong> as normal.</li>
</ul>
<h3>If it all goes wrong&#8230;</h3>
<p>Sometimes things go wrong. With Likewise, it&#8217;s usually straightforward. If you&#8217;re getting errors when binding to the domain with <strong>domainjoin-cli</strong>, it&#8217;s usually because it&#8217;s having problems connecting to the domain controller. If your domain controllers are on a different network, check that any firewalls inbetween aren&#8217;t dropping SMB traffic. The <strong>domainjoin-cli</strong> command should give you a definitive list of ports it needs open to communicate with the domain controller.</p>
<p>Once up and running, I&#8217;ve found Likewise Open to be very stable, but on the odd occasion that something has gone awry, it&#8217;s often enough to just restart the <strong>lsassd</strong> daemon. Failing that, try emptying the cache (with <strong>lw-ad-cache &#8211;delete-all</strong>). If you&#8217;re still getting odd errors, it might be worth checking out the <a href="http://www.likewise.com/resources/documentation_library/">documentation</a> or the <a href="http://www.likewise.com/community/index.php/forums/">forums</a>.</p>
<h3>Where to from here?</h3>
<p>Because the PAM magic happens with pam_lsass, in theory anything which uses PAM can be made AD-aware. I&#8217;ve personally used it with <a href="http://www.pureftpd.org">Pure-FTPd</a> to provide company-wide access to an fileserver, and it works flawlessly with <strong>gdm</strong>, so you can use it on your desktop. Again, because it&#8217;s PAM-based, it can be stacked with other modules such as <strong>pam_securid</strong> (for RSA&#8217;s SecurID tokens) or <a href="http://www.gsp.com/cgi-bin/man.cgi?section=8&amp;topic=pam_opie">pam_opie</a> (for one-time password sets).</p>
<p>Ironically, one thing that does require a little bit more configuration is Samba &#8211; something I&#8217;ll cover in a future post.</p>
<p><strong>Update</strong>: Yvo van Doorn <a href="http://andys.org.uk/bits/2010/01/28/likewise-open-and-linux/comment-page-1/#comment-30">comments below</a> with a handy hint if you only need access to one domain, which should save on keyboard wear for some users <img src='http://andys.org.uk/bits/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://andys.org.uk/bits/2010/01/28/likewise-open-and-linux/feed/</wfw:commentRss>
		<slash:comments>13</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[<p>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&#8217;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>&#8217;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;">0&#215;1E</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>0</slash:comments>
		</item>
		<item>
		<title>OpenSSH and OpenSC for Debian and Ubuntu</title>
		<link>http://andys.org.uk/bits/2009/12/23/openssh-and-opensc-for-debian-and-ubuntu/</link>
		<comments>http://andys.org.uk/bits/2009/12/23/openssh-and-opensc-for-debian-and-ubuntu/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 02:27:04 +0000</pubDate>
		<dc:creator>Andy Smith</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[key]]></category>
		<category><![CDATA[opensc]]></category>
		<category><![CDATA[pkcs]]></category>
		<category><![CDATA[rsa]]></category>
		<category><![CDATA[smartcard]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://andys.org.uk/bits/?p=8</guid>
		<description><![CDATA[<p>I&#8217;m using OpenSC at the moment so that I can repurpose an otherwise unused Aladdin eToken to hold SSH keys. I could go through the process involved in setting up the token, but as this chap has already done a thorough job, I won&#8217;t go into detail.</p>
<p>Unfortunately, the openssh-client package from Debian (and Ubuntu) doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using <a href="http://www.opensc.org/">OpenSC</a> at the moment so that I can repurpose an otherwise unused <a href="http://www.aladdin.com/etoken">Aladdin eToken</a> to hold SSH keys. I could go through the process involved in setting up the token, but as <a href="http://www.mayrhofer.eu.org/Default.aspx?pageid=78">this chap</a> has already done a thorough job, I won&#8217;t go into detail.</p>
<p>Unfortunately, the <em>openssh-client</em> package from Debian (and Ubuntu) doesn&#8217;t enable OpenSC support. It&#8217;s trivial to rebuild the package with OpenSC support, but for those who don&#8217;t want to or can&#8217;t for some reason, I&#8217;ve put my rebuilt, OpenSC-enabled packages <a href="http://andys.org.uk/debian/pool/main/o/openssh/">here</a>.</p>
<p>Once installed, if your token is set up correctly, you should be able to get your SSH public key from the card with:-</p>
<blockquote>
<pre>ssh-keygen -D &lt;card&gt;</pre>
</blockquote>
<p>&#8230;which should give you something like:-</p>
<blockquote>
<pre>ssh-rsa AAAA .. .. .. t8/Q==
1024 65537 14233 .. .. .. 70941</pre>
</blockquote>
<p>You can then add your private key to a running SSH agent with:-</p>
<blockquote>
<pre>ssh-add -s &lt;card&gt;</pre>
</blockquote>
<p>Pop in your PIN, and ssh should function as if you were using a normally-generated key.</p>
]]></content:encoded>
			<wfw:commentRss>http://andys.org.uk/bits/2009/12/23/openssh-and-opensc-for-debian-and-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IPTables::Log 0.0004 released</title>
		<link>http://andys.org.uk/bits/2009/12/22/iptableslog-0-0004-released/</link>
		<comments>http://andys.org.uk/bits/2009/12/22/iptableslog-0-0004-released/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 01:40:45 +0000</pubDate>
		<dc:creator>Andy Smith</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[cpan]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[iptables-log]]></category>
		<category><![CDATA[netfilter]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://andys.org.uk/bits/?p=3</guid>
		<description><![CDATA[<p>I released version 0.0004 of IPTables::Log early yesterday morning, which mostly consists of test fixes.</p>
<p>If you&#8217;re interested, have a look at the entry on CPAN.</p>
]]></description>
			<content:encoded><![CDATA[<p>I released version 0.0004 of <strong>IPTables::Log</strong> early yesterday morning, which mostly consists of test fixes.</p>
<p>If you&#8217;re interested, have a look at <a href="http://search.cpan.org/~meh/IPTables-Log-0.0004/">the entry on CPAN</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://andys.org.uk/bits/2009/12/22/iptableslog-0-0004-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
