Linux setting hostname and domain name of my server

Posted on in Categories , , , , last updated October 21, 2007

Q. I would like to change hostname and domain name for my Linux server. Where can I set the local hostname and domain name of my server?

A. You can use hostname command to show or set the system’s host name and dnsdomainname command to show the system’s DNS domain name. But the changes are temporary if you use these commands.

Local hostname and domain name of your server defined in text configuration located in /etc directory.

If you are using Red Hat or Fedora Linux
Use redhat-config-network GUI tool. Type following command and click on DNS tab > Setup hostname and domain name:
# redhat-config-network
On other hand you can edit a text file. Find out and set up the value for HOSTNAME in the file /etc/sysconfig/network:
# vi /etc/sysconfig/network
Setup/replace HOSTNAME
HOSTNAME=web.nixcraft.com
Where, web is hostname and nixcraft.com is your DNS domain name.

If you are using Debian Linux

You need to edit /etc/hostname file and put hostname.domain.com in this file:
# vi /etc/hostname
Set or replace hostname:
web.nixcraft.com

Debian, Suse and other Linux distro support GUI tool called network-admin. Type following command and click on DNS tab > Setup hostname and domain name:
$ network-admin

Please note that you must have properly configured DNS server to work FQDN based hostname. See how to configure Linux as a dns client.

See also:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

10 comment

  1. Step1: Change the New Values in the Host file
    [[email protected] ~]# cat /etc/hosts
    # Do not remove the following line, or various programs
    # that require network functionality will fail.
    127.0.0.1 localhost.localdomain localhost
    192.168.0.1 erp.myappsdba.com erp
    [[email protected] ~]#

    Step2: Change the New Values in the network file
    [[email protected] ~]# cat /etc/sysconfig/network
    NETWORKING=yes
    NETWORKING_IPV6=no
    HOSTNAME=erp.myappsdba.com
    GATEWAY=192.168.0.3

    Step3: Change the New Values in the sysctl.conf and resolv.conf files
    [[email protected] ~]## cat /etc/sysctl.conf
    kernel.hostname=erp.myappsdba.com
    kernel.domainname=myappsdba.com

    [[email protected] etc]# cat /etc/resolv.conf
    search myappsdba.com
    nameserver 192.168.0.7
    nameserver 192.168.0.2
    option attemts : 5
    option timeout :15
    [[email protected] etc]#

    Step4:Ping the Host Name or Changed IP Address.
    [[email protected] etc]# ping myappsdba.com
    PING myappsdba.com (192.168.0.1) 56(84) bytes of data.
    64 bytes from fortedc.myappsdba.com (192.168.0.1): icmp_seq=1 ttl=128 time=1.06 ms

    Step5:Restart the Network or Reboot the system for effecting the changes
    [[email protected] ~]# init 6 or

    [[email protected] ~]# service network restart

Leave a Comment