<?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>Felipe Alfaro Solana &#187; DHCP</title>
	<atom:link href="http://www.felipe-alfaro.org/blog/category/dhcp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.felipe-alfaro.org/blog</link>
	<description>A little bit of technology, security and networking with Linux, FreeBSD and Mac OS X, plus some personal opinions.</description>
	<lastBuildDate>Sun, 23 Oct 2011 16:46:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>OpenBSD, dynamic and static IP address on the same interface</title>
		<link>http://www.felipe-alfaro.org/blog/2009/05/08/openbsd-dynamic-and-static-ip-address-on-the-same-interface/</link>
		<comments>http://www.felipe-alfaro.org/blog/2009/05/08/openbsd-dynamic-and-static-ip-address-on-the-same-interface/#comments</comments>
		<pubDate>Thu, 07 May 2009 22:25:14 +0000</pubDate>
		<dc:creator>Felipe Alfaro Solana</dc:creator>
				<category><![CDATA[DHCP]]></category>
		<category><![CDATA[OpenBSD]]></category>

		<guid isPermaLink="false">http://www.felipe-alfaro.org/blog/?p=301</guid>
		<description><![CDATA[Today I was faced with the following problem: I was trying to configure one of the Ethernet interfaces of an OpenBSD 4.5 box with both a dynamic address leased via DHCP, but also a static IP address. Initially, I tried this: # cat /etc/hostname.vr2 dhcp inet 1.1.1.11 255.255.255.0 NONE up # sh /etc/netstart vr2 The [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was faced with the following problem: I was trying to configure one of the Ethernet interfaces of an OpenBSD 4.5 box with both a dynamic address leased via DHCP, but also a static IP address. Initially, I tried this:</p>
<div>
<pre>
# cat /etc/hostname.vr2
dhcp
inet 1.1.1.11 255.255.255.0 NONE
up
# sh /etc/netstart vr2
</pre>
</div>
<p>The problem with this approach is that <code>dhclient</code> never gets daemonized because <code>netstart</code> gets it annoyed: <code>dhclient</code> notices that something else reconfigured the interface and commits suicide. So, then I thought about reversing the order of the first two lines:</p>
<div>
<pre>
# cat /etc/hostname.vr2
inet 1.1.1.11 255.255.255.0 NONE
dhcp
up
# sh /etc/netstart vr2
</pre>
</div>
<p>Now <code>dhclient</code> daemonizes but also removes all previously configured IP addresses, so the statically configured address configured via the first line is wiped by <code>dhclient</code>. Not very nice.</p>
<p>Turns out the solution lies in <code>/etc/dhclient.conf</code>:</p>
<div>
<pre>
# cat /etc/dhclient.conf
interface "vr2" {
        supersede domain-name "example.com";
        supersede domain-name-servers 1.1.1.1;
}

alias {
        interface "vr2";
        fixed-address 1.1.1.11;
        option subnet-mask 255.255.255.0;
}
</pre>
</div>
<p>The alias stanza allows one to define an additional, aliased IP address for an interface. Which allows the machine to be always reachable on a fixed IP address.</p>
<p>Neat.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.felipe-alfaro.org/blog/2009/05/08/openbsd-dynamic-and-static-ip-address-on-the-same-interface/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Configuring a diskless Ubuntu</title>
		<link>http://www.felipe-alfaro.org/blog/2007/12/09/configuring-a-diskless-ubuntu/</link>
		<comments>http://www.felipe-alfaro.org/blog/2007/12/09/configuring-a-diskless-ubuntu/#comments</comments>
		<pubDate>Sun, 09 Dec 2007 02:30:02 +0000</pubDate>
		<dc:creator>Felipe Alfaro Solana</dc:creator>
				<category><![CDATA[DHCP]]></category>
		<category><![CDATA[NFS]]></category>
		<category><![CDATA[PXE]]></category>
		<category><![CDATA[TFTP]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.felipe-alfaro.org/blog/2007/12/09/configuring-a-diskless-ubuntu/</guid>
		<description><![CDATA[This post is not about doing a PXE-based network installation of Ubuntu. There are already many posts describing how to do this. This post is about setting up an Ubuntu workstation in diskless mode, such as the workstation boots via PXE and the root filesystem is mounted over NFS. The process consists on the following [...]]]></description>
			<content:encoded><![CDATA[<p>This post is not about doing a PXE-based network installation of Ubuntu. There are already many posts describing how to do this. This post is about setting up an Ubuntu workstation in diskless mode, such as the workstation boots via PXE and the root filesystem is mounted over NFS.</p>
<p>The process consists on the following main steps:</p>
<ol>
<li>Setting up the DHCP server</li>
<li>Setting up the TFTP server and configuring PXE boot</li>
<li>Setting up the NFS server</li>
<li>Bootstrapping a Ubuntu installation into the client&#8217;s root filesystem</li>
<li>Booting up the diskless workstation</li>
</ol>
<h2>1. Setting up the DHCP server</h2>
<p>PXE-enabled workstations need to get an additional option during the DHCP negotiation that will point them to a TFTP server where the PXE-compatible boot loader code can be downloaded. Configuring <a href="http://www.thekelleys.org.uk/dnsmasq/doc.html"><code>dnsmasq</code></a> to hand this option to clients is just as easy as adding the following line to <code>/etc/dnsmasq.conf</code>:</p>
<div>
<pre>
dhcp-boot=pxelinux.0,tftp.lan,10.42.242.13
</pre>
</div>
<p>and restarting the <code>dnsmasq</code> service.</p>
<h2>2. Setting up the TFTP server and configuring PXE boot</h2>
<p>Now that DHCP has been configured, the next step is setting up the TFTP server. The TFTP server will be used by PXE-compatible clients to download the PXE boot loader code, and also the Linux kernel and Linux initial RAM disk.</p>
<p>I will use H. P. Anvin&#8217;s TFTP server as it&#8217;s widely used and works fairly well:</p>
<div>
<pre>
root@tftp.lan:# apt-get install tftpd-hpa
</pre>
</div>
<p><code>tftpd-hpa</code> does not integrate automatically with <code>xinetd</code> so if you want to run the TFTP server under <code>xinetd</code>, you will have to create the following file, which was ported from the <code>inetd</code> description that is created automatically in <code>/etc/inetd.conf</code> when <code>tftpd-hpa</code> is installed:</p>
<div>
<pre>
service tftp
{
        disable         = no
        id              = chargen-dgram
        socket_type     = dgram
        protocol        = udp
        user            = root
        wait            = yes
        server          = /usr/sbin/in.tftpd
        server_args     = -s /var/lib/tftpboot/
}
</pre>
</div>
<p>then restarting the <code>xinetd</code> service.</p>
<p>Configuring PXE boot is just a matter of copying the PXE boot loader code, a configuration file, the Linux kernel and initial RAM disks under the TFTP root. First, install <code>syslinux</code> and copy the PXE boot loader code to the TFTP server root:</p>
<div>
<pre>
root@tftp.lan:# apt-get install syslinux
root@tftp.lan:# cp /usr/lib/syslinux/pxelinux.0 /var/lib/tftpboot/
root@tftp.lan:# mkdir /var/lib/tftpboot/pxelinux.cfg
</pre>
</div>
<p>The Linux PXE boot loader code, <code>syslinux</code>, expects that a configuration file describing what kernel, its boot parameters, and the initial RAM disk to use to be stored within a directory named <code>pxelinux.cfg</code> just under the TFTP server root.</p>
<p>Client-specific config files can be created (based on the client MAC address, for example). We will create a config file that is suitable for any client. This configuration file is called <code>default</code> and can be created by running the following commands:</p>
<div>
<pre>
root@tftp.lan:# KERNEL_VERSION=2.6.22-14-generic
root@tftp.lan:# NFS_IPADDR=$(host nfs.lan | cut -d' ' -f4)
root@tftp.lan:# cat &gt; /var/lib/tftpboot/pxelinux.cfg/default &lt;&lt; EOF
> LABEL linux
> KERNEL vmlinuz-${KERNEL_VERSION}
> APPEND root=/dev/nfs initrd=initrd.img-${KERNEL_VERSION} nfsroot=${NFS_IPADDR}:/home/nfsroot ip=dhcp rw
> EOF
</pre>
</div>
<h2>3. Setting up the NFS server</h2>
<p>In this step, we will configure the NFS server and export the directory where the client&#8217;s root filesystem will be stored.</p>
<p>Let&#8217;s start by installing the NFS server packages:</p>
<div>
<pre>
root@nfs.lan:# apt-get install nfs-kernel-server nfs-common
</pre>
</div>
<p>I will use <code>/home/nfsroot</code> as the root for the client&#8217;s root filesystem</p>
<div>
<pre>
root@nfs.lan:# mkdir /home/nfsroot
</pre>
</div>
<p>Next, add the following line to <code>/etc/exports</code> in order to export the the client&#8217;s root filesystem:</p>
<div>
<pre>
/home/nfsroot *,gss/krb5(rw,no_subtree_check,async,no_root_squash)
</pre>
</div>
<p>Then re-export all the filesystems:</p>
<div>
<pre>
root@nfs.lan:# exportfs -avr
</pre>
</div>
<h2>4. Bootstrapping a Ubuntu installation into the client&#8217;s root filesystem</h2>
<p>The following steps will bootstrap the installation of a minimal Ubuntu Hardy Heron GNU/Linux system into the client&#8217;s root:</p>
<div>
<pre>
root@nfs.lan:# debootstrap --arch i386 hardy \
  /home/nfsroot http://ch.archive.ubuntu.com/ubuntu/
</pre>
</div>
<p>Only the minimum required packages will be downloaded from the Internet and installed into <code>/home/nfsroot</code>. The output of the previous command should look like this:</p>
<div>
<pre>
I: Retrieving Release
I: Retrieving Packages
I: Validating Packages
I: Resolving dependencies of required packages...
I: Resolving dependencies of base packages...
I: Found additional required dependencies: libdb4.6
I: Checking component main on http://ch.archive.ubuntu.com/ubuntu...
I: Retrieving adduser
I: Validating adduser
...
I: Base system installed successfully.
</pre>
</div>
<p>Once the system has been bootstrapped, we need to populate <code>fstab</code>. At least, <code>/proc</code> and <code>/</code> must get mounted, but other filesystems might be referenced in this file too, like additional NFS exports, swap files, and so on. The difference with respect a traditional, disk-based Ubuntu installation, is that the root filesystem gets mounted via NFS by the intial RAM disk, and is referenced by the kernel&#8217;s <code>/dev/nfs</code> block device.</p>
<p>The contents of <code>/home/nfsroot/etc/fstab</code> should look like this:</p>
<div>
<pre>
# /etc/fstab: static file system information.
#
# &lt;file system&gt; &lt;mount point&gt; &lt;type&gt; &lt;options&gt; &lt;dump&gt; &lt;pass&gt;
proc            /proc         proc   defaults       0      0
/dev/nfs        /             nfs    defaults       0      0
</pre>
</div>
<p>Another difference with a traditional Ubuntu system is that we don&#8217;t want the network interfaces be managed by Network Manager. In fact, the main (probably Ethernet) network interface was already configured by the kernel based on PXE&#8217;s supplied configuration. Letting Nework Manager reconfigure or manage this network interface might mean losing the connection to the NFS server and, thus, rendering the system unusable.</p>
<p>To stop Network Manager from managing the main network interface, the contents of <code>/home/nfsroot/etc/network/interfaces</code> must look like this:</p>
<div>
<pre>
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface, commented out for NFS root
iface eth0 inet manual
</pre>
</div>
<p>Finally, we will give the client a generic name. This can be done by storing that generic name into /etc/hostname:</p>
<div>
<pre>
root@nfs.lan:# echo client.lan &gt; /home/nfsroot/etc/hostname
</pre>
</div>
<h2>Booting up the diskless workstation</h2>
<p>Once everything is set up, the last thing to do is testing that the diskless workstation is able to boot via PXE. The mechanics of booting via PXE depend on the machine. On some machines, it&#8217;s just a matter of pressing ESC to get into a menu that allows to override the boot device. On others, the same can be done by pressing F12 during the POST. On most modern systems it&#8217;s possible to reconfigure the system to always boot from the network.</p>
<p>If the client is able to boot from PXE successfully, this is what you will briefly see on your screen:</p>
<div>
<pre>
CLIENT MAC ADDR: 00 11 22 33 44 55 66  GUID: 00000000 0000 0000 0000 000000000000
CLIENT IP: 192.168.0.2  MASK: 255.255.255.0  DHCP IP: 192.168.0.1
GATEWAY IP: 192.168.0.1

PXELNUX 3.36 Debian-2007-08-30  Copyright (C) 1994-2007 H. Peter Anvin
UNDI data segment at:   00094140
UNDI data segment size: 94B0
UNDI code segment at:   0009D5F0
UNDI code segment size: 20B0
PXE entry point found (we hope) at 9D5F:0106
My IP address seems to be C0A80001 192.168.0.2
ip=192.168.0.2:192.168.0.1:192.168.0.1:255.255.255.0
TFTP prefix:
Tring to load: pxelinux.cfg/00-01-02-03-04-05
Tring to load: pxelinux.cfg/C0A80001
Tring to load: pxelinux.cfg/C0A8000
Tring to load: pxelinux.cfg/C0A800
Tring to load: pxelinux.cfg/C0A80
Tring to load: pxelinux.cfg/C0A8
Tring to load: pxelinux.cfg/C0A
Tring to load: pxelinux.cfg/C0
Tring to load: pxelinux.cfg/C
Tring to load: pxelinux.cfg/default
boot:
Loading vmlinuz...
</pre>
</div>
<p>If the system boots up, we will be dropped into a text-mode console where we can log in as <code>root</code> with no password. Of course, the first thing you should do is creating a password for the <code>root</code> user, but if you have been able to get to this point, you probably know how to do it <img src='http://www.felipe-alfaro.org/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Once you are logged in as your in your new diskless workstation, you will probably want to add more functionality. For example, installing the <a href="http://www.openssh.org">OpenSSH</a> server, or the packages for the typical Ubuntu desktop system. Before you do that, we will need to add more Ubuntu repositories to <code>/etc/apt/sources.list</code>. This is how mine looks like:</p>
<div>
<pre>
deb http://ch.archive.ubuntu.com/ubuntu/ feisty main restricted
deb-src http://ch.archive.ubuntu.com/ubuntu/ feisty main restricted
deb http://ch.archive.ubuntu.com/ubuntu/ feisty-updates main restricted
deb-src http://ch.archive.ubuntu.com/ubuntu/ feisty-updates main restricted
deb http://ch.archive.ubuntu.com/ubuntu/ feisty universe
deb-src http://ch.archive.ubuntu.com/ubuntu/ feisty universe
deb http://ch.archive.ubuntu.com/ubuntu/ feisty multiverse
deb-src http://ch.archive.ubuntu.com/ubuntu/ feisty multiverse
deb http://ch.archive.ubuntu.com/ubuntu/ feisty-backports main restricted universe multiverse
deb-src http://ch.archive.ubuntu.com/ubuntu/ feisty-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu feisty-security main restricted
deb-src http://security.ubuntu.com/ubuntu feisty-security main restricted
deb http://security.ubuntu.com/ubuntu feisty-security universe
deb-src http://security.ubuntu.com/ubuntu feisty-security universe
deb http://security.ubuntu.com/ubuntu feisty-security multiverse
deb-src http://security.ubuntu.com/ubuntu feisty-security multiverse
</pre>
</div>
<p>Finally, I decided to install OpenSSH, OpenNTPD and the typical Ubuntu desktop:</p>
<div>
<pre>
root@client.lan:# apt-get update
root@client.lan:# apt-get install openssh-server openntpd ubuntu-desktop
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.felipe-alfaro.org/blog/2007/12/09/configuring-a-diskless-ubuntu/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Integrated DHCP and DNS services using OpenWRT</title>
		<link>http://www.felipe-alfaro.org/blog/2006/05/15/integrated-dhcp-and-dns-services-using-openwrt/</link>
		<comments>http://www.felipe-alfaro.org/blog/2006/05/15/integrated-dhcp-and-dns-services-using-openwrt/#comments</comments>
		<pubDate>Mon, 15 May 2006 10:40:22 +0000</pubDate>
		<dc:creator>Felipe Alfaro Solana</dc:creator>
				<category><![CDATA[DHCP]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[OpenWRT]]></category>

		<guid isPermaLink="false">http://felipe-alfaro.org/blog/2006/05/15/integrated-dhcp-and-dns-services-using-openwrt/</guid>
		<description><![CDATA[dnsmasq offers a lightweight, functional and integrated DHCP and DNS service. Using it on OpenWRT brings up and embedded, flexible DNS service, with a very small footprint, for small or home offices. dnsmasq acts as a caching DNS server and DHCP server. It reserves a DNS domain, called the local DNS domain and usually being [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://thekelleys.org.uk/dnsmasq/doc.html" title="dnsmasq">dnsmasq</a> offers a lightweight, functional and integrated DHCP and DNS service. Using it on OpenWRT brings up and embedded, flexible DNS service, with a very small footprint, for small or home offices.</p>
<p><em>dnsmasq</em> acts as a caching DNS server and DHCP server. It reserves a DNS domain, called the local DNS domain and usually being <code>.lan</code>, for local name resolution. When queried for an A RR inside the local DNS domain, <em>dnsmasq</em> looks at file <code>/etc/hosts</code> for a match. If one is found, its corresponding IP is returned as the query result. When queried for a PTR RR, it looks into file <code>/etc/hosts</code> for a match by IP and, if one is found, its correspoding hostname, qualified with the local DNS domain, is returned. Thus, <code>/etc/hosts</code> behaves much like a DNS master zone file.</p>
<p>Also, if the DHCP server funcionality of <em>dnsmasq</em> is enabled, when a query under the local DNS domain fails (no record is found in <code>/etc/hosts</code>), it will try to resolve the query from the DHCP lease database.</p>
<p>The DHCP lease database is usually stored at <code>/tmp/dhcp.leases</code>. Its format is pretty simple: it&#8217;s a text file, where each line represents an active DHCP lease. Each line is made up of five fields:</p>
<ol>
<li><b>Time of lease expiration</b>
<p>In epoch time (seconds since 1970). States when the lease will expire. Most DHCP clients will try to renew the lease when it reaches 80% of its valid lifetime.</li>
<li><b>Client MAC address</b>
<p>The MAC address corresponding to the client to which the lease belongs.</li>
<li><b>Leased IP address</b>
<p>A valid IP address, taken from the DHCP pool, which is actually and currently leased to the client whose MAC address is listed in the previous field.</li>
<li><b>Client hostname</b>
<p>If known, holds the unqualified host name of the client machine. Else, an asterisk is stored here.</li>
<li><b>Client ID</b>
<p>Simon Kelley defines it as:</p>
<blockquote><p>
The client-ID is used as the computer&#8217;s unique-ID in preference to the MAC address, if it&#8217;s available. Some DHCP clients provide it, and some don&#8217;t. The ones that do normally derive it from the MAC address unless explicity configured, but it could be something like a serial number, which would protect a computer from losing its identify if the network interface were replaced.
</p></blockquote>
<p>If not know, an asterisk is stored here.</li>
</ol>
<p>A sample DHCP database lease:</p>
<div>
<pre>
# cat /tmp/dhcp.leases
1147729862 00:16:3e:3b:56:f1 192.168.0.11 rhel *
1147725355 00:0c:29:09:3d:58 192.168.0.10 rhel-devel *
</pre>
</div>
<p>In this case, there are two active DHCP leases, one for client <code>rhel</code>, another one for <code>rhel-devel</code>.</p>
<p>OpenWRT uses a <em>rc.d</em> script stored at <code>/etc/init.d/S50dnsmasq</code><code> which, for a <em>squashfs</em> firmware is a symbolic link to </code><code>/rom/etc/init.d/S50dnsmasq</code>. This <em>rc.d</em> script tries to configure the <em>dnsmasq</em> daemon using NVRAM variables, which helps a lot when reflashing. However, I have found more convenient to the use the traditional <code>/etc/dnsmasq.conf</code> file instead.</p>
<p>Replacing the OpenWRT rc.d script with a custom one, in order to leverage <code>dnsmasq.conf</code>, is as simple as removing <code>/etc/init.d/S50dnsmasq</code> and invoking the <em>dnsmasq</em> daemon directly:</p>
<div>
<pre>
rm -f /etc/init.d/S50dnsmasq
cat > /etc/init.d/S50dnsmasq < < EOF
#/bin/sh
/usr/sbin/dnsmasq
EOF
</pre>
</pre>
</div>
<p>Here is a sample of a <code>/etc/dnsmasq.conf</code> file I use on my Linksys WRT54G router running OpenWRT White Russian RC5:</p>
<div>
<pre>
# filter what we send upstream
domain-needed
bogus-priv
filterwin2k
localise-queries

# allow /etc/hosts and dhcp lookups via *.lan
local=/lan/
domain=lan
expand-hosts

# enable dhcp (start,end,netmask,leasetime)
dhcp-authoritative
dhcp-range=10.0.0.10,10.0.0.100,255.255.255.128,12h
dhcp-leasefile=/tmp/dhcp.leases

# use /etc/ethers for static hosts; same format as --dhcp-host
# [hwaddr] [ipaddr]
read-ethers

# other useful options:
# default route(s): dhcp-option=3,192.168.1.1,192.168.1.2
#    dns server(s): dhcp-option=6,192.168.1.1,192.168.1.2
dhcp-option=3,10.0.0.126
dhcp-option=6,10.0.0.122
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.felipe-alfaro.org/blog/2006/05/15/integrated-dhcp-and-dns-services-using-openwrt/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

