Assigning Dedicated IPs to Subdomains
For WHM version 11.38
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 a browser-based interface 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:
| Domain/Subdomain |
IP Address |
| example.com |
192.168.0.1 |
| sub1.example.com |
192.168.0.2 |
| sub2.example.com |
192.168.0.3 |
Reasons to Assign Dedicated IP Addresses to Subdomains
ICANN,
IANA, and the
Regional Internet Registries policies on IP Address usage all follow Requests For Comments 2050 (RFC 2050) “
Internet Registry IP Allocation Guidelines.”
RFC 2050 states the following:
ISPs are required to utilize address space in an efficient manner. To this end, ISPs should have documented justification available for each assignment. The regional registry may, at any time, ask for this information. If the information is not available, future allocations may be impacted. In extreme cases, existing loans may be impacted.
Two valid reasons to dedicate an
IP address to a domain are as follows:
- The subdomain requires an SSL certificate — These certificates are generally used for ecommerce. SSL Certificates ensure that visitors can share sensitive information over a secure connection with the appropriate domain.
- The subdomain hosts an anonymous FTP site.
Remember: If you assign a dedicated
IP address to a
subdomain for a reason not stated above, you will be in violation of RFC 2050. If you have any questions, contact your ISP or hosting provider for further assistance.
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:
- /usr/local/cpanel/scripts/rebuildhttpdconf
Now, you will need to restart
Apache. You can accomplish this by issuing the following command:
- /usr/local/cpanel/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:
| Main Domain |
Addon Domain |
File in userdata |
| example.com |
addon.com |
addon.example.com |
In this case, you will need to change the
ip entry’s value for
addon.example.com.