1

I have installed two things :

A wi-fi access point through this tutorial:
https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point

And an Apache server from this tutorial:
https://www.raspberrypi.org/documentation/remote-access/web-server/apache.md

Now, from my phone for example, I can freely connect to my wi-fi access point and then access the Apache server using the address 192.168.42.1.

But I do not know how to assign a hostname, so that I can access my Apache server using a link like

http://my-raspberry-pi

instead of

http://192.168.42.1
MrWhite
  • 103
  • 6
user62724
  • 11
  • 1
  • 2

2 Answers2

2

As Steve Robilliard has stated the Pi already has a hostname, raspberrypi by default.

You should be able to address it with raspberrypi.local, although this relies on the avahi service (which is running on normal Raspbian). The use of it is discusssed in How do I set up networking/WiFi/Static IP.

If you want to change the hostname, it is STRONGLY recommended that you do this with raspi-config, which correctly changes ALL the files needed.

If you do it manually BOTH /etc/hosts and /etc/hostname need to be consistent (or you will get inexplicable error messages from some commands).

Milliways
  • 62,573
  • 32
  • 113
  • 225
0

You can set the hostname that the Apache webserver responds to using the ServerName directive in the Apache config file.

For example:

ServerName my-raspberry-pi:80

(on port 80)

However, unless the hostname is defined in a public DNS server (that points to your local Apache webserver), then you also need to configure the HOSTS file on each machine from which you want to access the Apache webserver and set the IP address that should be used for this hostname. For example:

192.168.42.1  my-raspberry-pi
MrWhite
  • 103
  • 6