LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-07-2007, 11:40 PM   #1
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 317

Rep: Reputation: 30
Test hostname


Is there a way I can test hostname to make sure it'll save over a reboot, without actually having to reboot?
 
Old 12-08-2007, 05:24 AM   #2
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,038

Rep: Reputation: 97
In ubuntu (and other debian based distros) the hostname is reset at boot time with the data in the /etc/hostname file.

From a quick google search it appears that in Slackware this filename might be in uppercase:
/etc/HOSTNAME


Therefore if you want to know what your hostname would be after a reboot:
Code:
cd /etc
ls -1|grep -i hostname|xargs cat
 
Old 12-08-2007, 01:59 PM   #3
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 317

Original Poster
Rep: Reputation: 30
That's the problem. I've had my hostname set in that file for months. But when the server reboots, the hostname isn't set to that and is instead set to "zeno".
 
Old 12-08-2007, 02:19 PM   #4
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,038

Rep: Reputation: 97
I don't have Slackware available, however on ubuntu the hostname is set at boot by:

/etc/rcS.d/S02hostname.sh

which is linked to:

/etc/init.d/hostname.sh
 
Old 12-08-2007, 03:33 PM   #5
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 317

Original Poster
Rep: Reputation: 30
Here's what is done on boot:
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
Why is it doing that? The cut line is cutting off the text at the .

Thus since I had zeno.biyg.org it simply turns into zeno. I can't have that happen, but I don't understand why it's doing that.

(The reason I can't have it set to zeno is because my email sends out from nobody@domain where domain seems to be set as the hostname, thus if it's nobody@zeno instead of the correct nobody@zeno.biyg.org, all email servers will reject the email)

Last edited by Zeno McDohl; 12-08-2007 at 03:34 PM.
 
Old 12-08-2007, 03:39 PM   #6
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 234Reputation: 234Reputation: 234
Just edit your HOSTNAME file with the name you want to use and be done with it. Every system has some type of script to determine the hostname at bootup. Red Hat will have the name set in /etc/sysconfig/network
 
Old 12-08-2007, 03:52 PM   #7
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 317

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by trickykid View Post
Just edit your HOSTNAME file with the name you want to use and be done with it. Every system has some type of script to determine the hostname at bootup. Red Hat will have the name set in /etc/sysconfig/network
Please read the thread. That doesn't work. I did set the HOSTNAME file as I already mentioned. But as you can see from the code I posted, the system does not fully read the file on boot. It only reads up to the first period and then stops.
 
Old 12-08-2007, 03:56 PM   #8
Disillusionist
Senior Member
 
Registered: Aug 2004
Location: England
Distribution: Ubuntu
Posts: 1,038

Rep: Reputation: 97
You could modify the script to use:

/bin/hostname $(cat /etc/HOSTNAME)

Instead of:

/bin/hostname $(cat /etc/HOSTNAME | cut -f1 -d .)
 
Old 12-08-2007, 04:21 PM   #9
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 317

Original Poster
Rep: Reputation: 30
Yeah I know I could do that. But I don't like changing system defaults without knowing why they were that way to begin with... There must be a reason.
 
Old 12-08-2007, 07:28 PM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,247

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
Consider
Code:
echo fred|cut -f1 -d .
fred

echo 'fred.g'|cut -f1 -d .
fred
IOW, if you have a hostame with a domain, it gets only the hostname, that's why the '.'
 
Old 12-08-2007, 07:58 PM   #11
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 317

Original Poster
Rep: Reputation: 30
I understand that. What I don't understand is WHY it is being done.
 
Old 12-09-2007, 02:03 AM   #12
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670Reputation: 670
What it is doing is correct. If you enter "hostname" or "echo $HOST" you should see "zeno". If you enter "dnsdomainname" you should see "biyg.com".

You should concentrate on the email part of the problem. For example, if the email is sent from a cronjob, edit the cronjob so that the email is sent to a real user.

You could have a "nobody: root" entry in /etc/aliases so that the email gets sent to root.
 
Old 12-17-2007, 08:08 AM   #13
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
OP, does that make sense[/I]?
(It does to me, at least after just a little thought.)
Do you need more explanation?
 
  


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
LXer: One programmer's unit test is another's integration test LXer Syndicated Linux News 0 07-29-2007 04:46 AM
linux test bed vs. windows test bed Hewson Linux - General 1 06-20-2007 11:01 PM
LXer: Mozilla invites users to pre-test a test LXer Syndicated Linux News 0 08-10-2006 12:12 AM
FC4 Test 1 CD Test failes every DISC Jimbo99 Linux - Software 1 03-18-2005 04:16 PM
hostname command vs. $HOSTNAME env. variable Silly22 Linux - Networking 2 03-29-2002 06:01 PM


All times are GMT -5. The time now is 04:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration