I've been reading for hours on this and am still stuck.

Everything I've read indicates I need my hostname and a domain name to get a FQDN. But what about a setup where I have one hostname, using Apache, and also virtual hosts with several domain names, and I am wanting to setup a mail server for a few of the domains.

If I choose one domain name as part of the FQDN what happens to functionality of the other domains? It would seem to me that since all the domains are virtualhosts, which resolve to the same IP, that I could choose any domain name for the FQDN and it would work for all the domains... correct? Or do I just add as many FQDN entries as there are domain names?

So does a hostname of mybox with the domains example.com, as well as example.net and example.org, mean that in my /etc/hosts/ file I write localhost.localdomain localhost mybox.example.com mybox mybox.example.net mybox mybox.example.org mybox


Thank you!

  • In the end, I think I understand what a FQDN is, and how one is made, and how other domains can work around it in terms of mail servers and such. After many attempts to install my own mail server I eventually gave up and went to mxroute.com. So many other email services either had limits on how many domains could be used (I have a bunch); the price was too high (especially if the domain limit was one or two); or was based on the company's FQDN. I like mxroute.com because the domains and mailboxes are unlimited, and it is quite affordable. – Shane Feb 23 '16 at 15:20

I think the proper format for your hosts file would be: localhost.localdomain localhost mybox.example.com mybox.example.net mybox.example.org mybox

... using only one line per IP address, and adding all the FQDNs to the list. Make sure to add the appropriate DNS entries so that other computers can connect to this server (if that is needed).

Once you have this in place, you can tweak your Apace VirtualHost entries on how to handle requests for each domain name. You might want to start with a single VirtualHost listening on *:80 just to test your FQDNs out. After that, you can add or replace it with specific VirtualHost entries for each domain name that you want to handle.

  • Thank you for your answer. Would "mybox.example.com" be the 'default' FQDN? Or are all in that list equally considered a FQDN? I've read that ppl name their host with what will be their 'default' FQDN, thus: ` localhost.localdomain localhost example.com.example.com example.com.example.net example.com.example.org example.com’ Is it better to use a one word name for the hostname (in my case I am using a DO droplet, and whatever name I gave the droplet when I made it, that seems to be the hostname. Would naming the droplet after a domain name cause problems.)? – Shane Apr 12 '15 at 3:15
  • I'm not familiar with the way DigitalOcean does things. That may be a good topic for a separate question. In general, don't use a domain name you don't own (like mydroplet.microsoft.com) if you want it to be accessible by the public. As for the primary hostname, the first name after the IP address is the primary hostname for that address. Your Linux distribution may vary, but the hostname -f command may help. The whole method for setting your hostname may differ, though, depending on distribution again. – GuitarPicker Apr 12 '15 at 12:13

Apache does not care about the contents of your /etc/hosts file. All that really matters is the Apache's VirtualHost configuration.

  • At its simplest, this is correct. Ideally, you simply call your default host the main FQDN of the machine, and then restrict access to it. After that, everything else is placed in to a VirtualHosts configuration... and that can be soft (by name) or hard (by interface/ip/port). – RVT Apr 11 '15 at 7:08
  • I think I understand that. But when it comes to installing a mail server I need a FQDN, and I haven't been able to figure out if on one host I can have more than one FQDN (postfix needs one as part of its installation, for example). All the example and tutorials tell me to choose a FQDN, but I've found none to seem to clearly explain how setting one FQDN affects other domain names on that host. And what is in the /etc/host seems to matter then. Thanks for your input. – Shane Apr 12 '15 at 3:30
  • 1
    You left important information away from your original question. You didn't mention the mail server at all, and it makes the question different. Postfix has its own mechanisms for handling FQDNs, and you need to set up one FQDN in /etc/hosts that matches the reverse DNS. – Tero Kilkanen Apr 12 '15 at 9:54
  • @TeroKilkanen I see. I was trying to keep the question as succinct as possible, not realizing that the answer might change depending on what was to be done with the FQDN. The last portion of your last line however does raise the question for me however: When you say I need to set up one FQDN in '/etc/hosts/' do you mean that there can only be ONE FQDN in the '/etc/hosts/'? If so, how do I set up more FQDNs with more domains, all on the same host? Would the first answer above not work then (wherein I place all domain names on one line)? Thank you. – Shane Apr 13 '15 at 13:17

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.