22

How do I configure domain names in Cent OS?

I am actually connecting to the servers via SSH remote terminal and I also have root credentials. Does configuring the /etc/sysconfig/network and /etc/hosts suffice? Would be great to have some steps or configuration guides..

3 Answers 3

22

Four things to do:

  • Add the hostname entry to /etc/hosts. Use the format detailed here.

  • If your hostname is "your_hostname", type hostname your_hostname at a command prompt to make the change effective.

  • Define the hostname in /etc/sysconfig/network to make this setting persist across reboots.

  • Reboot the system or restart services that depend on hostname (cups, syslog, apache, sendmail, etc.)

9

If by domain name you mean domain suffix, then /etc/resolv.conf is where the domain goes. Just add a line domain yourdomain.com

Then to set your server's hostname, there's only one good place for it, and it's /etc/sysconfig/network. Add a line HOSTNAME=yourhostname, and don't put the domain suffix in the hostname, as it will take it from /etc/resolv.conf.

You do not need to add anything (and shouldn't) in /etc/hosts to define your hostname. This is the wrong way to do it.

To test your setup, use the hostname command:

  • Use hostname -s to get the short name (should reflect what you have in /etc/sysconfig/network

  • Use the hostname -d command to test your domain (should reflect what you have in /etc/resolv.conf)

  • To test it all together, you can use hostname -f or hostname -A for the very long version.

1
  • 1
    In CentOS 7 HOSTNAME in /etc/sysconfig/network no longer works. Jan 24, 2019 at 16:51
0

The way to do it now is hostnamectl hostname.domainname

1
  • hostnamectrl set-hostname <hostname> you should not use the FQDN here
    – wrossmck
    Aug 17, 2020 at 22:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .