About this implementation of hostname

This has been tested on OS/390 V2R5. 

Unlike the hostname command on some other POSIX superset platforms, this version does not support setting the host name. Setting the host name is specific to each AF_INET PFS. 

This hostname command does not currently support binding to a specific PFS via an environment variable or any other mechanism. 

Using the hostname command 

Enter "hostname" to display the full hostname with domain name (if specified to the transport driver). Enter "hostname -s" to see just the host name without the domain name.

You could use your host name in your shell prompt as follows (optimized for speed): 

  • In your shell profile, use something like the following to set the HOSTNAME environment variable:
                                                                    export HOSTNAME=`hostname -s`
    Note that the quote marks are backward quote marks so that "hostname -s" is first executed and then HOSTNAME is set to the output of "hostname -s".
  • Also in your shell profile, use something like the following to put the host name in your shell prompt:
                                                                    export PS1="$HOSTNAME:$LOGNAME:$PWD: >"

Building the hostname command 

Compile it from the shell with the c89 command:
                                                        c89 -o hostname hostname.c

Here is the source for hostname.c:


int main(int argc,char **argv)
  char *dotpos;
  char hostname[2000 ];
  int dontPrintDomain = 0, rc = 0;

  if (argc == 2 &&
    dontPrintDomain = 1;
  else if (argc != 1)
            "Usage: %s [-s]\n"
            "Specify \"-s\" to print the host name without\n"
            "the domain name.\n",
    rc = 1;

  if (!rc)
    rc = gethostname(hostname,sizeof(hostname));
    if (rc)
      rc = 1;
      if (dontPrintDomain)
        dotpos = strchr(hostname,'.');
        if (dotpos)
          *dotpos = '\0';
  return rc;


If you have comments, feel free to reach me, Jeff Trawick, at trawick@us.ibm.com.

Contact IBM

Browse z/OS