Search Our Database
Adding DNS Records via SSH in cPanel and DirectAdmin
Introduction
DNS (Domain Name System) records are critical for directing domain-related traffic to the appropriate servers. While cPanel and DirectAdmin provide graphical interfaces for managing DNS records, there are situations where direct SSH access is necessary. This might include cases where the graphical interface is unavailable, multiple records need to be updated efficiently, or automation is required via scripts.
This guide explains how to manage DNS records via SSH for servers running cPanel and DirectAdmin. It details the prerequisites, step-by-step commands, and considerations specific to each control panel. The guide is aimed at system administrators familiar with command-line interfaces, ensuring efficient and accurate DNS record management.
By following this guide, you can add or update DNS records while avoiding common challenges such as misconfigurations or typos that might disrupt domain functionality.
Prerequisites
- Root or sudo access to the server.
- cPanel or DirectAdmin installed and running on the server.
- Familiarity with Linux command-line interface.
- Backup of existing DNS zone files to prevent accidental loss.
- Access to SSH client software (e.g., PuTTY or terminal).
- The following paths to DNS zone files:
- For cPanel: /var/named/
- For DirectAdmin: /var/named/ or /etc/namedb/
Step-by-step Guide
For cPanel
Step 1: Access the Server via SSH
Log in to the server using SSH. Use the following command:
ssh root@your-server-ip
Step 2: Navigate to the DNS Zone Directory
Navigate to the directory containing DNS zone files:
cd /var/named/
Step 3: Edit the Zone File
Locate the DNS zone file for the domain and open it using a text editor such as nano or vi. Replace example.com.db with the appropriate zone file:
nano example.com.db
Step 4: Add or Modify DNS Records
Add the desired DNS records in the appropriate format. For example:
- A Record:
subdomain IN A 192.168.1.1
- CNAME Record:
alias IN CNAME example.com.
- TXT Record:
@ IN TXT "v=spf1 include:example.com ~all"
Step 5: Save Changes
Save the changes and exit the text editor. For nano, use CTRL + O, press Enter, and then CTRL + X.
Step 6: Rebuild DNS Configuration
Rebuild the DNS configuration to apply changes:
/scripts/rebuilddnsconfig
Step 7: Restart the DNS Service
Restart the DNS service to ensure changes are active:
systemctl restart named
For DirectAdmin
Step 1: Access the Server via SSH
Log in to the DirectAdmin server via SSH:
ssh root@your-server-ip
Step 2: Navigate to the DNS Zone Directory
Locate the directory where DNS zone files are stored. For DirectAdmin, it is typically:
cd /var/named/
Step 3: Edit the Zone File
Open the zone file for the domain using a text editor. Replace example.com.db with the correct file name:
nano example.com.db
Step 4: Add or Modify DNS Records
Insert the DNS records in the required format. Use the same syntax as in the cPanel example above.
Step 5: Save Changes
Save and close the file as described earlier.
Step 6: Update the Named Configuration
DirectAdmin requires the zone files to be updated in its named configuration. Run the following command:
named-checkzone example.com /var/named/example.com.db
Step 7: Restart the DNS Service
Restart the named service to apply changes:
systemctl restart named
Conclusion
This guide detailed the steps to add or modify DNS records via SSH in both cPanel and DirectAdmin environments. Managing DNS through SSH provides flexibility, especially for bulk changes or during interface issues. Remember to validate changes using tools like dig or nslookup to ensure proper functionality.
Should you have any inquiries about the guidelines, please feel free to open a ticket through your portal account or contact us at support@ipserverone.com. We’ll be happy to assist you further.