Want Complete Linux Host Information? 5 Linux Commands That Can Do the Job

By | 24/06/2013

It is important for system as well as network administrators to be able to access all kind of system and as well as network related Linux host information. This information helps a great deal while debugging system level or network level problems. In this article, I will explain 5 commands (arch, dig, host, hostanme, uname) that will help you get most of host related information from system as well as network point of view.

NOTE- I have used Ubuntu 13.04 to run all the examples shown in this article

 

Linux Host Information

 

1. Linux hostname command

Hostname represents your system name. You can view as well change your hostname using this command.

Here is an example :

$ hostname
mylinuxbook-Inspiron-1525

So, hostname of my Ubuntu box is mylinuxbook-Inspiron-1525. You will observe that hostname usually appears in command prompt of shell also. So, you might want to change it to keep it short and precise.

Here is how you can change it :

$ sudo hostname mylinuxbook

In the command above, I tried to change hostname to ‘mylinuxbook’. Note that I have used ‘sudo’, this is because changing a host name requires root privileges. Once you are done with that, open a new terminal/tab and you will see that the change gets reflected. Even command prompt will contain the new domain name.

But, one problem with the above approach is that the change done is temporary. It will not get reflected after a reboot. In order to change the hostname permanently, just change the content of /etc/hostname file. This change will let your hostname to be changed permanently.

Also, option -F can be used along with hostname command to read hostname from a file and set it temporarily.

2. Linux host command

This command can be used to fetch IP address of a domain name and vice versa. This command is very useful while debugging network issues.

Here are some examples of this command :

Fetch the IP address related information of a domain name by simply passing the domain name as argument to host command.

$ host google.com
google.com has address 74.125.236.72
google.com has address 74.125.236.78
google.com has address 74.125.236.73
google.com has address 74.125.236.71
google.com has address 74.125.236.65
google.com has address 74.125.236.69
google.com has address 74.125.236.66
google.com has address 74.125.236.64
google.com has address 74.125.236.67
google.com has address 74.125.236.68
google.com has address 74.125.236.70
google.com has IPv6 address 2404:6800:4007:801::1004
google.com mail is handled by 10 aspmx.l.google.com.
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 40 alt3.aspmx.l.google.com.
google.com mail is handled by 50 alt4.aspmx.l.google.com.

So we see that IP (v4 and v6) related as well as mail server related information of google.com is fetched.

Print all the DNS records using -a option

$ host -a google.com
Trying "google.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34210
;; flags: qr rd ra; QUERY: 1, ANSWER: 21, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com.            IN    ANY

;; ANSWER SECTION:
google.com.        211    IN    AAAA    2404:6800:4007:800::1009
google.com.        299    IN    MX    10 aspmx.l.google.com.
google.com.        299    IN    MX    50 alt4.aspmx.l.google.com.
google.com.        299    IN    MX    20 alt1.aspmx.l.google.com.
google.com.        299    IN    MX    30 alt2.aspmx.l.google.com.
google.com.        299    IN    MX    40 alt3.aspmx.l.google.com.
google.com.        267    IN    A    74.125.236.168
google.com.        267    IN    A    74.125.236.165
google.com.        267    IN    A    74.125.236.166
google.com.        267    IN    A    74.125.236.167
google.com.        267    IN    A    74.125.236.164
google.com.        267    IN    A    74.125.236.174
google.com.        267    IN    A    74.125.236.163
google.com.        267    IN    A    74.125.236.169
google.com.        267    IN    A    74.125.236.162
google.com.        267    IN    A    74.125.236.161
google.com.        267    IN    A    74.125.236.160
google.com.        136467    IN    NS    ns3.google.com.
google.com.        136467    IN    NS    ns1.google.com.
google.com.        136467    IN    NS    ns4.google.com.
google.com.        136467    IN    NS    ns2.google.com.

Received 412 bytes from 127.0.1.1#53 in 30 ms

Fetch nameserver and SOA related information using -C option

$ host -C google.com
Nameserver 216.239.38.10:
	google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061800 7200 1800 1209600 300
Nameserver 216.239.34.10:
	google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061800 7200 1800 1209600 300
Nameserver 216.239.36.10:
	google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061800 7200 1800 1209600 300
Nameserver 216.239.32.10:
	google.com has SOA record ns1.google.com. dns-admin.google.com. 2013061800 7200 1800 1209600 300

Use -d or -v for verbose information in output

$ host -v google.com
Trying "google.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52674
;; flags: qr rd ra; QUERY: 1, ANSWER: 11, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com.            IN    A

;; ANSWER SECTION:
google.com.        77    IN    A    74.125.236.40
google.com.        77    IN    A    74.125.236.38
google.com.        77    IN    A    74.125.236.34
google.com.        77    IN    A    74.125.236.37
google.com.        77    IN    A    74.125.236.36
google.com.        77    IN    A    74.125.236.41
google.com.        77    IN    A    74.125.236.35
google.com.        77    IN    A    74.125.236.33
google.com.        77    IN    A    74.125.236.46
google.com.        77    IN    A    74.125.236.32
google.com.        77    IN    A    74.125.236.39

Received 204 bytes from 127.0.1.1#53 in 33 ms
Trying "google.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31473
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com.            IN    AAAA

;; ANSWER SECTION:
google.com.        28    IN    AAAA    2404:6800:4007:800::1002

Received 56 bytes from 127.0.1.1#53 in 28 ms
Trying "google.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2871
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com.            IN    MX

;; ANSWER SECTION:
google.com.        13    IN    MX    40 alt3.aspmx.l.google.com.
google.com.        13    IN    MX    50 alt4.aspmx.l.google.com.
google.com.        13    IN    MX    10 aspmx.l.google.com.
google.com.        13    IN    MX    20 alt1.aspmx.l.google.com.
google.com.        13    IN    MX    30 alt2.aspmx.l.google.com.

Received 136 bytes from 127.0.1.1#53 in 29 ms

So this way, host command can be used to fetch a lot of information.

3. Linux arch command

This command is used to fetch the system hardware name. This essentially means name of the processor and system architecture.

Here is the output of this command on my machine :

$ arch
x86_64

So, this means that my machine has 64 bit, x86 series of processor. This command is same as uname -m (which we will discuss later). You can use –version argument to get the version related details.

4. Linux uname command

Uname command can be used to fetch a lot of information related to your system such as OS name, kernel name, Kernel version, kernel release, hostname, network node name etc.

Here are some of the examples :

Print OS name using -o option

$ uname -o
GNU/Linux

Print Kernel name using -s option

$ uname -s
Linux

Print machine hardware name using -m option (note that this is same as arch command output)

$ uname -m
x86_64

For more information on this command. Read our article on Linux uname command.

5. Linux dig command

Dig is a DNS lookup utility. You can use this utility to query domain name servers for lot of information like host addresses, mail exchanges etc.

Here is a basic example of dig :

$ dig google.com

; <<>> DiG 9.9.2-P1 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40090
;; flags: qr rd ra; QUERY: 1, ANSWER: 11, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;google.com.            IN    A

;; ANSWER SECTION:
google.com.        227    IN    A    74.125.236.33
google.com.        227    IN    A    74.125.236.38
google.com.        227    IN    A    74.125.236.46
google.com.        227    IN    A    74.125.236.40
google.com.        227    IN    A    74.125.236.32
google.com.        227    IN    A    74.125.236.37
google.com.        227    IN    A    74.125.236.34
google.com.        227    IN    A    74.125.236.35
google.com.        227    IN    A    74.125.236.41
google.com.        227    IN    A    74.125.236.39
google.com.        227    IN    A    74.125.236.36

;; Query time: 30 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Sat Jun 22 15:38:58 2013
;; MSG SIZE  rcvd: 215

So you can see that a lot of information is received when dig was run to query information for google.com.

To understand complete structure of dig’s output, I would recommend you to read this comprehensive article on dig command.

Leave a Reply

Your email address will not be published. Required fields are marked *