0

I have a situation like this:

raspi3-netw-02

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:

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.

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?

sdbbs
  • 1,127
  • 4
  • 16
  • 22
  • 1
    The simplest solution is to configure the Ubuntu/Windows PC as the DNS server for the entire network. By doing that you can define hostnames for the network and point them to any ip address you want. – Ramhound Jan 26 '17 at 14:20
  • Thanks @Ramhound - but this RPi is maybe not going to be used on the same local network as the one described in the question, so I need a more general solution - if such exists... – sdbbs Jan 26 '17 at 14:29
  • 1
    If that is the case you will have to edit the hosts file itself and add entry for each client. This means your clients and servers will have to have static intranet ip address, and each time you add a client to the network, you will have to update the file. of course if the RPi isn't going to be on the network, then the clients on the network, wouldn't be able to communicate with it anyways. – Ramhound Jan 26 '17 at 14:33
  • Thanks @Ramhound - with "edit the hosts file", do you mean `/etc/hosts` on the RPi only, or the `hosts` file on each and every PC on the local network? Either way, managing hosts files with static IPs will still not help me (I don't really know the local network topology where the RPi could be used), I'm looking for something automatic... Since I run `dnsmasq` on the RPi, I was hoping I could modify it (or `dhcpcd`?) so it responds with an IP once it gets a request looking up its name - but couldn't find any examples so far... – sdbbs Jan 26 '17 at 14:37
  • 2
    All of the above. If you can't use a central DNS server where you add/remove machines to it, then you have to add/remove the host names for every machine on each client (or at least the DHCP servers). – Ramhound Jan 26 '17 at 14:40
  • 1
    What's a bit strange is that you only changed the RPi hosts file but do see that change on the Ubuntu machine. My assumption would be (as you mentioned it) that your mDNS installation isn't properly handeled on your Ubuntu machine but Windows understands how to work with it. If you really want this to work for all machines without special configuration you probably need to setup a full fleged DNS server on the Pi and let your router announce it as the DNS server to use. – Seth Jan 27 '17 at 09:39

0 Answers0