How do I get the host name from /etc/hosts? by writing hostname?
And what about the dns domain name, how do I get that?
How do I get these names through the commandline?
2 Answers
When you type
hostnameit will show you the value that is stored in
/etc/hostnameSee 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 fileThis 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 -ffor the long host name (FQDN).
7Presuming you want your local (LAN) IPv4 address....
To avoid your server returning a long string that combines your IPv4 and IPv6 addresses, use this programmatically in a bash script:
LOCALIP=$(hostname -I | awk '{print $1}')Or type this on the CLI:
hostname -I | awk '{print $1}' 2