Contents
hostname
: 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).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
$ hostname -h 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 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. |
Show hostname
1 2 |
$ hostname jack14x64 |
Show FQDN
1 2 |
$ hostname -f jack14x64 |
Show domain name
1 |
$ hostname -d |
Temporary change the host name.
This is only effective till a reboot.
1 2 3 4 5 6 7 8 9 10 11 |
$ hostname jack14x64 $ sudo hostname www.phaisarn.com $ hostname www.phaisarn.com $ hostname -f phaisarn.com $ hostname -d com $ hostname -i 150.107.31.46 |
-i คืนค่า ip จริงของโดเมนนั้น ๆ ไม่ได้คืนค่า ip ของ host เรา
Set the fully qualified domain name (FQDN)
ไฟล์ /etc/hosts
เปลี่ยนบรรทัด 127.0.1.1 ให้เป็นชื่อ FQDN ทีต้องการ (hostname.domainname)
1 2 3 4 5 6 7 8 9 10 |
$ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 c1.phaisarn.com c1 # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters |
ไฟล์ /etc/hostname
เปลี่ยนให้เป็นชื่อ hostname ที่ต้องการ
1 2 |
$ cat /etc/hostname c1 |
Show hostname
1 2 |
$ hostname c1 |
Show FQDN
1 2 |
$ hostname -f c1.phaisarn.com |
Show domain name
1 2 |
$ hostname -d phaisarn.com |