The hostname command may be multifunctional

It's not so versatile, but there are quite a few options. You can return the result with alias or 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.

Both yp and dns are symbolic links.

$ 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

Why don't you try the sauce to take a break? Download the source with 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] It's often done in UNIX to change the behavior. This kind of thing used to be a hard link, but I wonder if it's different now.

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

The hostname command may be multifunctional
PyQtGraph may not be available in the interpreter.
The problem that the ifconfig command cannot be used
Python note: When the pip command cannot be used
The story of stopping the production service with the hostname command
About the service command
Install the pip command
Linux delete command when only the folder cannot be deleted
Clone using the dd command
Speed up the netstat command
Until the shell finds the command
Python standard module that can be used on the command line