LinuxQuestions.org
Review your favorite Linux distribution.
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 02-19-2013, 03:28 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Rep: Reputation: 46
'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?
 
Old 02-19-2013, 03:40 PM   #2
Didier Spaier
Senior Member
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slackware{,64}-{14.1,current} on a Lenovo Thinkpad T61 6457-4XG
Posts: 4,249

Rep: Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044
'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.
 
Old 02-19-2013, 03:53 PM   #3
NeoMetal
Member
 
Registered: Aug 2004
Location: MD
Distribution: Slackware
Posts: 106

Rep: Reputation: 19
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 )

Last edited by NeoMetal; 02-19-2013 at 03:56 PM.
 
Old 02-19-2013, 04:04 PM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Original Poster
Rep: Reputation: 46
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.
 
Old 02-19-2013, 04:04 PM   #5
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 5,259

Rep: Reputation: Disabled
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
 
Old 02-19-2013, 04:09 PM   #6
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Original Poster
Rep: Reputation: 46
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.
 
Old 02-19-2013, 08:31 PM   #7
MadMaverick9
Member
 
Registered: Aug 2010
Location: Here
Distribution: Slackware 14.0
Posts: 137

Rep: Reputation: Disabled
@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
 
Old 02-20-2013, 06:25 AM   #8
tmerle
LQ Newbie
 
Registered: Dec 2008
Posts: 1

Rep: Reputation: 0
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)

Last edited by tmerle; 02-20-2013 at 06:35 AM.
 
Old 02-21-2013, 09:12 AM   #9
jtsn
Member
 
Registered: Sep 2011
Location: Europe
Distribution: Slackware
Posts: 803

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by tmerle View Post
- 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.
 
Old 02-21-2013, 10:30 AM   #10
kikinovak
Senior Member
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: Slackware, Slackware64
Posts: 1,619

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by stf92 View Post
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
 
1 members found this post helpful.
Old 02-21-2013, 01:09 PM   #11
larrybpsu
LQ Newbie
 
Registered: Oct 2005
Location: Uniontown PA, USA
Distribution: Slackware
Posts: 25

Rep: Reputation: 7
Quote:
Originally Posted by jtsn View Post
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.
 
1 members found this post helpful.
Old 02-21-2013, 07:09 PM   #12
jtsn
Member
 
Registered: Sep 2011
Location: Europe
Distribution: Slackware
Posts: 803

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Quote:
Originally Posted by larrybpsu View Post
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
getting errors related to hostname -- security problem? ok to change hostname? sneakyimp Linux - Server 2 11-18-2012 05:25 PM
clients CAN resolve hostname of server w/nslookup, but CANNOT access by hostname WTF? psycroptic Linux - Networking 9 11-10-2012 11:24 AM
FC13 install can ping by hostname, ssh by hostname fails jeffk42 Linux - Networking 4 11-14-2011 11:27 AM
Changed hostname during install, now CUPS has wrong hostname on web interface slinx Linux - Software 1 08-07-2009 08:01 PM
after hostname change, syslogd still output previous hostname to messages file tiger2000 Linux - General 3 07-22-2009 09:36 PM


All times are GMT -5. The time now is 07:45 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration