Modify multiple dns zone files

There are 2 basic ways to modify a dns zone file, from the command line or from WHM via
Main >> DNS Functions >> Edit DNS Zone. What happens if you have five hundred domains on a server and want to migrate them all to a new shared IP address? Do you spend the next 4 days going through all of the zone files modifying them by hand or via the command line? I don’t think so…

We will be using cPanels swapip utility. The swapip utility allows you to update nameserver records by specifying 4 parameters in a command line interface. The swapip utility is located at

To use this utility for a single zone file, run the following command, specifying the appropriate parameters:

/usr/local/cpanel/bin/swapip $sourceip $targetip $ftpip $domains

Note: $sourceip, $targetip, $ftpip, and $domains are meant to symbolize the parameters you wish to enter.


  1. * sourceip (string) — The old IP address.
    * targetip (string) — The new IP address.
    * ftpip (string) — The new FTP server’s IP address.
    * domains (string) — One or more domains associated with the IP address being changed.




would change the nameserver records for on to point HTTP and FTP requests to

A successful swapip attempt should return you to the command line without displaying any messages. The output should resemble the following:

root@example [~]# /usr/local/cpanel/bin/swapip
root@example [~]#

An unsuccessful swapip attempt should result in an error message, the output of which will resemble the following:

root@example [~]# /usr/local/cpanel/bin/swapip
Error: domains missing
Usage: /usr/local/cpanel/bin/swapip sourceip destip ftpip domains...

Note: At this time the error message may not give an accurate assessment of the error that has occurred.

In order to change all dns zone file ip’s to another ip, we will use a simple one liner like so;

for each in `cat /etc/domainips | grep | cut -d: -f2`; do /usr/local/cpanel/bin/swapip $each done;

If you see any variation in this, please let me know.


I am a g33k, Linux blogger, developer, student and Tech Writer for My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.