I have a situation like this:
The Raspberry Pi 3 is set up as a WiFi access point (as per https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/) and a web server. I would like to give it a hostname, say myrpi, which will be resolvable on the local network from any client - regardless if they are connected wired or wireless -, such that when I enter the web address http://myrpi into any browser (Firefox, Chrome) on any local PC (Windows, Ubuntu), I would get the webpage served at port 80 on the Raspberry Pi - without changing anything on the web client computers (that is the Windows and Ubuntu PC on the image, if the RPi is a web server)
I found first this:
- http://www.howtogeek.com/167190/how-and-why-to-assign-the-.local-domain-to-your-raspberry-pi/
- http://www.howtogeek.com/167195/how-to-change-your-raspberry-pi-or-other-linux-devices-hostname/
So, I went along it. Now I have on the RPi:
- In
/etc/hosts->127.0.1.1 myrpi - In
/etc/hostname->myrpi
Then I did sudo apt-get install avahi-daemon on the RPi and rebooted.
I then try from the command line on the Ubuntu PC (connected to the RPi as a WiFi client):
$ ping myrpi.local
PING myrpi.local (172.24.1.1) 56(84) bytes of data.
64 bytes from 172.24.1.1: icmp_seq=1 ttl=64 time=1.54 ms
...
$ wget -O- myrpi.local
Resolving myrpi.local (myrpi.local)... 172.24.1.1
Connecting to myrpi.local (myrpi.local)|172.24.1.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
...
<p>This is the default web page for this server.</p>
...
So, this looks good so far - BUT if I enter http://myrpi.local/ as a Web address in either Firefox or Chromium on Ubuntu PC, then I get "Server not found".
This may have something to do with the state of Avahi on Ubuntu:
[SOLVED] Can't access servers in the .local domain on corporate LAN
these do not work in Ubuntu. This is because Ubuntu installs, by default, the AVAHI Zeroconf mDNS system, configures it to "own" the .local domain, and prioritizes it ahead of regular DNS in the hostname resolution order.
- 173804 – [rfe]Add support for Bonjour (Rendezvous/zeroconfig) to browser
- https://stackoverflow.com/questions/29637622/resolve-mdns-local-url-in-browser-address-bar
- PC version of Google Chrome doesn't recognize ".local" domain name
So, I thought, I don't really care about having .local appended to the domain name - I just thought that is how things are supposed to be done. So I tried calling the hostname directly from the Ubuntu PC:
$ ping myrpi
PING myrpi (127.0.1.1) 56(84) bytes of data.
64 bytes from myUbuntuLaptop (127.0.1.1): icmp_seq=1 ttl=64 time=0.022 ms
...
$ wget -O- http://myrpi/
--2017-01-26 13:38:56-- http://myrpi/
Resolving myrpi (myrpi)... 127.0.1.1
Connecting to myrpi (myrpi)|127.0.1.1|:80... failed: Connection refused.
Here not even wget works (and clearly, neither do Firefox or Chromium browsers), although it is clear why - here myrpi resolved to 127.0.1.1, which is what is written in RPi's /etc/hosts verbatim - but once on the Ubuntu laptop, the same address means "this laptop" as it is a loopback one, and since I have no webserver running on the Ubuntu laptop, the whole process fails.
Now - here is the funny thing: in this setup, the Windows PC (I think Windows 7), myrpi.local resolves to 192.168.0.51 -- and the webpage of http://myrpi.local/ works fine in both Firefox and Chrome on Windows?!
As a final measure, I tried changing /etc/nsswitch.conf on the RPi:
# hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4 # original
hosts: files dns mdns4 mdns4_minimal
... and rebooting - however, the browsers on Ubuntu still cannot access http://myrpi/ or http://myrpi.local/. My /etc/resolv.conf on the RPi is still unchanged.
So, how can I give a name (.local or not), resolvable on the local network, to the Raspberry Pi - so that any other PC on the same local network can retrieve the webserver content from the Raspberry Pi, regardless of OS and browser running on that PC?
