LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   'hostname some_name' does not change the hostname. (http://www.linuxquestions.org/questions/slackware-14/hostname-some_name-does-not-change-the-hostname-4175450845/)

stf92 02-19-2013 03:28 PM

'hostname some_name' does not change the hostname.
 
Slackware 14.0

The only way I can get the hostname changed is running netconfig. Why does not hostname work?

Didier Spaier 02-19-2013 03:40 PM

'man hostname' says
Code:

hostname will print the name of the system as returned by the gethostname(2) function.

The  host  name  is  usually  set once at system startup in /etc/rc.d/rc.inet1 or /etc/init.d/boot (normally by
      reading the contents of a file which contains the host name, e.g.  /etc/hostname)

So I guess that you need to reboot for the change to take effect.

NeoMetal 02-19-2013 03:53 PM

If you run say 'hostname my_new_host' as root
and then run just 'hostname' does it give the right answer?

I think it should change it, but on your bash prompt for example, it might not change till you logout and log in. I think on reboot it will change back to whats in your hostname conf file if you don't change it there (/etc/HOSTNAME )

stf92 02-19-2013 04:04 PM

Yes, I had to edit /etc/HOSTNAME. But then, I need to do two things. (1) Edit that file. (2) Run hostname. Why does the hostname command not modify /etc/HOSTNAME? It would be easier.

Alien Bob 02-19-2013 04:04 PM

From http://docs.slackware.com/start?id=s...e_your_network
Code:

/etc/HOSTNAME
This is where your computer's hostname is defined.

May I suggest that you start READING about Slackware, which would prevent all the needless questions I've seen in the past weeks (months?). Please use http://docs.slackware.com/ - it's why we have setup that site.

Eric

stf92 02-19-2013 04:09 PM

If my questions were needless I do not think I would be asking them. Anyways, needless or not, I'll make the questions that come to my mind.

MadMaverick9 02-19-2013 08:31 PM

@stf92 - the old fashioned programmer

Quote:

Why does the hostname command not modify /etc/HOSTNAME?
Why don't you simply add some code to "/usr/bin/hostname" to do just that? It's all open-source, you know.

Or simpler - why don't you just write a shell script or a shell function to do just that? Easy enough.

Code:

function foobar() {
  /usr/bin/hostname "$1"
  /usr/bin/hostname -f > /etc/HOSTNAME
}

man bash
man hostname

tmerle 02-20-2013 06:25 AM

hostname is a linux command interacting only with the linux kernel (syscall). So it only changes the running kernel's "hostname" parameter.
It does not change any configuration file.
If you want to make changes persistent, you must perform what netconfig does:
- change /etc/HOSTNAME
- change /etc/hosts, the line related to 127.0.0.1 with the host name
- change /etc/NetworkManager/NetworkManager.conf "hostname=" line (if used)

jtsn 02-21-2013 09:12 AM

Quote:

Originally Posted by tmerle (Post 4895882)
- change /etc/hosts, the line related to 127.0.0.1 with the host name

127.0.0.1 is localhost and localhost only, and should not be changed to any other host names or numerous things break.

In special cases, you can add an entry with the official IP adress of the machine and its host name to /etc/hosts. But the better practice is to have a working DNS setup and completely keep away from /etc/hosts. It's obsolete anyway.

kikinovak 02-21-2013 10:30 AM

Quote:

Originally Posted by stf92 (Post 4895478)
If my questions were needless I do not think I would be asking them. Anyways, needless or not, I'll make the questions that come to my mind.

stf92, I have noticed that you like using various UNIX/Linux commands in ways that they're not designed in the first place. My recommendation to you: read the fine Slackbook from the first to the last page. Try out all the commands you find in it. Play with them.

Swim from one end of the pool to the other. Then come back and ask questions, and I'm sure folks here will be pleased to answer them.

Cheers,

Niki

larrybpsu 02-21-2013 01:09 PM

Quote:

Originally Posted by jtsn (Post 4896720)
127.0.0.1 is localhost and localhost only, and should not be changed to any other host names or numerous things break.

In special cases, you can add an entry with the official IP adress of the machine and its host name to /etc/hosts. But the better practice is to have a working DNS setup and completely keep away from /etc/hosts. It's obsolete anyway.

FYI: The netconfig script that is still included with Slack 14.0 will write the hostmane (and domain) into this file.

If you've given the system a hostname during the install, /etc/hosts must be edited if you decide to change the system hostname and DO NOT use the netconfig script.

jtsn 02-21-2013 07:09 PM

Quote:

Originally Posted by larrybpsu (Post 4896890)
FYI: The netconfig script that is still included with Slack 14.0 will write the hostmane (and domain) into this file.

The netconfig script writes
Code:

127.0.0.1              localhost
$IPADDR        $HOSTNM.$DOMAIN $HOSTNM

into /etc/hosts, which is correct behavior.


All times are GMT -5. The time now is 06:00 PM.