Canonical way for DHCP->IP->/etc/hosts
glarkin at FreeBSD.org
Mon Dec 15 14:04:11 PST 2008
-----BEGIN PGP SIGNED MESSAGE-----
Roger Olofsson wrote:
> Jeff Laine skrev:
>> On Sun, Dec 14, 2008 at 02:00:12PM +0100, Roger Olofsson wrote:
>>> Dear mailing list,
>>> I am sorry if this question has been asked over and over again -
>>> however the htdig search interface for the lists is somewhat shaky
>>> and gives referrer errors for me.
>>> Dualhomed firewalled FreeBSD7.1. One nic is LAN and the other
>>> dynamical IP from ISP.
>>> Question: What is the canonical way for catching the IP address from
>>> a DHCP assigned nic (from ISP that doesn't set hostname) and put the
>>> IP into /etc/hosts with a hostname?
>>> Reason for asking
>>> Firewall rules needs refreshing after new IP
>>> Possible answers:
>>> Create dhcp-exit-hooks (undocumented?) in /etc like so:
>>> if [ ! -z "$new_ip_address" ]; then
>>> IP=`ifconfig WAN | grep 'inet' | grep -v 'inet6' | cut -f 2 -d ' '`
>>> if [ ! -z "$IP" ]; then
>>> echo "$IP wan.local.domain wan" >> /etc/hosts
>>> <refresh firewall rules here>
>> Hello. I think pf can handle with dhcp updates on interfaces pretty well.
>> If only I get your question right.
> Hi Jeff and thank you for your reply,
> Yes, I know that pf will handle interfaces just fine, the question was
> not specific to pf though but more around dhclient, dhclient-script and
> the part of dhclient-script that calls the undocumented
> It might be handy to have the external IP assigned to a hostname - not
> only for pf.
I wrote a blog post about automatically configuring /etc/hosts with a
DHCP dynamic IP address earlier this year:
http://blog.sourcehosting.net/tag/dhcp/. You can download a ZIP file
with the dhclient-exit-hook script in it near the bottom of the page.
In my case, I also wrote some commands to update the Apache httpd.conf
file with the correct ServerName directive. You can easily remove that
from the script if you don't need it.
If you need any assistance, let me know.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-----END PGP SIGNATURE-----
More information about the freebsd-questions