Linux Find Out My Machine Name/Hostname

How do I find out my server name (machine name) under a Linux operating systems using the command line or bash shell?

You need to use the hostname command or hostnamectl command. Both commands can either set or show the current host, domain or node name of the system.

ADVERTISEMENTS

The procedure to find the computer name on Linux:

  1. Open a command-line terminal app (select Applications > Accessories > Terminal), and then type:
  2. hostname
    OR
    hostnamectl
    OR
    cat /proc/sys/kernel/hostname
  3. Press [Enter] key

Linux find hostname using hostnamectl

Type the following command if you are using systemd based distro:
$ hostnamectl
Linux Find hostname command
It is possible to filter output using the grep command:
$ hostnamectl | grep 'hostname'
OR simply use the cat command as follows too:
$ cat /proc/sys/kernel/hostname

Linux find computer name using hostname

At the terminal type hostname command:
$ hostname
Sample outputs
vivek-laptop.nixcraft.in
Where,

  • vivek-laptop : You computer name.
  • nixcraft.in : Your dNS domain name.
  • vivek-laptop.nixcraft.in : Your computer name with Fully Qualified Domain Name (FQDN).

To see the domain part of the FQDN (Fully Qualified Domain Name), enter:
$ dnsdomainname
Sample outputs:

nixcraft.in

How Do I Change My Hostname?

The hostname commands set the host name using the following syntax. Please note that only the super-user / root can change the names. To switch to the root user by typing su – and entering the root password, when prompted.
# hostname newhostname.nixcraft.in
# hostname laptop.nixcraft.net.in
# hostnamectl set-hostname laptop.nixcraft.in

You need to edit /etc/hostname or /etc/sysconfig/network file to set hostname permanently. See our previous FAQ about changing hostname using configuration files.

Getting help

I strongly suggest that your read the man pages by typing the man command:
$ man hostname
$ man hostnamectl

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
6 comments… add one
  • sudarshan apite May 28, 2012 @ 10:44

    which command is used for finding the server name…….???????

  • Abdul Dec 11, 2013 @ 16:59

    Which command is used to find OS version by using IP address or hostname?

    • Shankar Damodaran Jun 14, 2015 @ 20:41

      nmap -O

  • mathew Jul 30, 2015 @ 7:23

    how to change my computer name in linux mint 17-
    how to know computer name linuxmint 17

  • Hunter Fuentes Jul 1, 2016 @ 3:44

    How to find the DNS server and search domains

  • Zantar Dec 2, 2017 @ 0:11

    This is incorrect.
    The ‘hostname’ is the ‘shortname’ of the system instance, with the FQDN being the ‘hostname’ with the DNS ‘domain name’ appended (upon using a command to provide it).
    Setting the ‘hostname’ to the FQDN results in “hostname.domainname.domainname” when used (and fails resolution).
    ‘domainame’ is transient, and can change at any time.
    ‘hostname’ is more permanent, referencing the OS ‘instance’ and has nothing to do with the DNS ‘domain’ its currently residing in.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.