Quick questions about setting the hosts file and DNS entries
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
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.
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.
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.
hosts file
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.
@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
Source: I write Linode docs.