O'Reilly logo

Linux Pocket Guide, 2nd Edition by Daniel J. Barrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

hostname — stdin  stdout  - file  -- opt  --help  --version

Synopsis

hostname [options] [name]

The hostname command prints the name of your computer. Depending on how you have things set up, this might be the fully qualified hostname:

$ hostname
myhost.example.com

or your short hostname:

$ hostname
myhost

You can also set your hostname, as root:[19]

# hostname orange

However, hostnames and nameservers are complicated topics well beyond the scope of this book. Don’t just blindly start setting hostnames!

Useful options

-i

Print your host’s IP address.

-a

Print your host’s alias name.

-s

Print your host’s short name.

-f

Print your host’s fully qualified name.

-d

Print your host’s DNS domain name.

-y

Print your host’s NIS or YP domain name.

-F hostfile

Set your hostname by reading the name from file hostfile.

[19] This change might not survive a reboot. Some Linux distros require additional steps, such as placing the hostname into a configuration file that is read at boot time. Consult the documentation for your distro.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required