Home  >  Q&A  >  body text

centos - linux hostname和host啥区别?

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

迷茫迷茫2741 days ago689

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-17 13:34:10

    [hostname] command: Display host name & modify host name.
    For example:

    [root@localhost ~]# hostname
    localhost.localdomain

    【host】Command: Resolve a host name to an Internet address or resolve an Internet address to a host name.
    For example:

    [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

    For detailed instructions on using the two commands, you can check the help documentation of the linux command yourself.
    【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)

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:34:10

    Hostname is the host name, you can also check it by cat /proc/sys/kernel/hostname
    To change the host name, you usually change the /etc/sysconfig/network file, and you need to restart the network; or use the hostname command to change it, but It will be restored after restarting
    /etc/hosts function is equivalent to DNS, recording the mapping of IP to host name/domain name

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:34:10

    Hostname is the hostname, used to identify your machine. If you are connected to multiple hosts at the same time for operation, then the hostname can be used to distinguish which machine you
    are currently using. !If the host names are all the same...

    reply
    0
  • Cancelreply