On Wed, 7 Apr 1999, Graham Stoney wrote:
> Jeremy Impson writes:
> > /etc/HOSTNAME doesn't need to be writable (higly distribution dependent).
>
> It does if you're using DHCP to set the hostname, which is a Good Thing to do
> for autoconfiguring embedded boxes. Running a DHCP server is even worse,
Hmm. I am only familiar with dhcpcd 0.7, and I don't think it reads or
write /etc/HOSTNAME. It does optionally run a script (given to it with a
-c option). It gives some arguments to the script, one of which is the
leased IP address. You could just do something like this and put it in
/etc/dhcp/dhcpcd.connect:
#!/bin/sh
# dhcpcd script (assume IP address is first argument, or use ifconfig to
# get this IP). Only works if you have DNS. Could be made to work with
# /etc/hosts
HOSTNAME=`nslookup $1 | grep '^Name:' | sed 's/Name: *//'`
hostname $HOSTNAME
# restart sendmail, httpd, etc, so they now about the new hostname
# end
Then just run dhcpcd -c /etc/dhcp/dhcpcd.connect
Now you have set the system hostname, and any app can call uname(2)
and any script can call hostname to get the hostname, all without writing
to a file.
In fact, you can leave an /etc/HOSTNAME entry like "unnamed", have your
normal startup scripts do "hostname `cat /etc/HOSTNAME`" before running
dhcpcd. Then after boot you can use this to detect whether dhcpcd
successfully got an IP by checking whether the system name is unnamed.
(I do this at home--but I used ifconfig eth0 to get the IP address, then I
can run the script by hand if I need to, without worrying about giving it
the correct arguments.)
I've never used ISC's dhclient, and I also think the options for dhcpcd
1.x have changed, so maybe in those cases this won't work. There has to
be a way to execute scripts based on whether the lease was acquired,
though.
> > As far as stuff in /dev, I'm not really sure. Your /var idea would work,
> If it's copied to a ramdisk or a non-persistent partition, it's still
> OK; it's pretty ugly though, so I'm looking for a better alternative.
You're right, it is ugly. I know people have done read-only root
partitions in the past. There must be a more elegant way. Do /dev
entries need to be read-write, or is the kernel smart enough to know that
a process running as root should have access regardless of file
permissions?
--Jeremy
Jeremy Impson
Network Engineer
Advanced Technologies Department
Lockheed Martin Federal Systems
[EMAIL PROTECTED]