在Linux中修改主機(jī)名其實(shí)是一件非常容易的事情,但網(wǎng)上有些帖子在這一塊都說得很復(fù)雜,諸如修改什么配置文件之類的等等,用hostname這個命令我們就可以很輕易地修改了。
我們直接運(yùn)行hostname可以查看目前的主機(jī)名稱,要查看hostname的其它命令參數(shù),運(yùn)行hostname -h如下:
Usage: hostname [-v] {hostname|-F file} set hostname (from file)
domainname [-v] {nisdomain|-F file} set NIS domainname (from file)
hostname [-v] [-d|-f|-s|-a|-i|-y|-n] display formatted name
hostname [-v] display hostname/p>
p>hostname -V|–version|-h|–help print info and exit/p>
p>dnsdomainname=hostname -d, {yp,nis,}domainname=hostname -y/p>
p>-s, –short short host name
-a, –alias alias names
-i, –ip-address addresses for the hostname
-f, –fqdn, –long long host name (FQDN)
-d, –domain DNS domain name
-y, –yp, –nis NIS/YP domainname
-F, –file read hostname or NIS domainname from given file/p>
p>This command can read or set the hostname or the NIS domainname. You can
also read 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.
看到-v的用法了嗎?修改主機(jī)名命令如下:
hostname -v 新的主機(jī)名
這樣就可以了,是不是非常地簡單?