≡ Menu

Linux setting hostname and domain name of my server

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
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:

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:

Share this tutorial on:

Like this? Follow us on Twitter OR support us by using Patreon

{ 10 comments… add one }
  • shuvo009 January 19, 2009, 7:22 pm

    thank you bro. it is really helpfull

  • sanjay Katiyar May 8, 2009, 1:53 pm

    I think we have to restart the network service after making the changes.

    service network restart

  • Raj February 15, 2012, 10:40 pm

    Thank you so much for this information. It was very useful for me!

  • sidharth May 2, 2012, 1:45 am

    Do you also want to tell in your artice about restarting services so the new changes can come to effect? At the moment the article is half baked.

  • ritesh jha May 17, 2012, 6:47 am

    thanks a lot.

  • jim February 5, 2013, 7:05 am

    Thanks a lot from a CentOS newbie.

  • sandeep yadav June 24, 2013, 9:37 am

    hi I want to learn linux .what step should i follow?

  • Nilesh July 23, 2013, 4:54 am

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

    Step2: Change the New Values in the network file
    [root@erp ~]# cat /etc/sysconfig/network

    Step3: Change the New Values in the sysctl.conf and resolv.conf files
    [root@erp ~]## cat /etc/sysctl.conf

    [root@erp etc]# cat /etc/resolv.conf
    search myappsdba.com
    option attemts : 5
    option timeout :15
    [root@erp etc]#

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

    Step5:Restart the Network or Reboot the system for effecting the changes
    [root@erp ~]# init 6 or

    [root@erp ~]# service network restart

  • Rupesh December 23, 2014, 7:49 am

    Thanks for the good article. @Nilesh Thanks dude

  • handy November 3, 2015, 1:33 pm

    Please help me connect to server with a Linux netbook. There is a box for the name of the server… but I don’t know it.

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , ,