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
1
  • on the machines you want to connect from add an entry to the hosts file (google for how to do this based on your OS and version. The Pi already has a hostname which you can check with the hostname command and you can change this if needed via raspi-config. You may also want to add a hosname entry to the hosts file on your Pi as well. Feb 26 '17 at 14:28
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).

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.