Quick questions about setting the hosts file and DNS entries

I'm currently following along with the quick start guide. I've spun up a Debian 8 server, and am in the process of setting the hosts file. The current entries look like:

127.0.0.1       localhost
127.0.1.1       debian

As you can see, there's no domain entries, just a label for localhost and debian. What should I put for my public IP entries? I know where to find them, but should it be something like:

my-ip4-address   hostname
my-ip6-address  hostname

Or do I need to make a fake web address, like:

my-ip4-address  fu.bar.com  hostname
my-ip6-address  fu.bar.com  hostname

??

I also don't know what I should put in for my DNS records. The first screen says 'enter host name'. Would this be the fake one in the second example above?

6 Replies

Information on updating hosts can be found here:

https://linode.com/docs/getting-started#update-etchosts

You'll want to take the primary domain name you plan to use with it, make an entry for it to your server in our DNS Manager (or your own DNS Manager of choice), then add it to your hosts file as described in the documentation.

Your hosts file is up to you and your configuration; specifically the software you're using and how much it relies on /etc/hosts and DNS resolution. Here's an example from one of my Linodes, obfuscated with $VARIABLE:

alex@$HOSTNAME:~$ cat /etc/hosts
127.0.0.1    $HOSTNAME.$MYDOMAIN.com   $HOSTNAME
127.0.1.1    debian

That doesn't necessarily mean that $HOSTNAME.$MYDOMAIN.com is the domain, or even the only domain, pointed to that Linode's IP. But whatever domain you use in the DNS manager, that must be a domain you've registered, and set to use our name servers.

Update:

So as an example, if I own example.com and I am making a web server for it, I could set up my host file like this:

127.0.0.1    web.example.com    web
127.0.1.1    example.com

$PUBLICIP example.com

Now, Apache or Nginx don't need this configuration in order to properly serve content requested for example.com. But if you set up more complex clusters, or use other software that relies more heavily on this file, it will come in handy to have it properly configured.

Okay, so I ultimately want to host 3-5 sites on my server, all LEMP (Nginx, MariaDB, PHP) stack. Do I need to enter in a FQDN in my hosts file for each one? Or will virtual hosting take care of that provided my domains are pointed to the Linode nameservers?

EDIT: I've only ever used shared hosting for deployment, which is why this is a bit baffling to me. I used to just purchase a new account for each site, so I never had to worry about the hosts file at all. I understand the concept of what it does, just not how to set it up properly since all the guides assume a 1:1 Linode-to-website ratio. It'd be really nice if there was an added "If you're planning on hosting multiple sites on one account/server, do/don't do the following:" to each guide.

There seems to be a conceptual misunderstanding of what the hosts file does. It is used when your Linode needs to look up a hostname. In Ye Olden Days, a hosts file contained a nearly complete list of all hostnames and IP addresses on the Internet.

Today, we have the Domain Name System (DNS) which tells you the IP address(es) for foo.example.com. You don't need to maintain your own local list of names and addresses anymore. /etc/hosts only needs to contain things that DNS can't help you with. For example, localhost needs to be resolvable even if DNS or your outside network interface isn't working.

Your hosts file has nothing to do with what names can be used by others to reach your Linode's IP address. That is governed by what you put into DNS (or potentially, what other people put into their /etc/hosts). Nor does it affect what requests your web server responds to. That is controlled by your web server's configuration files (e.g., nginx or Apache). The default entries from your original post should work just fine without additions or modifications.

Vance's answer is spot on. To tie it back to my earlier posts, and to your last question in general, there are certain times where modifying your hosts file matters to the software you're running, but you probably won't encounter that any time soon.

@KevinM1:

It'd be really nice if there was an added "If you're planning on hosting multiple sites on one account/server, do/don't do the following:" to each guide.

That's actually something we do. So unless the guide says something about multiple websites, you can assume that the setting is not specifically for a one-site configuration.

Source: I write Linode docs.

Awesome, guys :D Thanks!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct