hostname コマンド:ホスト名を確認する

コマンドの概要

 「hostname」コマンドは、Linuxシステムのホスト名を表示または設定するために使用されます。ホスト名は、ネットワーク上でシステムを識別するための名前です。

コマンドの主なオプションと説明

オプション説明
-aすべてのホスト名を表示する。ホストの別名(alias)があれば表示する。
-dドメイン名を表示する。
-f「/etc/hostname」ファイルからホスト名を読み込む。
または、FQDN(Fully Qualified Domain Name:完全修飾ドメイン名)を表示する。
-iホストのIPアドレスを表示する。
-s短い形式のホスト名を表示する。
-yNISドメイン名を表示する。
-hヘルプを表示
主なオプションと説明

コマンドの使用例と解説

1.ホスト名の表示

このコマンドは、システムのホスト名を表示します。

$ hostname
localhost.localdomain
2.すべてのホスト名の表示

このコマンドは、すべてのホスト名(ホストの別名ショートホスト名、ドメイン名など)を表示します。

$ hostname -a
localhost.localdomain localhost4 localhost4.localdomain4 
localhost.localdomain localhost6 localhost6.localdomain6
3.IPアドレスの表示

このコマンドは、システムのIPアドレスを表示します。

$ hostname -i
::1 127.0.0.1
4.ヘルプの表示

このコマンドは、ヘルプメッセージを表示します。

$ 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

       {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.

 「hostname」コマンドは、システムのホスト名を管理するための便利なツールです。特定のオプションを使用することで、異なる情報を表示したり、ホスト名を設定したりすることができます。