Linux – How to set the domain name on GNU/Linux

debiandomain-namehostnamelinuxredhat

Similarly to hostname that can be changed in different ways:

  • temporarily using the hostname command
  • permanently using /etc/hostname (or /etc/sysconfig/network or /etc/HOSTNAME, these files are used by the init scripts)

I want to change my domain name. I can use the domainname command, but is there a way to make it permanent across reboots? I think it can be configured in /etc/resolv.conf but this file is generally generated and I don't know exactly the difference between search and domain directives. And at what time exactly the information there is passed to the domainname program to set the domain name?

Do you have any ideas on that?

I'd like to be mostly compatible across distributions. So if if anyone has pointers on the different distributions flavours, I'd gladly accept them.

Best Answer

Set FQDN

I'm using Debian 7 and this is what worked for me; thanks to Fernando Ribeiro.

sudoedit /etc/hostname

server # here's where you put the server's host name

activate hostname

sudo hostname -F /etc/hostname

add domain name and address to the server

sudoedit /etc/hosts

192.168.1.2   server.domain server

VERIFY

> hostname --short
server

> hostname --domain
domain

> hostname --fqdn
server.domain

> hostname --ip-address
192.168.1.2