linux_5 个获取 Linux 主机信息的命令
via:?http://linux.cn/thread/10942/1/1/
Linux 系统管理员在接手一台新的服务器的时候,如果没有好的交接文档,我们可以得到的主机信息就要靠我们自己了。很多信息是可以直接通过命令从主机上获得的,下面就和大家分享 5 个获取 Linux 主机信息的命令。(注:我使用的是 Ubuntu 13.04)
1. 查看或改变 Linux 主机名的命令
$ hostname
mylinuxbook-Inspiron-1525
从命令结果上您可以看到我的 Ubuntu 主机名是 mylinuxbook-Inspiron-1525。您可能会注意到,主机名通常也出现在命令提示符下,所以很多时候我们将主机名改短一些可能会更方便使用。
通过如下命令来改变它:
$ sudo hostname mylinuxbook
注意,改变主机名需要 root 权限,所以我在上面使用了 sudo 命令来提升权限。如果您执行了上面的命令,那么您可以立即打开一个新的终端,在终端中您就能查看到您新的主机名,同时您会看到新的名称的命令提示符。
不过通过这个命令修改的主机名是一个临时功能,一旦您重启您的服务器,这个名称将不会存在。如果您需要永久的修改主机名,那么您需要修改 /etc/hostname 文件。
2. host 命令
这个命令可以让您来查看主机的 IP 信息,
$ 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.
从命令的运行结果我们可以看到主机的 IP (IPV4 和 IPV6)以及邮件服务器相关的信息。
如果您还想查看 DNS 记录,可以使用 -a 参数
$ 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
如果您需要查看域名服务器或者 SOA 信息,可以使用 -C 参数
$ 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
或者您可以使用 -d 或者 -v 参数来输出详细信息
$ 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
这个命令可以让您获得大量的主机信息。
3. ?arch 命令
这个命令可以让您得到系统的处理器系统构架信息。
$ arch
x86_64
从命令执行结果来看,我的主机是 64 位的 x86 系列处理器。
4. uname 命令
上面的 arch 只能得到系统的简单信息,如果想得到更多的信息,我们就需要使用 uname 命令了,uname 命令可以获取到操作系统名称、内核名称、内核版本、主机名、网络节点等信息。
使用 -o 参数来查看操作系统名称
$ uname -o
GNU/Linux
使用 -s 参数来查看内核名称
$ uname -s
Linux
使用 -m 参数来查看系统构架信息,这个参数的得到的结果和上面的 arch 是一样的
$ uname -m
x86_64
还有如下命令您可以试一试:
$ 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 命令
dig 命令是 DNS 查看工具,使用此命令可以查看域名服务器的主机地址
$ 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