Ce n'est pas si polyvalent, mais il existe de nombreuses options. Vous pouvez renvoyer le résultat avec alias ou fqdn.
$ hostname --help
Usage: hostname [-b] {hostname|-F file} set host name (from file)
hostname [-a|-A|-d|-f|-i|-I|-s|-y] display formatted name
hostname display host name
{yp,nis,}domainname {nisdomain|-F file} set NIS domain name (from file)
{yp,nis,}domainname display NIS domain name
dnsdomainname display dns domain name
hostname -V|--version|-h|--help print info and exit
Program name:
{yp,nis,}domainname=hostname -y
dnsdomainname=hostname -d
Program options:
-a, --alias alias names
-A, --all-fqdns all long host names (FQDNs)
-b, --boot set default hostname if none available
-d, --domain DNS domain name
-f, --fqdn, --long long host name (FQDN)
-F, --file read host name or NIS domain name from given file
-i, --ip-address addresses for the host name
-I, --all-ip-addresses all addresses for the host
-s, --short short host name
-y, --yp, --nis NIS/YP domain name
Description:
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.
Les deux yp et dns sont des liens symboliques.
$ rpm -ql hostname-3.13-3.el7.x86_64 | grep bin | xargs ls -li
33663457 lrwxrwxrwx. 1 root root 8 Jan 20 2015 /bin/dnsdomainname -> hostname
33663500 lrwxrwxrwx. 1 root root 8 Jan 20 2015 /bin/domainname -> hostname
33663501 -rwxr-xr-x. 1 root root 15768 Jun 10 2014 /bin/hostname
33663502 lrwxrwxrwx. 1 root root 8 Jan 20 2015 /bin/nisdomainname -> hostname
33663503 lrwxrwxrwx. 1 root root 8 Jan 20 2015 /bin/ypdomainname -> hostname
Pourquoi n'essayez-vous pas la sauce pour faire une pause? Téléchargez le source avec yum-utils.
$ yum install yum-utils
$ yum --downloadonly --source hostname
$ rpm -ivh hostname-3.13-3.el7.src.rpm
$ rpm2cpio hostname-3.13-3.el7.src.rpm| cpio -id
$ tar xvzf hostname_3.13.tar.gz
argv [0] C'est souvent fait sous UNIX pour changer le comportement. Ce genre de chose était autrefois un lien dur, mais je me demande si c'est différent maintenant.
hostname.c
/* If called as 'dnsdomainname', by default show the DNS domain name. */
progname = (rindex(argv[0], '/')) ? rindex(argv[0], '/') + 1 : argv[0];
if (!strcmp(progname, "dnsdomainname"))
type = DNS;
else if (!strcmp(progname, "domainname"))
type = NIS;
else if (!strcmp(progname, "ypdomainname"))
type = NIS_DEF;
else if (!strcmp(progname, "nisdomainname"))
type = NIS_DEF;
Recommended Posts