When the Linux System Administrator takes over a new server, if there is no good handover document, the host information we can get depends on ourselves. A lot of information can be obtained directly from the host through commands. Below we will share with you five commands for obtaining Linux host information. (Note: I am using Ubuntu 13.04)
1. View or change the Linux host name command
$ hostname
mylinuxbook-Inspiron-1525
From the command results you can see that my Ubuntu host name is a mylinuxbook-Inspiron-1525. You may notice that the host name usually appears at the command prompt, so it is more convenient to shorten the host name.
Run the following command to change it:
$ sudo hostname mylinuxbook
Note that the root permission is required to change the host name. Therefore, I used the sudo command to raise the permission. If you run the preceding command, you can open a new terminal and check your new host name in the terminal, the command prompt with the new name is displayed.
However, the host name modified using this command is a temporary function. Once you restart your server, this name will not exist. If you need to permanently modify the host name, you need to modify the/etc/hostname file.
2. Linux host commands
This command allows you to view the IP address of the host,
$ 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.
From the command running result, we can see the host's IP address (IPV4 and IPV6) and mail server-related information.
If you want to view DNS records, you can use the-a parameter.
$ 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
If you need to view the Domain Name Server or SOA information, you can use the-c Parameter
$ 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
Alternatively, you can use the-d or-v parameters to output detailed information.
$ 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
This command allows you to obtain a large amount of host information.
3. Linux arch command
This command allows you to obtain the processor System Architecture Information of the system.
$ arch
x86_64
From the command execution results, my host is a 64-bit x86 series processor.
4. uname command
The arch above can only obtain simple information about the system. If you want more information, you need to use the uname command, the uname command can obtain information such as the operating system name, kernel name, kernel version, host name, and network node.
Use the-o parameter to view the operating system name
$ uname -o
GNU/Linux
Use the-s parameter to view the kernel name
$ uname -s
Linux
Use the-m parameter to view the system architecture information. The result of this parameter is the same as that of the arch above.
$ uname -m
x86_64
You can also try the following command:
$ uname -n
linuxuser-laptop
$ uname -r
2.6.32-21-generic
$ uname -v
#33-Ubuntu SMP Fri Apr 18 08:09:38 UTC 2011
5. dig command
The dig command is a DNS viewing tool. You can use this command to view the host address of the Domain Name Server.
$ 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