Modify DNS Record From shell on cPanel server


DNS update on cPanel
Update DNS Record from Shell on Linux cPanel Server

A DNS record on server help resolve domain to an IP address. cpanel allow DNS record to be managed from WHM Zone manager from WHM but today we will look at steps as how to modify dns records from shell. This can also come in handy if you want to modify large number of records with single command after server move. If there is sudden IP change then working from command prompt will give fast results.

First you will need root access to server to access zone files and modify them.

1 Login to Server as root user and visit directory /var/named

cd /var/named

If you will do listing with ls command you will see lot of db files which represent the zone file for domain for example

domain.com.db

2) Open the domain db file in your favorite text editor for which you want to modify DNS record, It will be named as domain for which you want to edit dns record followed by .db extension.

vi domain1.com.db

Text editor will show content of zone file from which you can modify records

Save the file and exit

:wq!

3) Restart DNS Server

Restart the DNS Service using this command

service named restart

Or

/etc/init.d/named restart

Once restarted new DNS record will start propagating within couple of hours.

Bulk Update DNS record for all domain on server

If there are hundred of thousand of domain on server and its required to do bulk DNS update then it can also be performed from shell

Once in /var/named/data directory use Find command to do search and replace

In example below we will be changing old IP with new IP in zone file for all domain on server.

cd /var/named

find . -name '*.db' | xargs perl -pi -e 's/old_ip/new_ip/g'

service named restart

This can also be used to update MX record, TXT records and CNAME records.

Leave a comment

Your email address will not be published. Required fields are marked *