To make it easier to access the Raspberry Pi from the local network we want to create a local name so that we can access from our computer using a name rather than an IP address.
Setting a hostname is easier to remember, more convenient to type, and generally better for managing multiple devices on a network.
By default, the Raspberry Pi hostname is raspberrypi, but if you have multiple Pi’s on the same network you’ll probably want to set a unique hostname for each. Otherwise, you’ll have issues with SSH timing out when attempting to connect.
So we want to create new host name that looks like: webserver
If you have already done this change using the Raspberry Pi Preferences -> Raspbery Pi Configuration menu option, then you don’t need to do anything else. Changing the name in the GUI display will make the changes in all the required files.
However, you can do the changes using the terminal as follows:
Edit the /etc/hosts file:
You’ll see a line like this:
Replace raspberrypi with your desired hostname, save, and quit.
Edit the /etc/hostname file
By default, this file contains only the name raspberrypi. Again, replace this with your desired hostname. Updating this file will ensure that the hostname remains set upon the next reboot.
So, now once the web site is set up, we will be able to access it using the host name http://webserver rather than using the IP address or using an internet URL.