SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Here's something interesting I've not noticed before. When my Linux 14.2 server boots, I have rc.local send me an email with the subject "$HOSTNAME^^} Reboot". Today, I received that message after booting, after doing a `slackpkg upgrade-all`. I got the message with the subject, "DARKSTAR Reboot".
When I logged in to check it, it had the correct $HOSTNAME. Is this something new with the latest update or have I just never noticed that before?
If the latter (not noticed), why? Is rc.local running before network connections are established and/or DHCP assigns the IP?
Note that this host's name is not in /etc/hosts, although it is in /etc/HOSTNAME. It is a DHCP client and the DHCP server assigns the IP; and, presumably, the host name? I'm gussing that rc.local is running before all that is accomplished. This is just a guess on my part. If some Slackster expert could confirm or correct this notion, I'd be grateful.
First, rc.local is run at the end of rc.M, so all of the network stuff will have already run at that point. However, it is certainly possible that your dhcp server is slow to respond and thus the network is not yet (fully?) configured.
As to the system hostname being set via dhcp, that should not occur in a default Slackware setup. If you have the desired hostname in /etc/HOSTNAME (it should be in the format of "hostname.localnet.tld"), then this happens early-ish in rc.M:
Code:
# Set the hostname.
if [ -r /etc/HOSTNAME ]; then
/bin/hostname $(cat /etc/HOSTNAME | cut -f1 -d .)
else
# fall back on this old default:
echo "darkstar.example.net" > /etc/HOSTNAME
/bin/hostname darkstar
fi
In other words, if the system is getting the "darkstar" hostname assigned to it, then either /etc/HOSTNAME is not readable by root or "darkstar" is what's in /etc/HOSTNAME :-)
Re setting hostname via dhcp, I'm not familiar with how dhclient handles this, but if you are using dhcpcd as the dhcp client (you are unless you changed that or didn't install dhcpcd), then it should only set a hostname if one isn't set at all (i.e. current value is unset/null/blank or is "localhost") OR if /etc/dhcpcd.conf has "force_hostname" set to yes/true/whatever (you would have had to add this, as that parameter isn't even present in the default config file).
In short, I have no idea how you're seeing that behavior if none of the above information can explain it.
$HOSTNAME is an internal bash variable initialised when the bash shell starts. rc.local gets sourced into rc.M, so $HOSTNAME during rc.local will be whatever was set at the shell invocation of rc.M (before /etc/HOSTNAME is read).
One workaround might be to reset $HOSTNAME in rc.M after /etc/HOSTNAME is used, but as I've mentioned before in the requests for current thread, I really dislike all the sourcing that goes on in rc.S/M and would rather just have all the child scripts in rc.d exec'd according to their #! specifiers, avoiding these sorts of issues.
rworkman: my /etc/HOSTNAME is readable by root and, in fact, world. And if it could not, rc.M would write "darkstar.example.net" to /etc/HOSTNAME, which it does not. My actual, correct FDQN is in /etc/HOSTNAME.
GazL: I think you might be on to something. Yes, rc.local is sourced by rc.M and no, HOSTNAME is not set anyway in rc.M. So, perhaps this has always worked this way and I've just never noticed. I think the solution will be to set HOSTNAME in rc.local as:
Code:
export HOSTNAME=`hostname`
That should get the setting made by rc.M (3rd line of rworkman's snippet).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.