Tag Archives: how to set domain name in redhat linux 7

How to setup domain name in Linux server

Learn how to setup domain names in RedHat, Ubuntu, CentOS, Fedora like Linux servers. Also, see how to verify domain name in Linux and FQDN setup in Linux

Domain name in Linux

Many companies have an internal domain for their IT infrastructure. This needs its servers to be configured with a domain name. This will ensure all servers will have FQDN (Fully Qualified Domain Name). For example, server12 is hostname and server12.kerneltalks.com is its FQDN. In such setup, many tools, monitoring requires servers to be identified by FQDN only.

For such a scenario you have to configure the domain name for your Linux server. We will walk you through steps that need to be taken to the setup domain name on your Linux server.

First of all, check if your server is having domain name already set up or not using below command :

root@server12 # dnsdomainname
kerneltalks.com

If you get output like above then your server is configured with the domain name. If your output is blank then you have to the setup domain name for your server.

Without further delay lets jump into steps to configure domain name.

Step 1.

How to setup FQDN in Linux?

First thing to be done is add FQDN to your hostname in /etc/hosts file.

root@server12 # cat /etc/hosts
10.10.2.32    server12.kerneltalks.com server12

To confirm your FQDN, run below command :

root@server12 # hostname -f
server12.kerneltalks.com

Output should be hostname.domain name

Step 2.

Configure domain name in Red Hat RHEL, Fedora and CentOS

Add below line in /etc/sysconfig/network

DOMAINNAME=<domainname>

Add below parameter in /etc/sysctl.conf

kernel.domainname = <domainname>

Configure domain name in Ubuntu

Edit your hostname (not FQDN) in /etc/hostname file. and restart hostname service. If you see below error :

# service hostname restart
Failed to restart hostname.service: Unit hostname.service is masked.

you can set hostname using :

# hostnamectl set-hostname server12

Once done, confirm normal hostname (using hostname) and FQDN (using hostname -f)

Step 3.

Add domain in /etc/resolv.conf. This file used for setting nameservers as well.

root@server12 # cat /etc/resolv.conf
search kerneltalks.com

This addition makes sure that you can resolves hostnames within your domain.

Step 4.

Confirm that changes are working perfectly. Question is how to check the domain name of the Linux server?

Below are the commands to check hostname, FQDN, and domain name of your server.

root@server12 # hostname
server12

root@server12 # hostname -f
server12.kerneltalks.com

root@server12 #dnsdomainname
kerneltalks.com

hostname command shows your server’s hostname. hostname -f shows your FQDN. dnsdomainname command shows your domain name of the server!