How do I get the host name from
/etc/hosts
? by writinghostname
?
And what about the dns domain name, how do I get that?
How do I get these names through the commandline?
Answer
When you type
hostname
it will show you the value that is stored in
/etc/hostname
See hostname --help
for a lot of options. From the help …
-s, --short short host name
-a, --alias alias names
-i, --ip-address addresses for the host name
-I, --all-ip-addresses all addresses for the host
-f, --fqdn, --long long host name (FQDN)
-A, --all-fqdns all long host names (FQDNs)
-d, --domain DNS domain name
-y, --yp, --nis NIS/YP domain name
-b, --boot set default hostname if none available
-F, --file read host name or NIS domain name from given file
This command can get or set the host name or the NIS domain name. You can also get the DNS domain or the FQDN (fully qualified domain name). Unless you are using bind or NIS for host lookups you can change the FQDN (Fully Qualified Domain Name) and the DNS domain name (which is part of the FQDN) in the /etc/hosts file.
So
hostname -f
for the long host name (FQDN).
Attribution
Source : Link , Question Author : dada dudu , Answer Author : Rinzwind