Administrative

Projects

Active

Future

Finished

Reference

Abandoned

Automatic LAN configuration on FreeBSD

I wanted my notebook (running FreeBSD) to connect to the Internet automatically when booting, if a network is available.

Note that this script has been rewritten quite some time ago to be more flexible when moving to other hardware, and to support more choices when configuring manually. I just have to update the documentation...

As the Internet might be reachable through several ways (e.g. the builtin Fast Ethernet interface, the builtin WLAN card, a USB dongle providing Bluetooth access to the GPRS-enabled mobile phone), the connection mechanism must be able to find the right transport to use and then do the right things to connect.

I also want to be able to boot up without any networking support, and then manually start a connection - which comes handy when being "in the wild" and wanting to start up a short networked session over the mobile phone.

The scripts I have hacked for this purpose work like this at boot time:

When called manually, the script can also do some more things:

The main script is lan.sh, which is called without arguments at boot time (through a start script in /usr/local/etc/rc.d/. If this chooses to start a connection over the Fast Ethernet line (in my case, it's an re0 interface), it also starts a watcher script, [re0watch]{attach}images/re0watch), which checks for an IP after three minutes and, if none is there, stops the DHCP client again to save resources and keep the log clean.

When using this script, it is important that no network interfaces are configured in /etc/rc.conf for setup at boot time, as this would break the housekeeping done by this script. Keeping and verifying state (as in dhclient running or not, which interface is being used right now) is a thing that could be improved in lan.sh anyways, maybe I will put some more time into this one day. In the meantime, you may want to use this script as a starting point.

This script works hand in hand with some network profiling system (doing things like automatic SOCKS proxy configuration when needed, for example). To make this work, and use features like NTP, I also use dhclient's enter- and exit-hooks - which in turn call some other scripts. mailaway and lpdaway might be starting points for further own scripting.

Logbook