Raspberry Pi_Eng_11.3.1 Setting Host Name


Published Book on Amazon


All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 1
All of IOT Starting with the Latest Raspberry Pi from Beginner to Advanced – Volume 2


출판된 한글판 도서


최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (상)
최신 라즈베리파이(Raspberry Pi)로 시작하는 사물인터넷(IOT)의 모든 것 – 초보에서 고급까지 (하)


Original Book Contents


11.3   Using Host Name

 

11.3.1  Setting Host Name

 

In the Raspberry Pi system, the name of the system itself is called host name. This host name has the function of refering to the Raspberry Pi system itself in the local network. Therefore, when another system in the same network communicates with the Raspberry Pi system, the host name can be used instead of the IP address assigned to the Raspberry Pi system.

 

You can change the host name by using "raspi-config" command or by using the [Raspberry Pi configuration] feature of the Desktop window or by directly modifying the system file for the configuration.

 

 

   How to use "raspi-config" configuration tool

 

To set the host name for the Raspberry Pi system, you can use the "raspi-config" command, which is the tool to configure booting of the Raspberry Pi system. See the description in [9.9.2 Setting Hostname ] for this.

 

 

   How to use [Raspberry Pi configuration] feature of Desktop window

 

If you are connected to the Desktop GUI, the [Raspberry Pi configuration] function can be used. See the description in [9.2.2 How to Configure Using Desktop Window] for details.

 

 

   How to directly modify the system configuration file

 

On the system, the host name is stored in "/etc/hostname" file and "/etc/hosts" file. You can change the host name by directly modifying the contents of the files.

If you look at the contents of the "/etc/hostname" file on your system, it looks like this.

 

pi@raspberrypin ~ $ cat /etc/hostname

Raspberrypi

pi@raspberrypin ~ $ cat /etc/hosts

127.0.0.1       localhost

::1             localhost ip6-localhost ip6-loopback

fe00::0         ip6-localnet

ff00::0         ip6-mcastprefix

ff02::1         ip6-allnodes

ff02::2         ip6-allrouters

 

127.0.1.1       raspberrypi

 

First change the information in the "/etc/hostname" file. This file needs super user privilege, so be sure to use the "sudo" command or do work as the root user. Change the host name in the file.

 

pi@raspberrypin ~ $ sudo nano /etc/hostname

 

 

Next you need to change the information in the "/etc/hosts" file. This file also requires super user privileges, so you must use the "sudo" command or do work as the root user. Change the host name in the file.

 

pi@raspberrypin ~ $ sudo nano /etc/hosts

 

 

To change the hostname, change the last line to the desired name as follows.

 

127.0.0.1           new-hostname  

 

[Nano] is used as an editor here, but you can use another one. When you modify the contents by a suitable text editor, and reboot the system, the changed name can be used as the host name.