Subversion hosting, CVS hosting, Trac hosting, Bugzilla hosting and software collaboration Providing hosted Subversion, CVS, Trac and Bugzilla repositories
 

January 31, 2008

Apache Auto-configuration with a Dynamic IP Address

Filed under: Operating Systems — Tags: , , — Greg Larkin @ 6:02 pm

Hi everyone,

As I was setting up the new FreeBSD 6.2 VM with Apache 2.2 preinstalled in it, I ran into a problem. The VM’s virtual Ethernet adapter is configured for DHCP, and the VMware software acts as a DHCP server to hand out IP addresses as VMs are started.

The problem is that Apache likes to know the IP address of the machine it’s running on, and in some cases, it won’t start unless it does. Luckily, the DHCP client in FreeBSD, and likely other operating systems, calls separate hook scripts (if they exist) before and after configuring the adapter with a dynamic address.

In my case, I wanted to automatically create a ServerName directive for Apache with the dynamic address. The default Apache 2.2 installation on FreeBSD provides a user configuration file include directory at /usr/local/etc/apache22/Includes. As it starts up, Apache loads any file placed in that directory and named with the “.conf” suffix. I think we’ve got a solution!

It’s also necessary to tweak the contents of the /etc/hosts file so that the VM can resolve its own hostname. I wrote a DHCP client exit hook script that configures both Apache and the /etc/hosts file. This script should be easily adaptable to other operating systems, as it uses the standard Bourne shell syntax.

Simply download the script, unzip the contents into /etc, and let me know what you think!


Call me - Greg Larkin: error

Powered by WordPress