linux hostname和host啥区别?


hostname是第一次听说啊。HOST我知道他就相当于一个DNS解析,但是hostname呢,百度了一下也没看太懂是啥意思。

hosts linux运维 hostname centos Linux

Tomaxh 9 years, 8 months ago

hostname是主机名,用来标识你的机器.如果你同时连接到多台主机进行操作,这时,主机名就能用来区分你到底
目前使用的是哪一台机器了!如果主机名都一样......

deleted answered 9 years, 8 months ago

hostname就是主机名,还可以通过cat /proc/sys/kernel/hostname查看
改主机名一般是改/etc/sysconfig/network这个文件,需要重启网络;或者用hostname命令改,但重启后会恢复
/etc/hosts功能相当于DNS,记录IP到主机名/域名的映射

手撕老咩咩 answered 9 years, 8 months ago

【hostname】命令: 显示主机名&修改主机名。
如:


 [root@localhost ~]# hostname
localhost.localdomain

【host】命令: 把一个主机名解析到一个网际地址或把一个网际地址解析到一个主机名。
如:


 [root@localhost ~]# host -a  www.baidu.com
Trying "www.baidu.com"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 659
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 2, ADDITIONAL: 4

;; QUESTION SECTION:
;www.baidu.com.                 IN      ANY

;; ANSWER SECTION:
www.baidu.com.          3600    IN      MX      10 kw-mx.gw.nic.fujitsu.com.
www.baidu.com.          3600    IN      MX      10 yt-mx.gw.nic.fujitsu.com.

;; AUTHORITY SECTION:
.                       2921    IN      NS      kw-root.gw.nic.fujitsu.com.
.                       2921    IN      NS      yt-root.gw.nic.fujitsu.com.

;; ADDITIONAL SECTION:
kw-mx.gw.nic.fujitsu.com. 159   IN      A       10.0.238.35
yt-mx.gw.nic.fujitsu.com. 73    IN      A       10.134.59.35
yt-root.gw.nic.fujitsu.com. 287 IN      A       10.134.61.144
kw-root.gw.nic.fujitsu.com. 74  IN      A       10.0.238.36

Received 196 bytes from 10.167.129.6#53 in 101 ms

关于两个命令的详细使用说明可以自己查看linux命令的帮助文档。
【hostname】


 [root@localhost ~]# hostname --help
Usage: hostname [-b] {hostname|-F file}         set host name (from file)
       hostname [-a|-A|-d|-f|-i|-I|-s|-y]       display formatted name
       hostname                                 display host name

       {yp,nis,}domainname {nisdomain|-F file}  set NIS domain name (from file)
       {yp,nis,}domainname                      display NIS domain name

       dnsdomainname                            display dns domain name

       hostname -V|--version|-h|--help          print info and exit

Program name:
       {yp,nis,}domainname=hostname -y
       dnsdomainname=hostname -d

Program options:
    -a, --alias            alias names
    -A, --all-fqdns        all long host names (FQDNs)
    -b, --boot             set default hostname if none available
    -d, --domain           DNS domain name
    -f, --fqdn, --long     long host name (FQDN)
    -F, --file             read host name or NIS domain name from given file
    -i, --ip-address       addresses for the host name
    -I, --all-ip-addresses all addresses for the host
    -s, --short            short host name
    -y, --yp, --nis        NIS/YP domain name

Description:
   This command can get or set the host name or the NIS domain name. You can
   also get the DNS domain or the FQDN (fully qualified domain name).
   Unless you are using bind or NIS for host lookups you can change the
   FQDN (Fully Qualified Domain Name) and the DNS domain name (which is
   part of the FQDN) in the /etc/hosts file.

【host】


 [root@localhost ~]# host --help
host: illegal option -- -
Usage: host [-aCdlriTwv] [-c class] [-N ndots] [-t type] [-W time]
            [-R number] [-m flag] hostname [server]
       -a is equivalent to -v -t ANY
       -c specifies query class for non-IN data
       -C compares SOA records on authoritative nameservers
       -d is equivalent to -v
       -l lists all hosts in a domain, using AXFR
       -i IP6.INT reverse lookups
       -N changes the number of dots allowed before root lookup is done
       -r disables recursive processing
       -R specifies number of retries for UDP packets
       -s a SERVFAIL response should stop query
       -t specifies the query type
       -T enables TCP/IP mode
       -v enables verbose output
       -w specifies to wait forever for a reply
       -W specifies how long to wait for a reply
       -4 use IPv4 query transport only
       -6 use IPv6 query transport only
       -m set memory debugging flag (trace|record|usage)

☆凤凰院凶真☆ answered 9 years, 8 months ago

Your Answer