LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 03-16-2005, 03:39 AM   #1
[GOD]Anck
Member
 
Registered: Dec 2003
Location: The Netherlands
Distribution: Slackware
Posts: 171

Rep: Reputation: 33
hostname, fqdn, /etc/hosts setup


I've been using Linux in general and Slackware in specific for quite some time now but one of the things that I've never quite understood is how to set up a hostname / fqdn / hosts file properly. I've always been able to get things to work with sufficient use of voodoo magic but it doesn't feel quite right, if you know what I mean.

So I hit Google and looked for some /etc/hosts howto's.. there are plenty but most are contradicting in one way or another, and most seem to more or less work, which doesn't really help me determine which is the right way to do it.

I'm running a very simple setup, where I have a Slackware 10.1 box behind a router. I've registered a DNS name at DynDNS, myname.homelinux.org, which I have my router update whenever my IP changes. The router forwards ports for services I want to use to my Slackware box. These include ssh, http, ftp, imap, and smtp.

What should I have in /etc/HOSTNAME? What should the result of "hostname -f" be? What should I have in my /etc/hosts file? Currently I have it set like this:

Code:
root@P233:/# cat /etc/HOSTNAME
P233.DOMAIN

root@P233:/# hostname
P233

root@P233:/# hostname -f
myname.homelinux.org

root@P233:/# cat /etc/hosts
#
# hosts         This file describes a number of hostname-to-address
#               mappings for the TCP/IP subsystem.  It is mostly
#               used at boot time, when no name servers are running.
#               On small systems, this file can be used instead of a
#               "named" name server.  Just add the names, addresses
#               and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine.  It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1               localhost.localdomain localhost
192.168.1.106           myname.homelinux.org P233
# End of hosts.

root@P233:/#
The things I'm not quite comfortable with is whether or not to put my machine name in the fqdn, or maybe to make my machine name the first part of my DynDNS name, and what I should have in /etc/HOSTNAME. It appears to not be used at all right now, as the /etc/hosts file takes precedence.

I'd much appreciate any advice on how to do this properly. If you can point me to a good howto that will actually explain why things should be one way or another, that'd also be great. Thanks!

Last edited by [GOD]Anck; 03-16-2005 at 03:43 AM.
 
Old 03-16-2005, 05:45 AM   #2
n0xvb
Member
 
Registered: Sep 2004
Location: 127.0.0.1
Distribution: Slackware 13; openSUSE 11.2
Posts: 255

Rep: Reputation: 32
You are actually describing two different processes on your machine.

The HOSTNAME file is just a text file that holds the name of your system. The OS or programs can read this to get your system name. It actually doesn't do anything for DNS resolutions. You want your fqdn here.

The /etc/hosts file is used by your system to resolve fqdn to IP addresses. Typically (depends on the configuration in /etc/resolv.conf) your system will check the /etc/hosts file for the fqdn or simple host name and use the IP address if it is found. If you are not using a nameserver for DNS queries, then if there is not an entry in your hosts file, then you will receive an error message.

In your hosts file, the 127.0.0.1 is your loopback interface (which is found on all systems)
and

192.168.1.106 myname.homelinux.org P233

is the entry that will allow you to ping p233 or ping myname.homelinux.org
It also allows you to have the fqdn (myname.homelinux.org) and simple name (P233)

The /etc/HOSTNAME file should probably contain:
myname.homelinux.org
or
P233.homelinux.org

and the simple name in /etc/hosts normally will match, although it doesn't have to.
Hope that helps?
 
Old 03-16-2005, 06:21 AM   #3
[GOD]Anck
Member
 
Registered: Dec 2003
Location: The Netherlands
Distribution: Slackware
Posts: 171

Original Poster
Rep: Reputation: 33
Wel.. a bit..

See, what I get from man hostname is this:

Code:
hostname will print the name of the system as returned by the gethostname(2) function.
So that would then return the first bit of whatever is in /etc/HOSTNAME, in my case P233, correct? But then it goes on to say:

Code:
Technically: The FQDN is the name gethostbyname(2) returns for the host name returned by gethostname(2).
The DNS domain name is the part after the first dot.
So, if I made my /etc/HOSTNAME file say "myname.homelinux.org" then gethostname(2) would return "myname", and gethostbyname(2) would return the FQDN that /etc/hosts specifies for the alias "myname". If I had a line in my /etc/hosts file specifying "192.168.1.106 myname.homelinux.org myname" then gethostbyname(2) would give me "myname.homelinux.org". However, the DNS domain name, also returned by the command dnsdomainname, being the part after the first dot, would be simply "homelinux.org" where I feel it ought to be "myname.homelinux.org" as that is the DNS name that I registered. So I think what is confusing me most right now, is whether my dnsdomainname should be "myname.homelinux.org" or simply "homelinux.org"?

Also, most sources specify that an FQDN should consist of both the hostname and the domain name, but then I would have to have "192.168.1.106 P233.myname.homelinux.org P233" in my /etc/hosts file..

Hehe I hope that still makes any sense. My head hurts.

Last edited by [GOD]Anck; 03-16-2005 at 06:41 AM.
 
Old 03-16-2005, 06:41 AM   #4
n0xvb
Member
 
Registered: Sep 2004
Location: 127.0.0.1
Distribution: Slackware 13; openSUSE 11.2
Posts: 255

Rep: Reputation: 32
Certainly!

The HOSTNAME file is used to return the name of your system, the /etc/hosts file is used to return the IP address associated with a fqdn or simple name.

When hostname is used, it will use the contents of the /etc/HOSTNAME file, not what is contained within your /etc/hosts file.

Your fqdn contains two parts: The hostname (myname) and the domain (homelinux.org). The hostname command will return "myname"
Your domain is homelinux.org and your fully qualified domain name is myname.homelinux.org.

These are defined when you run netconfig and set up your network.

In your web browser (or other application) if you put in www.linuxquestions.org, it will search your /etc/hosts for this fqdn and if it is found will point your browser to the correct IP address. It would not use the /etc/HOSTNAME file.

I believe the gethostname and gethostbyname are the actual system calls within the hostname program, unfortunately I don't have my system handy to look at that!

The HOSTNAME file only contains the name and domain for your system. The /etc/hosts file can contain the name and/or fqdn and its IP address for any system.
 
Old 03-16-2005, 06:56 AM   #5
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,443

Rep: Reputation: 94
Also you may want to add in /etc/resolv.conf :
search homelinux.org
 
Old 03-17-2005, 03:24 AM   #6
[GOD]Anck
Member
 
Registered: Dec 2003
Location: The Netherlands
Distribution: Slackware
Posts: 171

Original Poster
Rep: Reputation: 33
I think I've got it down this time.. thanks for the replies.

I've got a follow-up question though: what would I need to have in /etc/hosts if I had more than 1 interface / IP? For example, I have 2 network cards connecting a box to 2 networks, eth0 is assigned IP address 192.168.1.106 and eth1 is assigned IP address 192.168.2.106. How do I set up /etc/hosts now?

The way I figured, it's not a problem if the interfaces share an FQDN, but they would need to have different aliases.. so I could have something like this:

Code:
192.168.1.106 myname.homelinux.org myname
192.168.2.106 myname.homelinux.org othername
Or, how does that work?

Last edited by [GOD]Anck; 03-17-2005 at 03:27 AM.
 
Old 03-17-2005, 05:12 AM   #7
n0xvb
Member
 
Registered: Sep 2004
Location: 127.0.0.1
Distribution: Slackware 13; openSUSE 11.2
Posts: 255

Rep: Reputation: 32
Quote:
Originally posted by [GOD]Anck
I think I've got it down this time.. thanks for the replies.

I've got a follow-up question though: what would I need to have in /etc/hosts if I had more than 1 interface / IP? For example, I have 2 network cards connecting a box to 2 networks, eth0 is assigned IP address 192.168.1.106 and eth1 is assigned IP address 192.168.2.106. How do I set up /etc/hosts now?

The way I figured, it's not a problem if the interfaces share an FQDN, but they would need to have different aliases.. so I could have something like this:

Code:
192.168.1.106 myname.homelinux.org myname
192.168.2.106 myname.homelinux.org othername
Or, how does that work?

Yes, you could do that, you would just have to remember that when you attempt to resolve myname.homelinux.org it will use 192.168.1.106 first because it is first in the list. You only need to have one entry. For multiple names, it might be better to do it this way to remove the duplicate entry:
Code:
192.168.1.106 myname.homelinux.org myname
192.168.2.106 othername.homelinux.org othername
192.168.1.106 yetanothername
192.168.1.106 thisonetoo
EDIT: sorry wanted to add in that you can do multiple fqdn as well.

Last edited by n0xvb; 03-17-2005 at 05:16 AM.
 
Old 03-17-2005, 05:14 AM   #8
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,443

Rep: Reputation: 94
It is correct, just for the example :
Code:
192.168.1.106 myname.homelinux.org myname
192.168.2.106 othername.homelinux.org othername
 
Old 03-17-2005, 05:17 AM   #9
n0xvb
Member
 
Registered: Sep 2004
Location: 127.0.0.1
Distribution: Slackware 13; openSUSE 11.2
Posts: 255

Rep: Reputation: 32
Quote:
Originally posted by keefaz
It is correct, just for the example :
Code:
192.168.1.106 myname.homelinux.org myname
192.168.2.106 othername.homelinux.org othername
Thanks keefaz, you read my mind!
 
Old 07-20-2010, 04:51 PM   #10
bluegospel
Member
 
Registered: Jan 2010
Distribution: centOS
Posts: 404

Rep: Reputation: 53
I'm not sure which IP address to use when I list my machine name in /etc/hosts, particularly after reading:

Quote:
By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1 # should NEVER be named with the name of the machine. It causes problems # for some (stupid) programs, irc and reputedly talk. :^)
Here's what I have now:

Code:
root@eagleswing:~# hostname
eagleswing
root@eagleswing:~# cat /etc/HOSTNAME
eagleswing.5binc
root@eagleswing:~# cat /etc/hosts
#
# hosts		This file describes a number of hostname-to-address
#		mappings for the TCP/IP subsystem.  It is mostly
#		used at boot time, when no name servers are running.
#		On small systems, this file can be used instead of a
#		"named" name server.  Just add the names, addresses
#		and any aliases to this file...
#
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
# should NEVER be named with the name of the machine.  It causes problems
# for some (stupid) programs, irc and reputedly talk. :^)
#

# For loopbacking.
127.0.0.1		localhost


# End of hosts.

root@eagleswing:~#
 
  


Reply

Tags
config, configuration, host, hostname, hosts, netconfig, network, setup


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
Changing Hostname.../etc/hosts...? vous Linux - Networking 13 01-16-2008 08:38 PM
"hosts allow" in smb.conf expects only FQDN, not alias or netbios name!? Not now, John! Linux - Networking 1 10-13-2006 05:17 AM
/etc/hosts, hostname, and dnsdomainname questions rdmenotte Linux - Software 8 10-10-2004 04:30 AM
hostname setup for router RoughEdge Linux - Newbie 5 04-29-2004 09:16 AM
hostname changes after setup internet spchehe Linux - General 4 08-19-2003 02:11 PM


All times are GMT -5. The time now is 10:17 PM.

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