cPanel change the IP of an addon domain or subdomain

In cPanel by default any addon domain or subdomain will share the IP of the main domain / account it was made under. But what if you wanted a dedicated IP? This can be done but not within cPanel and allow it to be cPanel friendly! This will require SSH access and some editing via the command line and a rebuild of the apache config

First SSH into the server and browse over and edit to (replacing $user and $domain with what you wish to modify) :

nano -w /var/cpanel/userdata/$user/$domain.com

In this file you can modify the IP of the subdomain or addon domain. The contents of the file will look like this:

documentroot: /home/user/public_html/sub1
group: user
hascgi: 1
homedir: /home/user
ip: 127.0.0.1
no_cache_update: 0
phpopenbasedirprotect: 1
serveradmin: [email protected]
serveralias: www.sub1.domain.com
servername: sub1.domain.com
usecanonicalname: ‘Off’
user: user
userdirprotect: ”

Now you can change the IP to that of another IP on the server that is not being used (If you are doing this for SSL purposes this IS key that the IP is not already in use or else WHM will not allow you to install the cert and would have to do it manually as I described in: https://mosmostech.com/2011/09/wildcard-ssl-certs-and-cpanel/.

After the change save the work and you will need to rebuild the apache config and restart apache (with a backup of the config to be safe):

cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak

/scripts/rebuildhttpdconf

service httpd restart

You should be all set to use the new IP. Just update your DNS manually to point to the proper IP. Doing this will not allow cPanel to make changes for you on IP functions or DNS functions so you must keep that in mind down the road.

This is very much related to my other article on changing document roots https://mosmostech.com/2011/12/changing-a-cpanel-document-root-docroot/