PDA

View Full Version : [ubuntu] Setting a FQDN?



rhcm123
May 9th, 2009, 09:37 PM
I know this has been asked a million times, but I have yet to find any good way to do it despite many google searches.

I need to set a system-wide FQDN (mostly for apache), using the following info:
Hostname: USSR-MOSCOW
Website: <no, sorry>.dyndns.org.

Can anybody give me some help with /etc/hosts? I'm at my wits end. :(

albinootje
May 9th, 2009, 09:51 PM
Can anybody give me some help with /etc/hosts?

You'll be wanting to edit /etc/hostname instead.
See also "man hostname", to test with the command "hostname".

rhcm123
May 9th, 2009, 10:02 PM
You'll be wanting to edit /etc/hostname instead.
See also "man hostname", to test with the command "hostname".

according to man hostname, i need to be editing /etc/hosts


You canít change the FQDN (as returned by hostname --fqdn) or the DNS domain name (as returned
by dnsdomainname) with this command. The FQDN of the system is the name that the resolver(3)
returns for the host name.

Technically: The FQDN is the name gethostbyname(2) returns for the host name returned by geth‐
ostname(2). The DNS domain name is the part after the first dot.

Therefore it depends on the configuration (usually in /etc/host.conf) how you can change it.
Usually (if the hosts file is parsed before DNS or NIS) you can change it in /etc/hosts.


From what ive read, the FQDN is whatever the resolving system sets it as. In ubuntu (see /etc/host.conf) it defaults to /etc/hosts, then BIND.

I need to know what lines i put into /etc/hosts to set a system wide FQDN.

albinootje
May 9th, 2009, 10:15 PM
according to man hostname, i need to be editing /etc/hosts


Well, I speak from experience, but try it yourself :

1) edit /etc/hostname, to e.g. yourhost.dyndns.org
2) run : hostname -F /etc/hostname
3) edit /etc/hosts accordingly
4) /etc/init.d/apache2 restart

Some applications might need time to get used to the change, a reboot would be handy imho.

capscrew
May 9th, 2009, 10:15 PM
according to man hostname, i need to be editing /etc/hosts



From what ive read, the FQDN is whatever the resolving system sets it as. In ubuntu (see /etc/host.conf) it defaults to /etc/hosts, then BIND.

I need to know what lines i put into /etc/hosts to set a system wide FQDN.

The /etc/hosts file is normally for the localhost (the machine the file resides on). If you want to use an /etc/hosts file for domain wide (LAN) you can use DNSmasq. This uses the local /etc/hosts file for domain wide name resolution. The term FQDN typically denotes a hostname.domainname listing.

albinootje
May 9th, 2009, 10:16 PM
In my previous comment I've put step 3 there, but I just tested this with only steps 1, 2 and 4, and apache clearly responded to the changes.

rhcm123
May 9th, 2009, 10:18 PM
The /etc/hosts file is normally for the localhost (the machine the file resides on). If you want to use an /etc/hosts file for domain wide (LAN) you can use DNSmasq. This uses the local /etc/hosts file for domain wide name resolution. The term FQDN typically denotes a hostname.domainname listing.

That's a helpful/good idear, as this system is also the localnetwork DHCP server. Can you give me some helpful starter tips on how to do use DNSmasq?

rhcm123
May 9th, 2009, 10:27 PM
In my previous comment I've put step 3 there, but I just tested this with only steps 1, 2 and 4, and apache clearly responded to the changes.

Did that, got this output from restarting apache:


apache2: apr_sockaddr_info_get() failed for USSR-MOSCOW.<wat>.dyndns.org
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
... waiting .apache2: apr_sockaddr_info_get() failed for USSR-MOSCOW.<wat>.dyndns.org
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

capscrew
May 9th, 2009, 10:36 PM
That's a helpful/good idear, as this system is also the localnetwork DHCP server. Can you give me some helpful starter tips on how to do use DNSmasq?

There's not much to say. It is a lightweight DHCP/DNS server for local networks. It will act as a DNS forwarder for Internet DNS requests. In addition it will handle dynamic mapping for hostnames to DHCP IP addresses.

The main page for DNSmasq is http://thekelleys.org.uk/dnsmasq/doc.html (http://thekelleys.org.uk/dnsmasq/doc.html)

All the documentation is located at http://thekelleys.org.uk/dnsmasq/docs/ (http://thekelleys.org.uk/dnsmasq/docs/)

Read the man page all the way through and very carefully. It is available at: http://thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html (http://thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html)

Edit: And of course there is Wikipedia's write up at: http://en.wikipedia.org/wiki/Dnsmasq (http://en.wikipedia.org/wiki/Dnsmasq)

SirGe
April 4th, 2010, 03:23 AM
I have a solution, that works for me; if it works for you, use it.

There are two files, that control how names are looked up: /etc/host.conf and /etc/nsswitch.conf. As far as I can tell, host.conf is old technology, superseded by nsswitch.conf. I do not know whether use of nsswitch.conf is hardwired, or host.conf is used as a fallback when nsswitch.conf is not present.

My /etc/host.conf has
order hosts,bind, which means /etc/hosts is searched first, then DNS.

My nsswitch.conf has


hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4

which results in the same behavior: files, than DNS.

Does not matter: we leave both as is.

My /etc/hosts has two relevant lines:


127.0.0.1 localhost
127.0.0.1 my-hostname


And, of course, /etc/hostname has my-hostname.

So, because files are hit first,
hostname --fqdn cannot get a FQDN, it only gets a short name. And Apache whines.

One way to try to fix this is to replace my-hostname in /etc/hosts with FQDN. This makes Apache happy, but lookups for my-hostname are broken (unless DNS knows how to resolve them) and lookups for FQDN (e.g. my-hostname.my-domain.net)return 127.0.0.1, which sucks.

You can add my-hostname on the same line with the FQDN. If you add it before the FQDN, the FQDN is not seen and Apache whines again. If you add it after the FQDN, things are OK, but both the hostname and the FQDN are resolved to 127.0.0.1 - gack!

The right thing is to have both the short name and the FQDN resolve to the real IP address.

If you do not have a functional DNS server on your network and your IP is static, just put the line with


123.45.67.89 my-host.my-domain.net my-host

in /etc/hosts (substitute real IP address/names).

If you do not have a functional DNS server and your IP is dynamic, go hack your DHCP scripts, so this gets fixed when your IP address changes. But in this case I suspect you are not running an Apache server, that can be accessed from outside your machine.

If you have a DNS server, then just comment out the line in /etc/hosts, so that the names - both short and long - are resolved via DNS.

This does the right thing for hostname, hostname --fqdn, Apache, etc. for short name, FQDN and localhost.