Assigning Dedicated IPs to Subdomains
Warning: Please read the
Reasons for Assigning Dedicated IP Addresses to Subdomains section of the article before continuing to the process.
Though our software does not provide an easy UI that allows you to assign dedicated IP addresses to your users' subdomains, it is possible. To do so, you simply need to know which files to edit and which services to restart. For the purposes of this article, we’ll use the following:
Reasons for Assigning Dedicated IP Addresses to Subdomains
ICANN requires that a website owner meet one of 2 simple requirements before dedicating an
IP address to his or her domain. The user’s domain or
subdomain must either:
- Require an SSL Certificate — Generally, these certificates are used for e-commerce. SSL Certificates ensure visitors that they are sharing sensitive information on a secure connection with the appropriate domain.
- Run an anonymous FTP site.
Remember: Assigning a dedicated
IP address for any other reason than the reasons listed above is a violation of ICANN’s terms. For more information about ICANN policies, you can visit their website
here.
Editing Files in the Userdata Directory
To begin, we’ll need to use a terminal to navigate to our
userdata directory. This directory can be found at
/var/cpanel/userdata. The
userdata directory contains exactly that, user data. It contains the information our web server references when locating a user’s files within the system.
Next, you’ll need to locate the user who requires that each
subdomain use a dedicated
IP address. We’ll call this user
John. To open
John’s userdata folder:
Inside of the user’s
userdata directory, you’ll find the following files:
- example.com
- example.com.cache
- sub1.example.com
- sub1.example.com.cache
- sub2.example.com
- sub2.example.com.cache
- main
- main.cache
Next, you’ll need to change the IP addresses for the 2 subdomains. You can do this using your preferred text editor (vi, vim, pico, nano, etc.). When you open the file to edit it, you should see entries that resemble the following:
customlog:
-
format: combined
target: /usr/local/apache/domlogs/example.com
-
format: "\"%{%s}t %I .\\n%{%s}t %O .\""
target: /usr/local/apache/domlogs/example.com-bytes_log
documentroot: /home/John/public_html
group: Group1
hascgi: 1
homedir: /home/John
ip: 192.168.0.1
owner: John
phpopenbasedirprotect: 1
port: 80
scriptalias:
-
path: /home/John/public_html/cgi-bin
url: /cgi-bin/
-
path: /home/John/public_html/cgi-bin/
url: /cgi-bin/
serveradmin: webmaster@example.com
serveralias: www.example.com
servername: example.com
usecanonicalname: 'Off'
user: John
userdirprotect: ''
Within the subdomains’ files, you’ll need to edit the
ip entry to reflect the dedicated
IP address that should hold the user’s subdomains. For
sub1.example.com, you would need to edit the file to reflect the following information:
customlog:
-
format: combined
target: /usr/local/apache/domlogs/example.com
-
format: "\"%{%s}t %I .\\n%{%s}t %O .\""
target: /usr/local/apache/domlogs/example.com-bytes_log
documentroot: /home/John/public_html
group: Group1
hascgi: 1
homedir: /home/John
ip: 192.168.0.2
owner: John
phpopenbasedirprotect: 1
port: 80
scriptalias:
-
path: /home/John/public_html/cgi-bin
url: /cgi-bin/
-
path: /home/John/public_html/cgi-bin/
url: /cgi-bin/
serveradmin: webmaster@example.com
serveralias: www.example.com
servername: example.com
usecanonicalname: 'Off'
user: John
userdirprotect: ''
For
sub2.example.com, you would need to repeat the process to reflect the following:
ip: 192.168.0.3
Rebuilding and Restarting Apache
When you are finished modifying your
userdata files, you will need to rebuild and restart
Apache. To rebuild
Apache, issue the following command:
- /scripts/rebuildhttpdconf
Now, you will need to restart
Apache. You can accomplish this by issuing the following command:
- /scripts/restartsrv_apache
If you would prefer to use the UI to restart
Apache, you can find this interface in the
Restart Services section of WHM. To restart
Apache using the WHM user interface:
- Click the Restart Services icon on the main page or the appropriate link in the navigation bar.
- Click the HTTP Server (Apache) icon.
- Click the Yes button.
Adding the Subdomains’ Nameserver Records
Finally, you’ll need to add the subdomains’ IP addresses to the
nameserver records. You can accomplish this through the WHM interface. Please read our documentation for editing zone files
here.
If you would prefer to use our API, the documentation can be found
here.
Note: To use the API to edit
nameserver records, you will need to be running cPanel/WHM 11.25+.
Reserving the Dedicated IP Address
To prevent the dedicated
IP address from being assigned via the WHM interface, you may need to add it to the reserved
IP address list. You can find our documentation for reserving IP addresses
here.
Addon Domains
You can also use this method to assign dedicated IP addresses to addon domains. However, our addon domains are mapped to subdomains within the
userdata directory. When you edit the files within the
userdata directory, your
addon domain will appear as such:
In this case, you will need to change the
ip entry’s value for
addon.example.com.