A hostname is the unique name assigned to a Linux machine on a network. It identifies your system for communication, remote access, and configuration.
Methods to Find Hostname in Linux
1. Using hostname Command
- Open a terminal.
- Type
hostnameand press Enter. - The current hostname will be displayed. This method works across most Linux distributions.
2. Using hostnamectl Command
- Type
hostnamectland press Enter. - It shows the static hostname as stored in
/etc/hostname.
3. Checking /etc/hostname File
- Type
cat /etc/hostnameand press Enter. - The hostname stored in the configuration file will be displayed.
4. Using uname Command
- Type
uname -nand press Enter. - This shows the network node hostname.
5. Using nmcli (Network Manager CLI)
- Type
nmcli general hostnameand press Enter. - The hostname will be displayed if Network Manager is installed.
Tips & Notes
- Changing Hostname: Use
sudo hostnamectl set-hostname newnameto update. - Persistence: Editing
/etc/hostnameand/etc/hostsensures the name stays after reboot. - Restrictions: Hostnames can include letters, numbers, hyphens, and periods, up to 253 characters.
- Admin Rights: Viewing the hostname doesn’t require root privileges, but changing it does.
Finding your hostname in Linux is simple and can be done using several commands or configuration files. Each method provides quick access to this essential system detail.
By mastering these techniques, you’ll be able to manage and configure your Linux system more effectively on any network.
