4

I need to add a domain/IP record to my hosts file on a CentOS box running WHM/cPanel, so that a domain which has no public DNS is routed to the correct IP address.

I've done this on my macbook but I'm unsure of the process on cPanel.

When I nano /etc/hosts I see the following:

# Automatically generated by OnApp (2.3.1)
127.0.0.1               localhost
1.2.3.4                 s1.mydomain.com

So - if the contents of this file are automatically generated:

  • Is it safe to edit this file manually - or will cPanel wipe my changes during updates etc?
  • Does WHM/cPanel have an GUI for adding hosts records?
3
  • Do you have a root account? otherwise you can't. Aug 7, 2015 at 9:46
  • Yeah I have root and can edit and save the file. I'd just be keen to know if cPanel will overwrite the changes if OnApp generates the file again
    – JamesG
    Aug 7, 2015 at 15:11
  • Good question. There is not much information on this, and no GUI plugin for WHM/cPanel for direct hosts file mitigation. Have you tried experimenting though? For example, add a line in /etc/hosts, then change/add a nameserver in DNS Functions » NS Record Report or mess with DNS Functions » Add an A Entry for Your Hostname (or other spots) to see if your manual changes are wiped out or preserved. Going on a limb, i think you're safe to edit it, however as LaVar Burton says, "But you don't have to take my word for it...." (insert cPanel expert opinion in next comment hah)
    – dhaupin
    Aug 7, 2015 at 15:14

3 Answers 3

5

It is perfectly acceptable to update /etc/hosts in cPanel/WHM.

As a rule of thumb, incase of an update which may change the file (unlikely, cPanel doesn't tend to touch it after the initial install phase) run this command to take a backup.

# cp /etc/hosts /etc/hosts.bak

This will copy your hosts file to a new file in your etc directory called hosts.bak which you can rename to hosts again at anytime incase you need to revert any changes.

At current, cPanel does not provide a GUI for updating your hosts file however, if this is a feature that you feel will benefit others, you can submit a feature request where others can vote on and discuss your request.

0

Yes, you can safely add entries to the hosts file. The only thing you might need to consider is that the entries may be erased if you update WHM/Cpanel.

0

I use this feature routinely to speed up development.

My hosts file from line 4 and on looks like this so we all know which areas are something we can edit without worrying about the server generated stuff - we never touch those first few lines!

###START{CUSTOM_HOSTS_SPOOF}
10.1.1.2        clientdomain1.example www.clientdomain1.example
10.1.1.2        clientdomain2.example www.clientdomain2.example
10.1.1.2        clientdomain3.example www.clientdomain3.example
10.1.1.2        clientdomain4.example www.clientdomain4.example
###END{BRIXWORK_HOSTS_SPOOF}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.