getaliasbyname_r - Linux


getaliasbyname_r is a Linux command used to retrieve alias information for a specified name or alias. It is commonly used in networking and system administration for managing aliases and resolving domain names.


int getaliasbyname_r(const char *name, struct hostent *result, char *buffer, size_t buflen, int *h_errnop);


| Option | Description | Default |
| name | The name or alias to lookup. | |
| result | A pointer to a hostent structure to receive the alias information. | |
| buffer | A buffer to store the returned data. | |
| buflen | The size of the buffer. | |
| h_errnop | A pointer to a variable that will receive an error code. | |


Lookup alias information for a given name:

#include <netdb.h>

int main() {
    struct hostent *result;
    char buffer[1024];
    int h_errnop;

    if (getaliasbyname_r("", result, buffer, sizeof(buffer), &h_errnop) == 0) {
        printf("Alias information for\n");
        printf("Name: %s\n", result->h_name);
        printf("Aliases: ");
        for (char **alias = result->h_aliases; *alias != NULL; alias++) {
            printf("%s ", *alias);
    } else {
        printf("Error: %s\n", hstrerror(h_errnop));

    return 0;

Common Issues

Error code 1 (HOST_NOT_FOUND): The specified name or alias does not exist.

Error code 3 (TRY_AGAIN): The DNS server is temporarily unavailable. Retry later.


getaliasbyname_r can be combined with other commands for advanced tasks:

  • nslookup to perform DNS lookups:
nslookup | getaliasbyname_r -

Related Commands

  • gethostbyname_r – Retrieve host information from a name.
  • getaddrinfo – Resolve a host name or service name to a list of addresses.
  • dns – Perform DNS lookups and administration.