Configuring DNS (Domain Name Server) is crucial for hosting a website and email capability. In order for your server to be visible to the outside world as example.com and not as a string of numbers like 123.132.123.132 you have to have a domain and configure it.
As every provider has a different panel for DNS records it is pointless to provide pictures. Read on and you will easily catch on.
Getting a domain
If you want a free domain check out the requirements page to see how to grab one for a few months. If you want to commit to an address for longer you will have to buy a domain for yourself. namecheap.com has some good deals under $2 for a year to get you started.
Basics
There are three major entries that you need to configure yourself
- DNS A type record
- MX mail record
- SPF record
- PTR record – done by your ISP
Without proper DNS configuration you will not be able to serve a website properly and most definitely you will not be able to send nor recive any mail.
DNS A
This is your main record. It will point directly to your router, which in turn will direct traffic to your server.
Configuring DNS A
Use the following configuration and put it in the control panel of your domain
- Subdomain – @
- Address – put your external IP address
- Record type – choose A
- Priority – ignore
- TTL – if present, set it up for something high, like 86400
Subdomain @ – this means no subdomain, you want to configure example.com first
Address – you can check your external address here, this will be four triple digit numbers separated with full stops, e.g. 123.456.789.123 This address points to your router.
Record type A – This means the main address of the domain you registered. Typing example.com in your browser will resolve this specific address
Priority – used for MX record, ignore here
TTL – time to live for resolved name in seconds. The recommendation is either 12 or 24 hours, which means either 43200 or 86400 seconds. ISPs might completely ignore this value so you can also leave the default value and do not worry about it.
Now put a second, almost identical, DNS A record with the following configuration
- Subdomain – www
- Address – same as above
- Record type – same as above
- Priority – same as above
- TTL – same as above
This will act in the same way as the above record, but will be used if someone types www.example.com instead of example.com
Some domains are not obvious and newyorkcity.travel might not look like a website address to everyone, but if you write www.newyorkcity.travel it is different, but people will inculde www. prefix, so you have to configure your DNS to resolve that as well. This is a good practice.
MX DNS record
You need to configure this record for email to work. Think of it as your physical address, postman will not be able to deliver mail which says John on the envelope, but if you add John Doe, This Street 1, London he will know where to deliver the mail. This is what the MX record does, more or less.
Put the following configuration
- Subdomain – @
- Address – example.com.
- Record type – choose MX
- Priority – 10
- TTL – same as above
Subdomain – you want email to be delivered to example.com, without any subdomains, hence again put @ like with DNS A record
Address – this time we are putting the address handle that your mail is supposed to be delivered to. Everything after the @ sign in john@example.com should be placed in this field, however, do MIND THE DOT at the end! It is required in order for the DNS to resolve your address properly!
Record type MX – this simply tells the DNS server that you are configuring an email record
Priority – this sets the priority of email servers. If you have just one, you can put any value that you want – 10, 20, 69, it does not matter. It is only used if you have more than one email server on the same domain, this is often used to set up a backup email in case your main server is unreachable. For now configure only our main server
TTL – exactly as your main A record
SPF DNS record
Sender Policy Framework is a record for authenticating the sender. Sent email is authenticated against this record to tell the recipient server that you are allowed to send emails from this domain. This record is not required, however, without it your mail can be flagged as spam. In worst cases the target server will refuse to deliver it at all.
Put the following configuration
- Subdomain – @
- Address – v=spf1 mx a ~all
- Record type – choose TXT
- Priority – ignore
- TTL – ignore
Caution! you might see an SPF type record in your DNS configuration, it is an outdated type of record and you should not use it. Use TXT record type instead.
Above configuration will tell recipients that your domain is configured for sending email and you are not a Nigerian Prince sending spam from kingdom@nigeria.com
PTR DNS record
This one, unfortunately, cannot be changed by you.
PTR is basically the reverse of DNS A type record. You can configure your example.com domain to point to 123.456.789.123, but if you want 123.456.789.123 to point to example.com you are at mercy of your ISP. Check with your internet provider if they can change that for you. This usually involves a plan with static IP or some king of a plan targeted at a business and will cost you more.
If you do not have a PTR record, then most likely your mail will go straight to recipient’s SPAM folder. Some spam filters will also qualify domain without PTR as spam and will block your emails entirely. Getting a PTR record with your ISP pretty much guarantees that you will not be flagged as a spammer by automated filters.
Unfortunately I do not have a PTR record myself, which means mail sent from my server is delivered to SPAM folders pretty much most of the time. I need to change my ISP…
Subdomains
If you want your webmail to be accessible from your browser by typing mail.example.com or you want to set up a forum at forum.example.com you need to configure your DNS to tell it that there is a website to be served at this address.
Simply add the following record, that is almost exactly like your A type record
- Subdomain – mail
- Address – put your external IP address
- Record type – choose A
- Priority – ignore
- TTL – ignore
Another one for when someone uses www prefix
- Subdomain – www.mail
- Address – put your external IP address
- Record type – choose A
- Priority – ignore
- TTL – ignore
This way you can add as many subdomains as your DNS registrar allows. Most likely more than you will ever need.
Subdomain vs an alias
Each service requires a specific address for access. It can be either a subdomain like mail.example.com, but it can also be an alias like example.com/mail
What is the difference? Alias can use the domain’s certificate. Subdomains need to be specified within the certificate, which is a pain if you want to add a new service to the existing setup. Unless you get a wildcard certificate which costs a LOT of money annualy. Read more about certificates and how to get one for free here
Using an alias is just more convenient. Learn more about them here
Conclusion
Setting up DNS records is not hard, however, it is necessary if you want to have a decent server, and an absolute must if you want email capability and secure connection with the website. Unprotected websites are flagged by most browsers as dangerous so a rule of thumb is – get yourself a domain.
Caution! DNS servers take some time to update. Initially configured domain might take 24 hours to update. If you have configured everything but it looks like something is not working then give it a day. Subdomains should be good to go right after configuring, but just in case – be patient.