LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 10-01-2017, 10:42 PM   #1
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,593

Rep: Reputation: 179Reputation: 179
HOSTNAME reverting to darkstar on boot


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.

Last edited by mfoley; 10-01-2017 at 10:44 PM.
 
Old 10-01-2017, 11:58 PM   #2
rworkman
Slackware Contributor
 
Registered: Oct 2004
Location: Tuscaloosa, Alabama (USA)
Distribution: Slackware
Posts: 2,559

Rep: Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351Reputation: 1351
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.
 
1 members found this post helpful.
Old 10-02-2017, 03:54 AM   #3
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,915

Rep: Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033Reputation: 5033
Just a guess, but..

$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.
 
Old 10-02-2017, 11:18 AM   #4
mfoley
Senior Member
 
Registered: Oct 2008
Location: Columbus, Ohio USA
Distribution: Slackware
Posts: 2,593

Original Poster
Rep: Reputation: 179Reputation: 179
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).
 
  


Reply

Tags
darkstar, dhcp



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Sun to Open Source Project Darkstar, Announces Darkstar Playground LXer Syndicated Linux News 0 03-07-2007 06:46 AM
no KDE at boot, prompt only, darkstar login? phazon Slackware - Installation 11 05-22-2006 03:45 PM
Network boot and hostname mesh2005 Linux - Networking 2 05-07-2006 12:52 AM
Reverting Debian to its minimal boot-strap version hasanito Debian 3 09-28-2004 03:50 PM
New Slack 10 Install asking for Darkstar login and password at boot up schteelhead Slackware 3 08-28-2004 05:02 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 01:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration