SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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!
Distribution: Slackware 13; Ubuntu Raspberry Pi OS
Posts: 255
Rep:
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?
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.
Distribution: Slackware 13; Ubuntu Raspberry Pi OS
Posts: 255
Rep:
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.
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:
Distribution: Slackware 13; Ubuntu Raspberry Pi OS
Posts: 255
Rep:
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:
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:
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:~#
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.