LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Can not get the default hostname to change on current (https://www.linuxquestions.org/questions/slackware-14/can-not-get-the-default-hostname-to-change-on-current-4175649985/)

GazL 03-13-2019 04:14 PM

Code:

# Set the hostname.
if [ -r /etc/HOSTNAME ]; then
  /bin/hostname $(cat /etc/HOSTNAME)
else
  # fall back on this old default:
  echo "darkstar.example.net" > /etc/HOSTNAME
  /bin/hostname $(cat /etc/HOSTNAME)
fi

Well, the obvious question that I haven't seen asked yet is what permissions do you see on /etc/HOSTNAME? If it's not readable then the script will overwrite it each boot.

coralfang 03-13-2019 05:24 PM

Quote:

Originally Posted by TarFile (Post 5973534)
# echo "darkstar" > /proc/sys/kernel/hostname
# echo "mydomain" > /proc/sys/kernel/domainname

Still won't survive a reboot.

As for this; echo'd values made into /proc don't survive a reboot.
You will have to make a file such as;

/etc/sysctl.d/hostname.conf
Code:

kernel.hostname = "myhostname"
kernel.domainname = "mylocalnet"

If your hostname changes by echoing those values, then that should work after a reboot.

TarFile 03-13-2019 06:13 PM

That did not work.

This is from rc.M

# Set the hostname.
if [ -r /etc/HOSTNAME ]; then
/bin/hostname $(cat /etc/HOSTNAME)
else
# fall back on this old default:
echo "darkstar.example.net" > /etc/HOSTNAME
/bin/hostname $(cat /etc/HOSTNAME)
fi

copied to rc.sethostname then ran it.

bash-5.0# ./rc.sethostname
hostname: the specified hostname is invalid

I saw that flash by at boot time right after the going multiuser message.

I have not idea as /etc/HOSTNAME is valid.

TarFile 03-13-2019 06:18 PM

Aw crap HOSTNAME was invalid netconfig shoved the hostname and the domain as one hostname for some reason must have been too big. There is a bug somewhere probably in netconfig?

It put it in like this

hostname.domainame.org

TarFile 03-13-2019 07:16 PM

OK I am not exactly sure how this is supposed to work.

netconfig asks for a hostname then a domainname.

It puts hostname.domainname in /ect/HOSTNAME.

hostname on the command line returns hostname.domainname

domainname returns (none)

My problem was caused by the domainname I put in netconfig.

It has a problem if you use something like this domainname_name.org apparently the _ is not allowed in a doaminname at least it won't work here. Since I don't know the rules for domain names (if any) I just put in what I liked for the local network.

Still I think if netconfig asks for a domainname it should set it correctly, providing of course it's a name that meets whatever rules are in place.

Not sure if this is a bug or a feature.

OK for what its worth

AG Domain Name Rules Summary

Use only letters, numbers, or hyphen ("-")
Domain names cannot begin or end with a hyphen
Domain names cannot have more than 63 characters, not including .AG, .COM.AG, .NET.AG, .ORG.AG, .EDU.AG, .GOV.AG, ETC.
Maximum length of a complete (Fully Qualified, FQDN) domain name (including .separators) is 255 characters
Minimum length of a domain name is 1 character, not including extensions. However, all 1 character domain names are reserved by the Registry.
A name may begin with a digit
Two character domain names are allowed
Domain names considered offensive may be declined
For domains to be active on the Internet, they must have at least one configured and working name server.
There is no restriction on the physical location or IP address of these name servers.

The rest is not related to the names allowed.

This rules out the use of _ in a domainname the cause of my initial problem.

I still think domainname should be set ny netconfig but I suppose there may be a reason it's not.

GazL 03-13-2019 07:57 PM

I disagree with Pat on this one. IMO the domain part does not belong in the nodename/hostname. I just have this.
Code:

$ cat /etc/HOSTNAME
ws1
$ grep ws1 /etc/hosts
127.1.1.1              ws1.local ws1
fe80::REDACTED ws1-wlan0.local ws1-wlan0

I don't use netconfig. I set it up manually.


Oh, and domainname gives you the NIS/YP domain. not the dns domainname. It's not the same thing.

abga 03-13-2019 08:03 PM

@TarFile

Told you it's all about the correct syntax ;) Happy to hear you got it working.

On why using "_" in the hostname is not really supported, never tried it TBH, you can get some answers from here:
https://stackoverflow.com/questions/...erscore-in-it#

TarFile 03-13-2019 08:51 PM

OK if domainname gives you the NIS/YP domain is that not the one set up by netconfig? Don't you have to register the DNS domainname to use it online?

abga 03-13-2019 09:02 PM

hostname and domain name are two different entities.

TarFile 03-13-2019 09:45 PM

From GazL's reply

"Oh, and domainname gives you the NIS/YP domain. not the dns domainname. It's not the same thing."

abga 03-13-2019 09:57 PM

@TarFile

Sorry, missed GazL's "Oh" post edit, considered you were replying to me. Never mind.

GazL 03-14-2019 05:17 AM

Quote:

Originally Posted by TarFile (Post 5973637)
OK if domainname gives you the NIS/YP domain is that not the one set up by netconfig?

No. All netconfig does with the domainname part is add it to the entry in /etc/hosts for the ip address entered, but as I said above, I believe netconfig is doing it wrong anyway by including the domain part in /etc/HOSTNAME.

TarFile 03-14-2019 12:53 PM

Yes that does seem odd. Oh well it does show the correct hostname but does not set the domianname at all. I think I may have seem something about not setting domianname for some reason in one of the setup files somewhere in /etc.

Petri Kaukasoina 03-14-2019 02:00 PM

Historically it was only the hostname and not the full canonical FQDN. Search for word 'hostname' in current's Changelog to see when it was changed in Slackware.

Petri Kaukasoina 03-14-2019 02:09 PM

The yp domainname (or nis, as they call it nowadays), which 'domainname' shows, it set by /etc/rc.d/rc.yp. If you use yp.


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