What command can you use to list the hosts defined on a domain

You can use a hosts file or a domain name server to resolve host names and IP addresses on a stand-alone or distributed deployment.

Resolving host names with a DNS server

If you are using a name server or DNS server to resolve host names, the host name must be configured on the DNS server. The host name you configure on the DNS server must also match the host name configured in the operating system.

  1. To check the host name on the operating system, in a command prompt, type:

    hostname

    For example: If the computer is ibm1, the system displays the following result:ibm1

  2. Verify the computer name information:
    1. Right-click My Computer.
    2. Click Properties.
    3. Click the Computer Name tab.
    4. Verify that the Full computer name field displays the fully qualified domain name of the computer. For example ibm1.example.com

      Note: To view the NetBIOS name for the local computer, click Change, then click More. Alternatively, in a command prompt, type nbtstat -n.

  3. Check the host name configured on the DNS server. Run the following command:

    nslookup host_name

    Where host_name is the host name.

    The nslookup command returns the fully qualified domain name configured on the DNS server. For example: ibm1.example.com.

  4. Check that the host is responding. You can run the following command:

    ping host_name

    Where host_name is the host name.

    Note: In some environments, the ping command might fail if the computer is configured to ignore ping requests. Check with your network administrator for alternative ways, if the problem persists.

Resolving host names with a hosts file

Domain names or IP addresses on a local computer can be resolved by adding entries in the local hosts file on a computer. Entries in the local hosts file have the added advantage that the system can run the application server, even when disconnected from the network. If you are using a hosts file to resolve IP addresses, the file must be configured correctly.

The location of the hosts file for:Windows SystemDrive:\Windows\System32\Drivers\etc\ Linux /etc/hosts

The file must include the following information:

  • The IP address, fully qualified domain name, and the host name of the computer.
  • The IP address 127.0.0.1, the fully qualified domain name localhost.localdomain, and the host name localhost.
For example: for a computer with a host name ibm1, the hosts file might contain the following entries:

#IP address Fully Qualified Domain Name Short Name 102.54.11.38 ibm1.example.com ibm1 127.0.0.1 localhost.localdomain localhost

Introduction

The Linux hostname command is used to view or change a system’s domain and hostname. It can also check a computer’s IP address.

In this tutorial, we will cover all the ways you can use the hostname command on Linux and how to change your computer’s hostname on a Linux system.

Prerequisites

  • A system running Linux
  • Access to the command line / terminal window

The hostname command uses the following format:

hostname [options] [new_hostname]

Use the [options] parameter to add more specific instructions to the hostname command. Without it, the default output shows your computer’s hostname:

Use the [new_hostname] parameter when you want to change your computer’s hostname.

The hostname command has a number of options you can use for more specific outputs:

  • -a, --alias: Displays the alias name of the host.
  • -A, --all-fqdns: Displays every FQDN (Fully Qualified Domain Name) of the computer.
  • -b, --boot: Always set a hostname.
  • -d, --domain: Display DNS domain name.
  • -f, --fqdn, --long: Display the FQDN.
  • -F, --file: Check a file to recover and display the hostname.
  • -h, --help: Print the help message as the output.
  • -i, --ip-address: Display the computer’s IP address.
  • -I, --all-ip-addresses: Display all of the computer’s network addresses.
  • -s, --short: Display the short version of the hostname.
  • -v, --verbose: Expand all output to verbose.
  • -y, --yp, --nis: Display the NIS domain name.

Using the hostname command without any additional options displays the computer’s hostname:

hostname

Use the -s or --short option to display the short version of the hostname, which is cut off at the first dot:

hostname -s hostname --short

Use the -a or --alias option to display the alias (substitute hostname) of the host if one is set. There are very few cases where this option is useful, and its use is no longer recommended.

hostname -a hostname --alias

Use the -F or --file option to search a specific file (such as hostname or hosts) and change your computer’s hostname to match the content of the file:

sudo hostname -F [file path] sudo hostname --file [file path]

Note: When using the -F or --file options, also specify the path to the file you want to check.

If you don’t want to have a specific file containing the hostname, or want to leave that file empty, use the -b or --boot option. This makes your computer use the default hostname (localhost) until you set a different one:

hostname -b hostname --boot

Use the -d or --domain option to display the name of your DNS domain:

hostname -d hostname –domain

If you want to display a system’s FQDN, use the -f, --fqdn, or --long option:

hostname -f hostname --fqdn hostname --long

A FQDN contains the short hostname and the DNS domain name.

To display each FQDN of your machine, use the -A or --all-fqdns option:

hostname -A hostname --all-fqdns

This option lists out all of your network addresses and their DNS domain names. It skips any addresses that it can’t translate.

Note: Different network addresses may translate to same DNS domain names. This can result in duplicate output entries when using -A or --all-fqdns options.

If you’re using NIS (Network Information Service), you can check your NIS domain name with the -y, --yp, or --nis option:

hostname -y hostname --yp hostname --nis

Use this command with the following format to change your NIS domain name:

sudo hostname -y [NIS hostname] sudo hostname --yp [NIS hostname] sudo hostname --nis [NIS hostname]

The hostname command also lets your display network addresses tied to a hostname. To do this, use the -i or --ip-address option:

hostname -i hostname --ip-address

This command only works if the hostname can be resolved.

Use the -I or --all-ip-addresses option to display all of the host’s network addresses. Unlike -i, this option doesn’t depend on hostname resolution:

hostname -I hostname --all-ip-addresses

You can change your computer’s hostname with the hostname command. To do this, use the following format:

sudo hostname [new hostname]

Any changes to the hostname you make using this command will only last until the next reboot.

To change the hostname permanently, use a text editor like Nano to make changes to the hostname and hosts files:

sudo nano /etc/hostname sudo nano /etc/hosts

You can also use the hostnamectl command to permanently change the hostname:

sudo hostnamectl set-hostname [new hostname]

Use the -V or --version option to print out the version of the hostname software package on your Linux system:

hostname -V hostname --version

If you need help with any of the commands, use the -h or --help option to print out a help message:

hostname -h hostname --help

Conclusion

After following this guide, you now know how to use the hostname command in Linux and all the options that can extend its use.

For more Linux commands, check out our Linux Commands Cheat Sheet.

Última postagem

Tag