Questions regarding dynamic IPs and dhcpcd
After successfully setting up dhcpcd to connect to a cable modem, I have a
few questions regarding dynamic ip addresses. First note that I have read
through the dynamic-ip-hacks mini-HOWTO, but am still a little confused.
Also, I will write up what ever information I find in a mini-HOWTO or a
debian note if it seems useable to others (which I think it would given
the explosion of cable modems).
I have set up debian 1.3 on a remote machine in Burlington that will
usually run Windows95 (parents machine - it will only run debian when I am
there or when I get someone to boot debian). My local permanent machine is
a static ip machine in Kingston. I would like to be able to call my
parents and have them boot debian (they know how to boot and shutdown, but
no more) and then have the machine automatically email me the dynamically
assigned ip address.
The dynamic-hacks mini-HOWTO really only deals with ppp. pppd outputs the
new ip address in $4. Is there anything similar to this for dhcpcd? I
can't find anything in the man page and I assume that I will need to
extract this from /etc/dhcpc/hostinfo-eth0.
Given this, after some experimentation, when I boot the remote machine (I
am in Burlington at the moment) it takes dhcpcd approximately 3 minutes to
configure the network and at that point /etc/dhcpc/hostinfo-eth0 is
updated and /var/run/dhcpcd-cache.eth0 is created. So I have to wait until
this happens to extract the ip address from /etc/dhcpc/hostinfo-eth0.
So what I want to do is write a script that waits until
/var/run/dhcpcd.cache-eth0 is created and then mails me
/etc/dhcpc/hostinfo-eth0. The waiting part is the part I do not know how
to do unless I just use an infinite loop (with perhaps a 10 minute limit)
that continously checks for /var/run/dhcpcd.cache-eth0. Is there a better
way to do this?
Ignoring correct syntax (i.e. a rough idea of the script - my bash book is
in my office), here's what I would like to try to do automatically from
time_now = (get time somehow)
while ( ! -f /var/run/dhcpcd.cache-eth0)
if (time_now+10 < (get time somehow))
file_exists = false
continue # i.e. keep looping until file exists or 10 minutes has past.
# if file is not created implying dhcpcd failed, then shutdown the machine
# but give long enough warning to stop in case someone who knows the root
# password (like me) is in Burlington and wants to use debian even though
# the net is down
if (file_exists == false)
shutdown -h 5 "Shutting down in 5 minutes. Cancel with shutdown -c"
mail -s "New IP address" firstname.lastname@example.org </etc/dhcpc/hostinfo-eth0
After that I would (on the local machine in Kingston) create a script that
pulls this message from my mail spool, uses host (from the dnsutils
package) to get the name, and updates /etc/hosts as in the
mini-HOWTO. However, one step at a time. All help is gratefully
Colin R. Telmer, Institute of Intergovernmental Relations
School of Policy Studies, Queen's University
Kingston, Ontario, Canada, K7L-3N6
PGP Fingerprint = 09 E9 DA 66 9C EE 33 DC B8 3B 97 0E 01 BC EC 0B
PGP Public Key at <URL:http://terrapin.econ.queensu.ca>
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
Trouble? e-mail to email@example.com .