labunix's blog

labunixのラボUnix

Raspberry Pi 4B(Ubuntu 20.04)のホスト名を変更する。

■Raspberry Pi 4B(Ubuntu 20.04)のホスト名を変更する。
 デフォルトではubuntu。

$ hostnamectl |awk -F: '{if($1 ~ /ID/){gsub("[0-9a-f]","X",$2);print $1":"$2}else{print $0}}'
   Static hostname: ubuntu
         Icon name: computer
        Machine ID: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
           Boot ID: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  Operating System: Ubuntu 20.04.1 LTS
            Kernel: Linux 5.4.0-1018-raspi
      Architecture: arm64

■FQDNで設定する。

$ sudo hostnamectl set-hostname raspi.myhome.local

■変更後の確認

$ hostnamectl |awk -F: '{if($1 ~ /ID/){gsub("[0-9a-f]","X",$2);print $1":"$2}else{print $0}}'
   Static hostname: raspi.myhome.local
         Icon name: computer
        Machine ID: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
           Boot ID: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  Operating System: Ubuntu 20.04.1 LTS
            Kernel: Linux 5.4.0-1018-raspi
      Architecture: arm64

$ hostname -s
raspi

$ hostname
raspi.myhome.local

$ cat /etc/hostname 
raspi.myhome.local