User Tools

Site Tools


Updating Your Hostname and Default Nameservers

Occasionally, you may want to change your server's main domain that you initially set up for use as the hostname and the default nameservers. Perhaps you have rebranded, accidentally allowed the old domain to expire, or some other reason has caused you to want to change your main domain. There are a few things to consider when doing this.

First of all, your existing domains that are using this domain as the basis for the nameservers should be considered. These domains may experience some slight downtime if that domain and consequently, its nameservers, are not working. Thus, it is imperative to work quickly when updating these records to the new domain after the old domain has expired. If you are simply rebranding while the old domain is still active, then there is no rush. Leaving the old domain, nameservers, and hostname active until the new records propagate will prevent a lot of unnecessary downtime while waiting on the new records to propagate.

The same considerations exist when considering the hostname and PTR record using that hostname in regards to sending email. Not having a hostname that resolves, and using a PTR record for an IP that is set to a non-resolving hostname can affect mail deliverability. As such, it is again necessary to correct this as soon as possible if your old domain is no longer functioning.

Often times it occurs that a domain expires and clients believe this to be a quick fix, though this is not the case. The issue is that you must create new nameservers, which may take 24-48 hours to propagate (though this usually occurs in 2-6 hours), and then one by one, you must log into your registrar account for each domain and update their nameservers to the new nameservers. Both, the creation of the new nameservers and the assignment of these new nameservers must be done at the server in addition to the registrar. Luckily, Knownhost can help with the server aspect of this. We can either do this for you, or you can use the instructions below to do it yourself.

Creating the New Nameservers and the Hostname A Record at the Server

To create the GLUE records in the server (which is just A records for the ns1 and ns2 subdomains), log into WHM as the 'root' user using the root user's password and navigate as follows:

  Home »DNS Functions »Edit DNS Zone 

You should see the following with a list of domains to choose from.

Select the domain that you want to use for the nameservers and the server's hostname from the dropdown list. The DNS Zone file for that domain will be displayed.

Scroll to the bottom of the page and input the following (To get the IPs, I just used the IPs that were present in the zone files for ns1/ns2.olddomain.tld):

host A <primaryIP>

ns1 A <primaryIP>

ns2 A <secondaryIP>

You can leave 14400 IN set as is.

Note: the creation of the A record for the new hostname because it is important to have a hostname that resolves and has a corresponding PTR record otherwise you may have mail deliverability issues. Now save the zone file and ensure that it saves without error. The interface will show that the zone file is being reloaded and that the settings have been updated:

You have just created the GLUE records at the server. Now, you will need to do the same at the registrar.

Registrar References

GLUE Records or Private Nameserver Registration is handled at the Domain Registrar; here are some quick links for popular domain registrars.

We have an article that expands on this process: Registering Nameservers

Assigning the New Nameservers

Now, we must actually use these nameservers. We will do this by changing the NS records for your domains from ns1.olddomain. and ns2.olddomain. to ns1.newdomain. and ns2.newdomain. This can be done in WHM's Edit DNS Zone as well for each domain.

To make this process quicker, I usually do this in bulk. I first make a backup of /var/named using this command:

  cp -a /var/named /var/named.bak

The change into the directory containing the zone files to edit:

  cd /var/named

You can now use sed to replace all old ns1 nameservers with the new ns1 nameservers, and then all old ns2 nameservers with the new ns2 nameservers:

  sed 's/ns1.olddomain./ns1.newdomain./g' *.db
  sed 's/ns2.olddomain./ns2.newdomain./g' *.db

NOTE: Please note the period at the end of each nameserver in these commands! If you omit this period, then the panel will think you are adding a subdomain and automatically append the domain name to the end of the record, which is NOT what we want. If you omit these periods at the end of each nameserver in the command, you will need to restore the backup you made and start over!

If you will be updating the hostname, it should be changed in these files as well (Again, take care to include these periods at the end of the hostnames as they are incredibly important!):

  sed 's/host.olddomain./host.newdomain./g' *.db

I then restarted named to force it to reload all zones:


Update the Default Nameservers

The default nameservers are those that are used for new accounts by default upon creation. These are currently set to ns1.olddomain. and ns2.olddomain. These can be updated in WHM here:

  Home »Server Configuration »Basic WebHost Manager® Setup 

Scroll to the bottom of the page and you will see the default nameserver settings. Replace the old nameservers with the new nameservers.

You will also need to make sure that the correct nameserver records are showing here. Occasionally, if DNS changes have been made regarding the nameserver A records, the old IPs may show for a day or so until the registrar updates their records and the panel updates following this. You can force the panel to update using the following script:


To update the nameserver A records (aka glue records), you will need to click "Configure Address Records" next to the nameserver.

Confirm the information shown is correct and click the "Configure Address Records" button in this frame.

You will need to repeat this process for the other nameserver, and then finally, click "Save Changes" at the bottom of WHM's "Basic WebHost Manager® Setup".

Changing the Hostname

Now, the hostname should be changed on our end, and in the panel. Once the hostname is changed on our end, we will also have to update the license (the command will be shown on screen with the error when you attempt to access WHM).

The command must be run via SSH as the root user and is as follows:


Changing the hostname in WHM can be done here:

  Home »Networking Setup »Change Hostname 

NOTE: The hostname must still be changed on our end so that we may also update the PTR record!

Remove Old DNS Zone Files

Lastly, when you "Edit DNS Zone" in WHM, you may notice that the DNS Zone files for the old nameservers and hostname still exist. These can be removed in WHM

  Home »DNS Functions »Delete a DNS Zone 

If you want to remove them both at the same time, hold down Ctrl and click both that you'd like to remove. They should both be highlighted. You can then click "Delete".

The only reason that you may not want to immediately remove these zone files would be if your old domain was still active, and thus the old nameservers and old hostname. Keeping these active until the new domain, nameservers, and hostname propagated could potentially prevent much of any unnecessary downtime.

Reminder: You Must Still Make the Appropriate Changes At the Registrar!

You must still create the nameservers at the registrar by adding A records for both ns1 and ns2, and you must then log into the registrar for each domain that requires the nameserver change and update the custom nameservers for those domains to the new nameservers that you just created.

That's it! :-)

control-panels/cpanel-whm/how-do-i-configure-my-dns-for-hostname-changes-in-cpanel.txt · Last modified: 2021/02/22 15:35 by Jonathan K. W.