0

I've created an access point on my Pi, and created a website. I can connect my pi with an ethernet cable to my laptop (with shared internet) so that the Pi goes into a subnet, and can connect to internet. That allows me to access the website via 192.168.137.xxx. I can also connect to the Pi's wifi network, and can access the website via 192.168.4.1

I've been trying to give it a name instead of an IP address. I've installed avahi, and changed the hostname to "gateway". When I do an IP scan (while connected to laptop), I get gateway.mshome.net, and that lets me view the webpage. When I connect to RPi access point and IP scan, I get raspberrypi. Neither raspberrypi nor raspberrypi.local show the webpage, but 192.168.4.1 still does.

How can I change it so I can connect to the AP, and view the website via gateway.local instead of 192.168.4.1?

Update:
I did set up the Rpi with dnsmasq. So when the Pi is in use, there will be no laptop and no ethernet connection, so there shouldn't be a conflict between the eth0 and wlan0 connection. The end use case is the Pi creates an AP, and devices connect to that AP (all wireless through wlan0) and the goal is to allow them to type gateway.my-wifi.net into the browser instead of 192.168.4.1. Do I set that name (gateway.my-wifi.net) in the dnsmasq config?

Ingo
  • 42,107
  • 20
  • 85
  • 197
Xyver
  • 19
  • 1
  • 2
  • Secondary part, I want to connect to this webpage via other devices (phones, tablets, other computers...) so hopefully i can stick with gateway.local. So far I can access the page with every device I've tested by connecting to the RPis wifi network, and going to 192.168.4.1 – Xyver Aug 24 '18 at 17:59
  • Does the RasPi is connected to the laptop with an ethernet cable? – Ingo Aug 24 '18 at 21:49
  • Yes. Connected via ethernet cable, the laptop shares internet with it. – Xyver Aug 24 '18 at 23:34
  • Is it possible that the laptop is always available when the local network is used? That would simplify the setup. Or must the access point run standalone even without internet access? – Ingo Aug 25 '18 at 00:12
  • It would simplify, but no it wont :/ The idea is we have a bunch of sensors that send out RF signals, the pi collects all the data, and creates a local wifi network. Anyone can come, connect to the wifi network with their device, and see the data from all the sensors organized (I've made a nice website with graphs and such) – Xyver Aug 27 '18 at 17:16

1 Answers1

0

This is an issue with name resolution. So far as I can see from your description we have the following situation. The RasPi is connected to two subnets:

  1. to the subnet 192.168.4.0/24 with interface wlan0 and static ip address 192.168.4.1 that spans the wifi for the access point. With access point we have a managed wifi and the raspi managed it on this subnet.
  2. to the subnet 192.168.137.0/24 with interface eth0 as client. It get its ip address by DHCP from the laptop that act as an router to the internet on this subnet.

There is no routing between wlan0 and eth0 so a subnet is independent from the other. On each subnet is a DHCP server running: one on the RasPi for the wifi and one on the laptop (presented with shared internet) for clients connected to it. If avahi find a DHCP server on its subnet it will never autoconfigure an ip address from range 169.254.0.0/16. This is by specification in RFC3927. See also discussion on Can't SSH by name on stretch; can on jessie. You can verify it very simple with ip addr when avahi is running. The interfaces have only the ip address from the DHCP server. This means you will never find a host with domain .local, e.g. raspberrypi.local in your case.

For name resolution is the DHCP server responsible together with a DNS server, mostly a caching only DNS server on the local system. When the DHCP server gives a new lease (ip address) to a client it also informs the DNS server what hostname it has which caches it. The laptop has this functionality because it defines a dns domain mshome.net so you can address its clients e.g. with gateway.mshome.net.

I don't know how do you setup your access point but on a RasPi usually the software dnsmasq is used to setup a DHCP server and a caching only DNS server. If you also use it then look at its configuration what DNS domain it presents. dnsmasq by default enables its DNS server. Then with the hostname and the domain you should be able to address your hosts on the wifi, e.g. gateway.my-wifi.net.

Update:
With your update I had a look at the man page of dnsmasq and found:

Dnsmasq accepts DNS queries and either answers them from a small, local, cache or forwards them to a real, recursive, DNS server. It loads the contents of /etc/hosts so that local hostnames which do not appear in the global DNS can be resolved and also answers DNS queries for DHCP configured hosts.

I'm not using dnsmasq so I cannot test it, but with an entry in /etc/hosts you should be able to solve your problem. Try it by inserting one or two of these lines into /etc/hosts:

# 127.0.1.1 is often used for the FQDN of the machine
127.0.1.1      gateway.my-wifi.net    gateway
192.168.4.1    gateway.my-wifi.net    gateway

Please give me feedback because im interested in this.

Ingo
  • 42,107
  • 20
  • 85
  • 197
  • Awesome, sounds good. I did set up the Rpi with dnsmasq. So when the Pi is in use, there will be no laptop and no ethernet connection, so there shouldn't be a conflict between the eth0 and wlan0 connection. The end use case is the Pi creates an AP, and devices connect to that AP (all wireless through wlan0) and the goal is to allow them to type gateway.my-wifi.net into the browser instead of 192.168.4.1. Do I set that name (gateway.my-wifi.net) in the dnsmasq config? – Xyver Aug 31 '18 at 23:35
  • @Xyver I have updated my answer. – Ingo Sep 02 '18 at 21:02
  • Hi @Xyver, does the update of my answer help you? Can you resolve names with entries in /etc/hosts? – Ingo Sep 12 '18 at 11:34
  • Just an update, I've tried this without success. I however was not using a subdomain, although I don't think that's relevant. – Renari May 02 '19 at 19:58
  • @Renari What do you try? Do you try to define host names in /etc/hosts and this names are not resolved? – Ingo May 02 '19 at 22:10
  • @Ingo correct now that I think about it it may be because I have my network adapter set to use 1.1.1.1 for DNS resolution which may be interfering I don't have time to check now though – Renari May 02 '19 at 23:42