The hostname
command in Bash is used to display or set the system’s hostname, which is the name that identifies the machine on a network. It plays a crucial role in network communication and can be used to configure how the system is recognized by other devices.
The basic syntax of the hostname
command is as follows:
hostname [options] [arguments]
-a
, --alias
: Display the alias name of the host.-d
, --domain
: Show the domain name of the host.-f
, --fqdn
: Display the fully qualified domain name (FQDN).-i
, --ip-address
: Show the IP address associated with the hostname.-s
, --short
: Display the short hostname (without domain).-V
, --version
: Show the version of the hostname command.Here are some practical examples of using the hostname
command:
hostname
hostname -f
hostname -s
hostname -i
sudo hostname new-hostname
/etc/hosts
file to reflect the new hostname for local resolution.hostnamectl
command on systems with systemd
for more advanced hostname management, including setting static, transient, and pretty hostnames.