View previous topic :: View next topic |
Author |
Message |
Kalin Tux's lil' helper
Joined: 22 Dec 2002 Posts: 130 Location: Germany
|
Posted: Thu Sep 04, 2003 2:30 pm Post subject: The right way to set hostname! |
|
|
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 :
/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 |
|
|
derelm Tux's lil' helper
Joined: 26 Nov 2002 Posts: 95
|
Posted: Sun Sep 07, 2003 5:30 pm Post subject: |
|
|
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 |
|
|
XavierPenguin n00b
Joined: 18 Dec 2002 Posts: 9
|
Posted: Wed Sep 10, 2003 3:39 am Post subject: setting dnsdomainname |
|
|
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 |
|
|
jaanv n00b
Joined: 16 Jul 2002 Posts: 12
|
Posted: Thu Sep 11, 2003 10:53 pm Post subject: setting dnsdomainname |
|
|
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 |
|
|
illc0mm n00b
Joined: 13 Sep 2003 Posts: 6
|
Posted: Sat Sep 13, 2003 3:30 am Post subject: |
|
|
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 |
|
|
ixion l33t
Joined: 16 Dec 2002 Posts: 708
|
Posted: Tue Sep 16, 2003 12:43 am Post subject: |
|
|
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?? _________________ only the paranoid survive |
|
Back to top |
|
|
illc0mm n00b
Joined: 13 Sep 2003 Posts: 6
|
Posted: Tue Sep 16, 2003 12:50 am Post subject: |
|
|
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 |
|
|
sy5t3mfux n00b
Joined: 17 Sep 2003 Posts: 1
|
Posted: Wed Sep 17, 2003 2:21 am Post subject: |
|
|
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 |
|
|
ixion l33t
Joined: 16 Dec 2002 Posts: 708
|
Posted: Wed Sep 17, 2003 11:07 pm Post subject: |
|
|
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!
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 |
|
|
Kalin Tux's lil' helper
Joined: 22 Dec 2002 Posts: 130 Location: Germany
|
Posted: Sun Feb 08, 2004 2:39 pm Post subject: Hostname problem : SOLVED |
|
|
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 |
|
|
capt.Hij n00b
Joined: 07 Mar 2006 Posts: 5
|
Posted: Mon Apr 08, 2013 5:04 pm Post subject: |
|
|
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 |
|
|
friesia Apprentice
Joined: 23 Mar 2007 Posts: 202
|
Posted: Tue Apr 09, 2013 10:53 am Post subject: |
|
|
How do we set DNS domain name with systemd then? |
|
Back to top |
|
|
cord Guru
Joined: 28 Apr 2007 Posts: 344
|
Posted: Fri Jun 16, 2017 1:01 pm Post subject: |
|
|
I use udhcpc and it get ip/mask,route from provider, but no hostname (always 'localhost').
Earlier I was using NetworkManager (same, udhcpc) and it was setting appropriate hostname on system startup.
Code: | May 29 16:07:33 [NetworkManager] <info> [1496063253.1764] policy: set-hostname: set hostname to 'xxx.xxxxx.xxx' (from address lookup) |
How to get hostname from provider (with no NM)? |
|
Back to top |
|
|
|