How to properly set "hostname", "hosts" file and add "A/AAAA record"?

I'm a little confused with the Linode's Official Guide and have difficulties in properly setting up. If you see any improper setting, please let me know.

Let's say my website is www.goodjob.com and my linode is running debian 10. And my user name is nick.

I set the hostname with this command.

hostnamectl set-hostname gj

And my terminal become to look like this.

[email protected] $ cat /etc/hostname
gj

In the Linode's Getting Started Guide, I have to edit the file /etc/hosts as follows,

127.0.0.1 localhost.localdomain localhost
203.0.113.10 example-hostname.example.com example-hostname
2600:3c01::a123:b456:c789:d012 example-hostname.example.com example-hostname

So, I edited this file as follows (except ip address). Do I need to edit the first line? Why?

127.0.0.1 localhost.localdomain localhost
203.0.113.10 gj.goodjob.com gj
2600:3c01::a123:b456:c789:d012 gj.goodjob.com gj

I bought my domain from namecheap and added ns1.linode.com … ns5.linode.com as Custom DNS. Then I Add A/AAAA Record from the Linode's Domains menu. This one is for ipv4.

Create A/AAAA Record
Hostname = www
IP Address = 203.0.113.10
TTL = Default

This one is for ipv6.

Create A/AAAA Record
Hostname = www
IP Address = 2600:3c01::a123:b456:c789:d012
TTL = Default

The problem is that if I do setup as above, my site do not work without www (see below). If I setup without www (i.e. leave a blank in Hostname), my site do not work with www.

[email protected] $ ping goodjob.com
ping: goodjob.com: Name or service not known

Please help.

1 Reply

Hey Nick,

It looks like you've done a great job so far! To answer your questions directly:

So, I edited this file as follows (except ip address). Do I need to edit the first line? Why?

When you are modifying /etc/hosts, you are basically setting aliases for specific IPs. 127.0.0.1, which is the first line, is for a localhost loopback address. You don't need to edit the first line as your hostname was already set earlier and also within this /etc/hosts file, so I'd leave this address for any programs or scripts that might try to use the alias localhost.

The problem is that if I do setup as above, my site do not work without www (see below). If I setup without www (i.e. leave a blank in Hostname), my site do not work with www.

This makes sense, since you only set one A/AAAA and you pointed it towards www. If you'd like for the address to resolve correctly without needing www, simply make another A/AAAA record that has the hostname blank, like so:

Create A/AAAA Record
Hostname = 
IP Address = 203.0.113.10
TTL = Default

Create A/AAAA Record
Hostname = 
IP Address = 2600:3c01::a123:b456:c789:d012
TTL = Default

-Sam

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