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.
The procedure to find the computer name on Linux:
- Open a command-line terminal app (select Applications > Accessories > Terminal), and then type:
- hostname
OR
hostnamectl
OR
cat /proc/sys/kernel/hostname - Press [Enter] key
Linux find hostname using hostnamectl
Type the following command if you are using systemd based distro:
$ hostnamectl
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 Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 6 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
which command is used for finding the server name…….???????
Which command is used to find OS version by using IP address or hostname?
nmap -O
how to change my computer name in linux mint 17-
how to know computer name linuxmint 17
How to find the DNS server and search domains
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.