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.
* 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.
/usr/local/cpanel/bin/swapip 127.0.0.0 22.214.171.124 126.96.36.199 example.com
would change the nameserver records for example.com on 127.0.0.0 to point HTTP and FTP requests to 188.8.131.52.
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 127.0.0.0 184.108.40.206
[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 127.0.0.0 220.127.116.11 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 18.104.22.168 | cut -d: -f2`; do /usr/local/cpanel/bin/swapip 22.214.171.124 126.96.36.199 $each done;
If you see any variation in this, please let me know.