Host information in linux

Useful ‘host’ Command Examples for Querying DNS Lookups

Host command is a minimal and easy-to-use CLI utility for performing DNS lookups which translate domain names to IP addresses and vice versa. It can also be used to list and verify various types of DNS records such as NS and MX, test and validate ISP DNS server and Internet connectivity, spam and blacklisting records, detecting and troubleshooting DNS server issues among others.

In this article, we will learn how to use host command with a few useful examples in Linux to perform DNS lookups. In previous articles, we showed the most used 8 Nslookup commands for testing and troubleshooting DNS servers and to query specific DNS resource records (RR) as well.

We also explained 10 Linux Dig (Domain Information Groper) commands to query DNS info, it works more like the Nslookup tool. The host utility also works in a similar way and comes preinstalled on most if not all mainstream Linux distros.

With that said, let’s look at these 14 host commands below.

Find the Domain IP Address

This is the simplest host command you can run, just provide a domain name such as google.com to get the associated IP addresses.

$ host google.com google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has IPv6 address 2a00:1450:4009:80b::200e google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com.

Find Domain Name Servers

To find out the domain name servers use the -t option.

$ host -t ns google.com google.com name server ns1.google.com. google.com name server ns2.google.com. google.com name server ns3.google.com. google.com name server ns4.google.com.

Find Domain CNAME Record

To find out the domain CNAME, run.

$ host -t cname mail.google.com mail.google.com is an alias for googlemail.l.google.com.

Find Domain MX Record

To find out the MX records for a domain.

$ host -n -t mx google.com ogle.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com.

Find Domain TXT Record

To find out the TXT records for a domain.

$ host -t txt google.com google.com descriptive text "v=spf1 include:_spf.google.com ~all"

Find Domain SOA Record

You can make host attempt to display the SOA records for specified zone, from all the listed authoritative name servers for that zone with the -C flag.

$ host -C google.com Nameserver 216.239.38.10: google.com has SOA record ns1.google.com. dns-admin.google.com. 156142728 900 900 1800 60 Nameserver 216.239.32.10: google.com has SOA record ns3.google.com. dns-admin.google.com. 156142728 900 900 1800 60 Nameserver 216.239.34.10: google.com has SOA record ns4.google.com. dns-admin.google.com. 156142728 900 900 1800 60 Nameserver 216.239.36.10: google.com has SOA record ns2.google.com. dns-admin.google.com. 156142728 900 900 1800 60

Query Particular Name Server

To query particual domain name server.

$ host google.com ns4.google.com Using domain server: Name: ns4.google.com Address: 216.239.38.10#53 Aliases: google.com has address 172.217.19.46 google.com has address 172.217.19.46 google.com has address 172.217.19.46 google.com has IPv6 address 2a00:1450:4005:808::200e google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com.

Find All Information of Domain Records and Zones

To make a query of type ANY, use the -a (all) option which is equivalent to setting the -v option.

$ host -a google.com Trying "google.com" ;; ->>HEADER

Get Domain TTL Information

To find out domain TTL information.

$ host -v -t a google.com Trying "google.com" ;; ->>HEADER

Use Either IPv4 or IPv6

The -4 or -6 option forces host to use only IPv4 or only IPV6 query transport respectively.

$ host -4 google.com OR $ host -6 google.com

Perform Non-Recursive Queries

The -r option performs non-recursive queries, note that setting this option clears the RD (recursion desired), the bit in the query which host makes.

$ host -rR 5 google.com google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has IPv6 address 2a00:1450:4009:80b::200e google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com.

Set UDP Retries for a Lookup

By default the number of UDP tries is 1, to change it, use the -R flag.

$ host -R 5 google.com google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has IPv6 address 2a00:1450:4009:80b::200e google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 10 aspmx.l.google.com.

Set Query Time Wait for Reply

Using the -W switch, you can instruct host to wait for a reply for the specified time in seconds and if the -w flag is used, it makes host to wait forever for a reply:

$ host -T -W 10 google.com google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has address 216.58.201.46 google.com has IPv6 address 2a00:1450:4009:80b::200e google.com mail is handled by 10 aspmx.l.google.com. google.com mail is handled by 40 alt3.aspmx.l.google.com. google.com mail is handled by 30 alt2.aspmx.l.google.com. google.com mail is handled by 20 alt1.aspmx.l.google.com. google.com mail is handled by 50 alt4.aspmx.l.google.com.

That’s it! In this article, we learned how to use host command with a few useful examples in Linux. Use the feedback form below to share any thoughts with us concerning this guide.

Источник

How to Use the hostname Command in Linux

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.

How to use the Linux hostname command

hostname Command Syntax

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.

hostname Command Examples

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.

Display Hostname

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

Display hostname

Display Short 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

Display short hostname

Display Alias

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

Display alias

Search for Hostnames

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]

Search for hostnames

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

Force Default Hostname

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:

Force default hostname

Display Domain Name

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

hostname -d hostname –domain

Display FQDN

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.

Display All FQDNs

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.

Display NIS Domain

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

Display NIS domain

Change NIS Domain Name

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]

Change NIS domain name

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.

Display related network addresses

Display All Network Addresses

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

Display all network addresses

Change Hostname Until Reboot

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.

Change hostname until reboot

Change Hostname Permanently

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]

Change hostname permanently

Additional hostname Options

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

hostname -V hostname --version

Display hostname version

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

Hostname help output

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.

Источник

How To Get Host Name and Domain Name Of Linux?

Host name is the identifier of a system in the network. Host name can be get with different ways in Linux. Host name is generally put in the /etc/hostname file.

Get Host name By Echoing Host name File

Host name information is stored in a file /etc/hostname . So we can simple print the host name to the terminal with echo command like below.

Get Host name By Echoing Host name File

Get Host name With hostname Command

We can get host name with hostname command. This will only list host name and will not print domain related information.

Get Host name With host name Command

Get Fully Qualified Host name

We can get fully qualified host name which provides full name with domain information.

Get Fully Qualified Host name

Hostname File

Host name file /etc/hostname will only provide host name with fully qualified domain name. There will any no other data in this file.

Change Host name

As the hostname is stored in the /etc/hostname file we can change the hostname by editing this file. We will set the hostname as ubu1 with the following echo command. Keep in mind that in order to change /etc/hostname file we require root privileges which can be get with the sudo command.

$ sudo echo "ubu1" > /etc/hostname

Change Hostname

Get Domain Name

Domain name information is about the systems network configuration.

How To Get Host Name and Domain Name Of Linux? Infografic

Источник

Читайте также:  Flutter vs code linux
Оцените статью
Adblock
detector