define(`TITLE', `DHCP server on a MacBook')
define(`DATE', `2013-11-07')
define(`CONTENT', `
When working with the Arduino I almost have the Ethernet Shield attached or directly make use of the Arduino Ethernet board. Nearly everything I'`m playing around with is network-attached.

Once it is done, I connect it to my home network, where a DHCP server provides network configuration. But while developing software for the beast, it is on the table in front of me with no network cables around, my laptop is connected via WLAN. A while a was using a small Mikrotik 750 with only the DHCP server enabled to connect my MacBook Air via the USB adapter and the Arduino. The problem: so much stuff and more over, the DHCP server of the Mikrotik overwrites the default gateway of my home network. So the MacBook has access to the home network, but when accessing the Internet it tries to route via the Mikrotik, which has no Internet connection. Bad!

To solve this issue I considered to start a DHCP server on the MacBook, attaching it only to the USB network adapter. Since the related interface has no other connection, particularly hasn'`t received a network configuration from another DHCP server (the one in the home network has configured the WLAN interface), first an IP address has to be assigned to the interface.

Actually, Mac OS X comes with a DHCP server, which just needs some configuration:

/etc/bootptab (this is the MAC-address of the Arduino, just to know which IP address is assigned to it):
<pre>
%%
due     1       DE:AD:BE:EF:FE:ED   192.168.75.20
</pre>

/etc/bootpd.plist:
<pre>
&lt;!DOCTYPE plist PUBLIC &quot;-//Apple Computer//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;
&lt;plist version=&quot;1.0&quot;&gt;
  &lt;dict&gt;
    &lt;key&gt;bootp_enabled&lt;/key&gt;
    &lt;false/&gt;
    &lt;key&gt;dhcp_enabled&lt;/key&gt;
    &lt;array&gt;
       &lt;string&gt;en2&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;Subnets&lt;/key&gt;
    &lt;array&gt;
      &lt;dict&gt;
        &lt;key&gt;name&lt;/key&gt;
        &lt;string&gt;internal&lt;/string&gt;
        &lt;key&gt;net_mask&lt;/key&gt;
        &lt;string&gt;255.255.255.0&lt;/string&gt;
        &lt;key&gt;net_address&lt;/key&gt;
        &lt;string&gt;192.168.75.0&lt;/string&gt;
        &lt;key&gt;net_range&lt;/key&gt;
        &lt;array&gt;
          &lt;string&gt;192.168.75.20&lt;/string&gt;
          &lt;string&gt;192.168.75.29&lt;/string&gt;
        &lt;/array&gt;
        &lt;key&gt;allocate&lt;/key&gt;
        &lt;true/&gt;
      &lt;/dict&gt;
    &lt;/array&gt;
  &lt;/dict&gt;z
&lt;/plist&gt;
</pre>

And finally a small script to assign the address and start the server:
<pre>
#!/bin/sh

INTF=en2

ifconfig $INTF alias 192.168.75.1
/usr/libexec/bootpd -D -d -i $INTF
ifconfig $INTF -alias 192.168.75.1
</pre>

Done. 

Once the script is started, it assigns the IP address and starts the booted (the DHCP server). The server will not detach from the terminal and does not fork into background. So, it can simply be stopped using Ctrl-C. However, Ctrl-C also interrupts the script and the unassigning of the address is not executed. This unfortunately needs to be done manually.

Now I can connect the Adruino Ethernet directly to my MacBook and it will receive the network configuration from it.
')