Occassionally, it's needed to keep a host in /etc/hosts
that periodically changes its IP address.
A remote server on a dynamic IP is an example.
The program is dependent on special format of /etc/hosts
entries. A line that has to be changeable
has to have the format
111.222.333.444 name1 name2 name3 ##AUTOSET:label
where the IP address and the number of spaces between it and the names has to be at least
15 characters total with trailing space (so the IP can be overwritten directly without having to
backup the file), the name1 name2 name3 are various possible "friendly" names for the IP address,
and the label is the name the IP is known by to the autohosts program.
The program is called with three parameters:
autohosts <filename> <IP.address> <label>
where filename
is usually /etc/hosts
, IP
is the new IP address
to be set there, and label
is the AUTOSET label in the /etc/hosts
file.
Basic check is performed on the IP address, so it shouldn't be possible to overwrite arbitrary entries in the hosts file by mistake or malice. There has to be no space between the ##AUTOSET: token, the label, and the end of line, for the match to be successful; the match is case-insensitive.
CAVEAT: It may be necessary to run the program as setuid, if it has to be called from non-root processes.
A host, immediately after connecting or reconnecting to the Net, may contact another host by a suitable mechanism (HTTP request, connection to xinetd, etc.). Some kind of authorization is strongly suggested, a SSL X.509 certificate sounds like a good idea here.