<?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; ifconfig</title>
	<atom:link href="http://andys.org.uk/bits/tag/ifconfig/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>Mon, 16 Apr 2012 00:39:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</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[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>4</slash:comments>
		</item>
	</channel>
</rss>

