Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
The right way to set hostname!
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Kalin
Tux's lil' helper
Tux's lil' helper


Joined: 22 Dec 2002
Posts: 109
Location: Japan

PostPosted: Thu Sep 04, 2003 2:30 pm    Post subject: The right way to set hostname! Reply with quote

Ok, I started this posting as a cry for help, but eventually after a lot of stracing I found I had some forgotten stuff in the /etc/hosts file :-)

My problem was that `hostname -d` was returning an emty string, because I had
127.0.0.1 localhost
11.22.33.44 my-host
in /etc/hosts ...

So now that I found the right way to do it, just wanted to post it here:

Reading in /etc/init.d/hostname
Quote:

# To have a proper FQDN, you need to setup /etc/hosts and /etc/resolv.conf
# properly (domain entry in /etc/resolv.conf, and FQDN in /etc/hosts).


# We use whatever is in /etc/hostname here. That means:
#
# 1) For doing it the proper way, you should NOT put a
# FQDN in there, but:
# a) Only have the hostname in there (no dns/nis domainname)
# b) Set the dnsdomainname via /etc/resolv.conf
# c) Set the nisdomainname via 'domainname'.
#
# 2) If the user want a FQDN in there, it should be possible
# without hacking things to pieces, but then he should
# know what he is doing ...
#


I figured out the usuall setup is:
/etc/hosts :
Code:
127.0.0.1       localhost

/etc/hostname :
Code:
myhost

/etc/resolv.conf :
Code:
search mydomain.topdomain
nameserver <your dns cache IP>


Then:
Code:
$ hostname -s
myhost
$ hostname -d
mydomain.topdomain
$ hostname -f
myhost.mydomain.topdomain
$ hostname -s
myhost
$ uname -n
myhost


That setup works OK, except when you cannot contackt your dns cache (i.e. you have no network connection for example).
Any idea how to fix this?
Back to top
View user's profile Send private message
derelm
Tux's lil' helper
Tux's lil' helper


Joined: 26 Nov 2002
Posts: 95

PostPosted: Sun Sep 07, 2003 5:30 pm    Post subject: Reply with quote

well, this doesn't work for me,

i still get mymachine.nkown_domain as fqnd at the login prompt.

hostname (-s -d -f) doesn't even work, it says :

Code:
hostname: No address associated with name


i'd love to get this solved!

btw: i use dhcp, it should set the domainname and the ypdomain automagically (which it does in /etc/resolve.conf and yp.conf)
Back to top
View user's profile Send private message
XavierPenguin
n00b
n00b


Joined: 18 Dec 2002
Posts: 9

PostPosted: Wed Sep 10, 2003 3:39 am    Post subject: setting dnsdomainname Reply with quote

Here's what I had to do to get this working. Don't know if it's the 'correct' way to do it, but works for me.

1. in /etc/hosts, put FQDN prior to hostname
Code:
127.0.0.1 localhost
192.168.0.1  host.home.net host
# had this, and 'domainname -d' would return nothing
# 192.168.0.1 host host.home.net
192.168.0.2  host2.home.net host2


2. start domainname service, make sure domainname is in /etc/dnsdomainname.
Code:
$ cat /etc/dnsdomainname
home.net
$ /etc/init.d/domainname start
$ rc-update add domainname boot


3. still ended up w/o domainname on tty login, need to update issue file changing \o to \O
Code:
This is \n.\O (\s \m \r) \t
Back to top
View user's profile Send private message
jaanv
n00b
n00b


Joined: 16 Jul 2002
Posts: 12

PostPosted: Thu Sep 11, 2003 10:53 pm    Post subject: setting dnsdomainname Reply with quote

On my system there was a typo in /etc/init.d/domainname.
IIRC like this:
ebegin "Setting DNS domainname to ${mydnsdomain}"
/bin/domainname $mydnsdomainname

the second line should be:
/bin/domainname $mydnsdomain

jaanv
Back to top
View user's profile Send private message
illc0mm
n00b
n00b


Joined: 13 Sep 2003
Posts: 6

PostPosted: Sat Sep 13, 2003 3:30 am    Post subject: Reply with quote

Okay, here is the solution:

As the install docs say:

Set your server name
Code:
$ echo mymachine > /etc/hostname


Set your Domain Name:
Code:
$ echo mydomain.com > /etc/dnsdomainname


And if you use NIS, set your NIS Domain Name:
Code:
$ echo nis.mydomain.com > /etc/nisdomainname


And then, for some reason this very important is left out:
Code:
$ rc-update add hostname default


That will take care of the dreaded:

Code:
This is hostname.(none)...


Prompt

Now, my next question. Is this a bug or a feature?

-illc0mm
Back to top
View user's profile Send private message
ixion
l33t
l33t


Joined: 16 Dec 2002
Posts: 708

PostPosted: Tue Sep 16, 2003 12:43 am    Post subject: Reply with quote

I've done ALL of this, but $HOSTNAME still report my old hostname.. this is quite frustrating seeing how I'm utilizing dyndns and apache won't start because it can't get the right hostname.... I have to login as root and 'export HOSTNAME=newname.mydomain.org' to get anything to work.. why is this? /etc/hosts is correct, /etc/hostname is correct, /etc/dnsdomainname is correct, /etc/nisdomainname is correct, /etc/domainname is correct, domainname and hostname are added to runlevel default... $HOSTNAME still reports old hostname... /etc/profile doesn't seem to have any references to the old hostname.. what gives?? :evil:
_________________
only the paranoid survive
Back to top
View user's profile Send private message
illc0mm
n00b
n00b


Joined: 13 Sep 2003
Posts: 6

PostPosted: Tue Sep 16, 2003 12:50 am    Post subject: Reply with quote

Well, the only thing else I can suggest is:

Code:
$ find /etc -type f | xargs grep -i "oldhostname"


Should find any "hidden" references to that hostname. It has to be defined somewhere, the server won't "remember" it between reboots.

If that finds nothing, last result would be:

Code:
$ find / -type f | xargs grep -i "oldhostname"


Which will search from the root.

-illc0mm
Back to top
View user's profile Send private message
sy5t3mfux
n00b
n00b


Joined: 17 Sep 2003
Posts: 1

PostPosted: Wed Sep 17, 2003 2:21 am    Post subject: Reply with quote

The only way I could get it to work was by putting the following line into /etc/conf.d/local.start

Code:
domainname -vF /etc/dnsdomainname


which sets up your domain name as the very last thing before you get to login
Back to top
View user's profile Send private message
ixion
l33t
l33t


Joined: 16 Dec 2002
Posts: 708

PostPosted: Wed Sep 17, 2003 11:07 pm    Post subject: Reply with quote

illc0mm wrote:
Well, the only thing else I can suggest is:

Code:
$ find /etc -type f | xargs grep -i "oldhostname"


Should find any "hidden" references to that hostname. It has to be defined somewhere, the server won't "remember" it between reboots.

If that finds nothing, last result would be:

Code:
$ find / -type f | xargs grep -i "oldhostname"


Which will search from the root.

-illc0mm



Thank You!!! Fixed it! :D :D :D

There were remnants of it left in /etc/profile.env and /etc/csh.env... editing those to proper values did that trick... thanks again!
_________________
only the paranoid survive
Back to top
View user's profile Send private message
Kalin
Tux's lil' helper
Tux's lil' helper


Joined: 22 Dec 2002
Posts: 109
Location: Japan

PostPosted: Sun Feb 08, 2004 2:39 pm    Post subject: Hostname problem : SOLVED Reply with quote

2013-04-09 edit:
That post is OLD! I'll leave it here for archivval purposes, but have a look at http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=8#doc_chap2 instead.

Well, I am still fighting with this problem from time to time on new (or old, forgotten) istallations....

Trying to clear it for myself:
Quote:
Problem:
Set the FQDN hostname to "pe.do.net" of a Gentoo box (linux-2.6, glibc-2.3.2), so that it stays constant without regard of DNS cache reachability.


This is the desired output:
Code:
$ hostname
me
$ dnsdomainname
zo.net

$ hostname -s
me
$ hostname -d
zo.net
$ hostname -f
me.zo.net


The files to tweak:
Code:
/etc/hostname
/etc/resolv.conf
/etc/hosts


I tried all possible combinations of settings in the above files, and somehow got it. Now that I think of it, it was obvious...

Here is how to do it:
Code:

#/bin/bash
# Copyright Kalin KOZHUHAROV <kalin@ThinRope.net>

HOST="me"
DOMAIN="zo.net"
# the IP address of our DNS cache (some call it server, WRONG!)
CACHE="192.168.1.1"

# If you have tried before, clean up
echo "Cleaning..."
for f in /etc/{{host,{dns,nis}domain}name,resolv.conf,hosts}; do mv $f $f-bAcKUP 2>/dev/null;done
rc-update del domainname >/dev/null 2>&1

# Create the files needed:
echo "Creating the files needed..."
echo ${HOSTNAME} >/etc/hostname
echo -e "127.0.0.1\t\t${HOST}.${DOMAIN} ${HOST} localhost" >/etc/hosts
echo -e "domain ${DOMAIN}\nsearch ${DOMAIN}\nnameserver ${CACHE}"    >/etc/resolv.conf

echo "Updating your config..."
hostname -F /etc/hostname
rc-update add hostname boot >/dev/null 2>&1

# check what we have done
echo "Checking..."
set -x
hostname
dnsdomainname
hostname -s
hostname -d
hostname -f
set +x
echo
echo "====================================================================="
echo "If you are satisfied with the results, delete the old files by doing:"
echo -e '\trm -f /etc/*-bAcKUP'
echo
echo "You can also see how did your config change by:"
echo -e '\tfor f in /etc/{{host,{dns,nis}domain}name,resolv.conf,hosts}; do diff -u $f-bAcKUP $f;done'
echo "====================================================================="


Some notes:
    1. /etc/init.d/domainname is a not a good one, as it does nothing for dns domain name, but prints that it does something!
    2. See `man hosts` for the format and see the examples. Should work as I suggest.
    3. Roughly speaking /etc/resolve.conf is used only when dnscache is reachable and etc/hosts when not. So test at both states.
    4. It is not tested with DHCP, but if you can reach your DHCP server, you won't need it anyway.
    5. For IPv6, add the necesary entries from your old /etc/hosts file, or they will be added anyway.
    6. That's all folks! Smile!


Last edited by Kalin on Tue Apr 09, 2013 4:34 am; edited 1 time in total
Back to top
View user's profile Send private message
capt.Hij
n00b
n00b


Joined: 07 Mar 2006
Posts: 3

PostPosted: Mon Apr 08, 2013 5:04 pm    Post subject: Reply with quote

Sorry for the necro-post, but I just came across this problem. This page had a high ranking on google and was second on the list, and unfortunately the information above is a bit out of date. The solution to the problem can be found at the following link:

http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=1&chap=8

See section 8b.

As of this writing the solution is to set the host name in the file /etc/conf.d/hostname
Back to top
View user's profile Send private message
friesia
Apprentice
Apprentice


Joined: 23 Mar 2007
Posts: 181

PostPosted: Tue Apr 09, 2013 10:53 am    Post subject: Reply with quote

How do we set DNS domain name with systemd then?
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum