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?
JamesG
  • 143
  • 1
  • 5

3 Answers3

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.

Peter Bishop
  • 451
  • 2
  • 7
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}
Analog
  • 2,385
  • 17
  • 29
jeffkee
  • 101
  • 1
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.

nathangiesbrecht
  • 3,350
  • 22
  • 34