• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Set hostname and FQDN in Ubuntu without reboot

July 23, 2013 by Sharad Chhetri 10 Comments

Set hostname and FQDN in Ubuntu without reboot

I will first start with definition of FQDN because many people have confusion over it. Hostname and FQDN both are little bit different.It is best to give the reference from wikipedia so that there should be no dispute.

FQDN or Fully Qualified Domain Name: With reference form Wikipedia

A fully qualified domain name (FQDN), sometimes also referred as an absolute domain name,[1] is a domain name that specifies its exact location in the tree hierarchy of the Domain Name System (DNS). It specifies all domain levels, including the top-level domain and the root zone.[2] A fully qualified domain name is distinguished by its lack of ambiguity: it can only be interpreted one way. FQDNs first arose out of the need for uniformity as the Internet was quickly growing in size in the late 1980s

For example, given a device with a local hostname myhost and a parent domain name example.com, the fully qualified domain name is myhost.example.com. The FQDN therefore uniquely identifies the device —while there may be many hosts in the world called myhost, there can only be one myhost.example.com. In the Domain Name System, and most notably, in DNS zone files, a fully qualified domain name is specified with a trailing dot. For example,

somehost.example.com.

Hostname : With reference from Wikipedia

A hostname is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication such as the World Wide Web, e-mail or Usenet. Hostnames may be simple names consisting of a single word or phrase, or they may have appended a domain name, which is a name in a Domain Name System (DNS), separated from the host specific label by a period (dot). In the latter form, the hostname is also called a domain name. If the domain name is completely specified including a top-level domain of the Internet, then the hostname is said to be a fully qualified domain name (FQDN).

Example: ‘saturn’ and ‘jupiter’ could be the hostnames of a couple of devices connected to a network called Alpha. Within Alpha the devices are reached by their hostname. Alpha could be configured so that its domain name is ‘alpha’ (in lower case letters). In that case, the mentioned devices’ hostnames, including the domain-name, would be ‘saturn.alpha’ and ‘jupiter.alpha’, respectively. With these names they could be reached in a private network of networks, each with its own domain name. If alpha is registered and can be reached as alpha.net on the Internet, then the fully qualified domain names for the devices would be ‘saturn.alpha.net’ and ‘jupiter.alpha.net’

How to find hostname in linux by command

(1) To get the hostname of system use the below given command

hostname

See the output of command

root@mailubuntu:~# hostname
mailubuntu
root@mailubuntu:~#

How to find FQDN in linux by command

Use the below command in linux to find FQDN

hostname -f

See the below given output

root@mailubuntu:~# hostname -f
mailubuntu.example.com
root@mailubuntu:~#

How to set hostname and FQDN in Ubuntu without reboot

Step 1: Get the ip address of system by using the command ifconfig

Step 2: Edit the /etc/hosts file. And follow the given pattern

IP-Address-of-system hostname.domainname.TLD hostname
eg.
192.168.168.15 mailubuntu.example.com mailubuntu

Here,
Hostname = mailubuntu
Domainname = example
TLD = .com

Note: Read about TLD

FQDN = hostname+domainname+tld
Hence, FQDN = mailubuntu.example.com

While installating Ubuntu, system asked me for giving hostname at that time I gave hostname as mailubuntu. Hence , in /etc/hosts file you can see the line 127.0.1.1 mailubuntu, which is I commented by using # symbol.

So,uncomment the line “127.0.1.1 hostname”
Write new line with this pattern as I described short above

IP-Address-of-system hostname.domainname.TLD hostname
eg.
192.168.168.15 mailubuntu.example.com mailubuntu

See the reference of my system’s /etc/hosts file

root@mailubuntu:~# vi /etc/hosts
127.0.0.1	localhost
#127.0.1.1	mailubuntu
192.168.168.15  mailubuntu.example.com mailubuntu
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
root@mailubuntu:~#

Step 3: Edit /etc/hostname file and give hostname. Here again hostname I am using is mailubuntu

root@mailubuntu:~# vi /etc/hostname
mailubuntu

Step 4 : Now restart the hostname service.

/etc/init.d/hostname restart

or 

/etc/init.d/hostname.sh restart

Step 5: Now check hostname and FQDN by using given below command

hostname  (for hostname)

hostname -f (for FQDN)

See the below help option of hostname command

root@mailubuntu:~# hostname -h
Usage: hostname [-v] [-b] {hostname|-F file} set host name (from file)
hostname [-v] [-d|-f|-s|-a|-i|-y|-A|-I] display formatted name
hostname [-v] display host name

{yp,nis,}domainname [-v] {nisdomain|-F file} set NIS domain name (from file)
{yp,nis,}domainname [-v] display NIS domain name

dnsdomainname [-v] display dns domain name

hostname -V|–version|-h|–help print info and exit

Program name:
{yp,nis,}domainname=hostname -y
dnsdomainname=hostname -d

Program options:
-s, –short short host name
-a, –alias alias names
-i, –ip-address addresses for the host name
-I, –all-ip-addresses all addresses for the host
-f, –fqdn, –long long host name (FQDN)
-A, –all-fqdns all long host names (FQDNs)
-d, –domain DNS domain name
-y, –yp, –nis NIS/YP domain name
-b, –boot set default hostname if none available
-F, –file read host name or NIS domain name from given file

Description:
This command can get or set the host name or the NIS domain name. You can
also get the DNS domain or the FQDN (fully qualified domain name).
Unless you are using bind or NIS for host lookups you can change the
FQDN (Fully Qualified Domain Name) and the DNS domain name (which is
part of the FQDN) in the /etc/hosts file.
root@mailubuntu:~#

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. How to change hostname or FQDN in CentOS and Redhat
  2. How to set hostname and FQDN on CentOS 7 and RHEL 7
  3. Add swap file in linux without reboot after OS installation
  4. How to change hostname in Ubuntu 12.04 and 12.10 without system restart
  5. Edit the crontab without using crontab -e
  6. Find mysql commands history without mysql server login
  7. Yum command to download rpm file without installing in linux system
  8. linux command to list the files from rpm package without extracting
  9. vi : Edit file without opening it
  10. Print grep command output without seperator

Filed Under: Linux Tagged With: hostname

Reader Interactions

Comments

  1. Rohit says

    October 27, 2015 at 11:07 am

    In my system hostname or FQDN both are same, How should I change my FQDN.

  2. Geoff says

    October 17, 2015 at 6:15 am

    Actually from Ubuntu 13 onward, the command is `sudo hostnamectl set-hostname new.fqdn.here`

    http://askubuntu.com/a/516898

  3. Geoff says

    October 17, 2015 at 6:08 am

    On Ubuntu 14.04 LTS there is no /etc/init.d/hostname and `sudo service hostname restart` generates this output stop: Unknown instance: hostname stop/waiting. I think sudo service networking restart works though.

  4. nashtrik says

    April 5, 2015 at 3:56 pm

    Thanks for a quick reply Sharad… all I want is that whatever mail I compose in mutt and send through postfix should reach its destination, and yes, it will also include messages through mixmaster remailer.
    Now you will have to guide whether I should purchase a domain name or not, or are there other methods to do so (including setting own postfix mail server…..). I have BSNL India as my ISP, if this info is of any use.
    Thanks.

  5. sharad chhetri says

    April 5, 2015 at 6:19 am

    Hello Nashtrik,

    The post is about setting Hostname and FQDN of your system. It is not related to get domain name. You have to buy domain name first from Domain Registerar like Godaddy, namecheap, name.com etc. They are tons of lot domain registerar. select anyone.

    You have to configure postfix . In case you are considering to make it mail server in public domain, then domain name is required to purchase. Setting own mail server has different steps. Let me know if you want to work on postfix mail server.

    Regards
    Sharad

  6. nashtrik says

    April 5, 2015 at 5:11 am

    Dear Sharad,
    Still confused after with domain name / domain address.All my sent mails through mutt and postfix in 14.04 remain undelivered and are returned back to me vide error 742, citing reason for failure as ” fully qualified address required”.
    Consider me a novice in linux. Suppose my computer is ‘ abc@xyz:~$’.
    What is my hostname in this ? I do not have any ‘domain’. Now could you instruct me from scratch how to get a domain name or address and howto configure postfix so that all my mails are delivered to their addressees. I do not want them to be sent through gmail or other MSP facility ,but through postfix…
    Thanks….

  7. sharad chhetri says

    February 6, 2015 at 11:07 am

    Welcome Friends 🙂

  8. fatman13 says

    February 6, 2015 at 9:12 am

    Very well explained. Thanks!

  9. sharad chhetri says

    September 26, 2013 at 4:40 pm

    Thanks Marcelo

  10. Marcelo Lunardi says

    September 26, 2013 at 2:13 pm

    Great man, exactly!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Commands

How To Find Absolute Full Path Of Command On Linux / Unix : which command

How to set motd in linux

What is Linux/Unix Internal And External Command

Learn Linux Date Command With Examples

type Command : Display Information About Command Type On Linux

Install lxml by using pip command on Ubuntu 14.04 LTS

smbpasswd command not found on CentOS 7 and RHEL 7

Explore 70+ Articles On Linux Commands

Always Useful Tips And Tricks

How to change login banner message in GUI mode in CentOS 6 or above version.

fatal error: error writing to /tmp/ccwAjc9Z.s: No space left on device

Do not show line haveing particular keyword by grep command

linux release renew dhcp assigned ip address

Error installing rails

How to encode and decode the strings with base64

How to forcefully send mail from mailq in sendmail MTA

Explore 90+ Article On "Linux Tips And Tricks"

You Might Like These Articles!

Linux basic command

Linux Basic Commands With Examples For Every Beginner

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Copyright © 2023 ·
The material in this site cannot be republished either online or offline, without our permission but Schools and Colleges can do in their Private Network
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy