<?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; Linux</title>
	<atom:link href="http://andys.org.uk/bits/tag/linux/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>Wed, 14 Jul 2010 10:34:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<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: 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 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: 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 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>1</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>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>14</slash:comments>
		</item>
	</channel>
</rss>
