Simple DNS Guide for cPanel Web Hosting Service
Note: This is a very simple DNS guide and explanation for easy understanding of DNS use for web hosting customers. It does not go into advanced terminologies to avoid confusion.
For a domain name to work for website and email, it requires properly configured DNS (Domain Name System). Without that Internet users cannot load the website from the correct server or send you email. When you register a domain, you have to configure DNS servers (also called name servers) at the domain registrar. These are typically two hostnames in the format of ns1.yourhostingservice.com and ns2.yourhostingservice.com. This basically delegates the DNS service for your domain to those name servers from where every aspect of domain, subdomains, and email can be controlled.
Those name servers keep records of your domain in a DNS Zone file. The DNS Zone can tell which server hosts yourdomain.com or a subdomain xyz.yourdomain.com etc.
When someone tries to load your website in the browser, the browser first asks the root name servers about the delegated name servers so it can find where it is hosted. The root name servers provide your hosting company’s name servers that you have configured at the domain registrar. Then your browser asks one of the name servers, where is the website hosted? If it cannot reach one, it will try and ask the second one. Once the response is received, the browser will connect to your web hosting server and request it to send web page.
There are different types of records in a DNS Zone file. The following three are most common that you may encounter, especially if you move your website or email from one server to another.
A: This record points the domain or subdomain to an IP address of server.
CNAME: This record points the domain or subdomain to another hostname as an alias. This way if the original hostname’s IP changes, you do not have to change any record in your DNS Zone. There is a restriction on how you can use CNAME. CNAME cannot be used for your domain that also needs A record and MX record. Example: you can create CNAME record for xyz.domain.com but you cannot create CNAME for domain.com because you have to create MX and A record for it as well. This is why typically CNAME records are used for subdomains only.
MX: This is called mail exchanger record and tells which server can receive email. This cannot have an IP address. It must be a fully qualified hostname. There can be multiple MX records with different priority settings.
cPanel Web Hosting
When your account is created on a cPanel web hosting service, your domain’s DNS Zone file is created automatically with all the necessary records in DNS Zone file that resides in your web hosting company’s name servers. Typically your website and email is hosted on the same server, therefore the records are setup like this:
- A record is setup for the domain using the web hosting server IP.
- www (subdomain) is setup using CNAME of your domain. Which means that www.yourdomain.com will point to same as yourdomain.com hosting server.
- Another A record is setup for mail.yourdomain.com using your web hosting server IP (which also hosts your email). And then that subdomain is used as MX record (because an MX cannot use direct IP address). Here’s a screen shot showing these records in cPanel’s Advanced DNS Zone Editor.
The MX record is not shown here. It is listed under Mail > MX Entry in cPanel.
If you need to move your website away from your hosting company’s website, the other company will provide you IP address of the new web hosting server. You can simply change the A record of your domain (first record shown in the above screen shot). This will automatically update www.yourdomain.com because of CNAME (alias). After making this change, and allowing a couple of hours for DNS propagation, your website will start pointing to the new IP while your email will stay on the current hosting server. Make sure your MX record points to mail.yourdomain.com and mail.yourdomain.com is set as an A record for your hosting server IP where you want to receive email.
Moving Email Server
When you need to move your email to another provider, they will typically give you one or more MX records. You can change the MX Records of your domain by going to cPanel > Mail > MX Entry. Here’s a screen shot how this is setup:
You can edit the record and also add more MX records on this screen. If they provide you with the IP address instead of fully qualified hostname, then you must first create an A record with that IP in Advanced DNS Zone Editor and then use that for the MX. MX record cannot use IP address. It must always use a hostname. Once you configure the MX, also make sure Email Routing shows that now you are using Remote Mail Exchanger. This is important because it will update the necessary configuration on the local mail server on your cPanel web hosting service to either receive mail or send it to remote server for the domain.
Spam Filtering Service
If you are using a third party email filtering service that requires you to change your MX record but still receive email on your cPanel web hosting server after they process your email, then you can change the MX records in MX Entry screen but keep Email Routing to Local Mail Exchanger by selecting the radio button and forcing that setting. Otherwise when you change the MX, cPanel will automatically change it to Remote Mail Exchanger, which will disable any incoming email for your domain.