Feb 032010

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.
    Example: example.com



/usr/local/cpanel/bin/swapip example.com

would change the nameserver records for example.com 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:

[email protected] [~]# /usr/local/cpanel/bin/swapip example.com
[email protected] [~]#

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

[email protected] [~]# /usr/local/cpanel/bin/swapip example.com
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.

 Posted by at 12:25 am