0

I have a raspi 4B running headless v10 (buster). I do have a PC connected to a router and I have a raspi connected to a router via ethernet (eth0). With this setup everything runs, I can ssh into the raspi and the raspi can ping google.com. Now I was setting the raspi up as a host AP using dnsmasq.conf

interface=wlan0
dhcp-range=10.0.0.10,10.0.0.15,12h
#dhcp-option=option:router,10.0.0.1
#dhcp-option=option:netmask,255.255.255.0

# Delays sending DHCPOFFER and proxydhcp replies for at least the specified number of seconds.
dhcp-mac=set:client_is_a_pi,B8:27:EB:*:*:*
dhcp-reply-delay=tag:client_is_a_pi,2

address=/raspiwifisetup.com/10.0.0.1

and dhcpcd.conf:

interface wlan0
static ip_address=10.0.0.1/24

After joining the hotspot ssid opened by the raspi I can join a webserver via 10.0.0.1 and do some stuff. All of this works as expected.

BUT when I now try to ping google.com via the eth0 interface the call returns:
ping: google.com: Temporary failure in name resolution

I am still able to ssh into the raspi (via 192.168.178.88) since the eht0 interface is still up with the same IP but somehow I cannot reach the internet. ip route returns:

default via 192.168.178.1 dev eth0 proto dhcp src 192.168.178.88 metric 202
10.0.0.0/24 dev wlan0 proto dhcp scope link src 10.0.0.1 metric 303
192.168.178.0/24 dev eth0 proto dhcp scope link src 192.168.178.88 metric 202

When I now call sudo dhclient eth0 I am able to ping google.com again. After executing dhclient ip route returns.

default via 192.168.178.1 dev eth0
default via 192.168.178.1 dev eth0 proto dhcp src 192.168.178.88 metric 202
10.0.0.0/24 dev wlan0 proto dhcp scope link src 10.0.0.1 metric 303
192.168.178.0/24 dev eth0 proto dhcp scope link src 192.168.178.88 metric 202

Can anyone tell me why this is happening and is there another solution than calling "sudo dhclient eth0" everytime the raspi is in "host AP" mode?

EDIT: A little more background information on what I am trying to accomplish using this setup.

  1. At the start the rpi is in host mode having a hotspot AP open using dhcpcd.conf for address assigning.
  2. This hotspot's only purpose is for somebody to join the hotspot, go to a webserver and enter the credentials for an available wifi the rpi shall join afterwards. The credentials are copied into the wpa_supplicant.conf file.
  3. The rpi reboots after entering the credentials, deletes dhcpcd.conf and dnsmasq.conf and is in "client" mode and connected to the wifi. When the wifi is not available for a certain time, the rpi switches to host mode again and creates the conf files again.
  4. During all 3 states from above, the eth0 interface should be able to access the internet. Currently only when the raspi is in client mode and NOT in host mode, eth0 has internet access.

EDIT: Only "solution" so far: Calling sudo dhclient eth0 - which is not a good solution according to @Milliways

Slev1n
  • 1
  • 3
  • Is is possible that you didn't enable routing on the raspberry pi? Check e.g. https://raspberrypi.stackexchange.com/questions/40563/ip-forwarding-and-routing-rpi-2b-jessie (also the question) on how to do it – Giacomo Catenazzi Sep 23 '22 at 12:26
  • This is a bizarre setup and I don't pretend to understand it. Both network segments claim dhcp but you appear to be providing a DHCP server on an access point. It is also unclear what you are attempting to do - there is no reason the Pi shouldn't be able to access the internet but there is no way devices connected to your AP will. There are many tutorials on setting up AP with routing. – Milliways Sep 23 '22 at 12:58
  • NOTE running dhclient is incompatible with dhcpcd. Mixing networking systems is a recipe for disaster. – Milliways Sep 23 '22 at 13:02
  • A little more background: The raspi will be in the field later. There are 3 ways of getting internet connection: dongle, wifi, eth. In order to provide an easy way for a customer to setup a wifi connection between raspi and his home-wifi. The raspi has an AP open and runs a webserver. The customer joins this network, goes to the webserver, enters the credentials and the pi reboots in client mode (dhcpcd.conf and dnsmasq.conf will be removed in client mode and recreated in host mode). I still want eth0 to be running while in host mode - so far the only way to get this done was using dhclient. – Slev1n Sep 23 '22 at 13:09
  • @Milliways: My setup is based on https://github.com/jasbur/RaspiWiFi. The devices joining the AP should not have internet (check my previous comment) they should only be able to connect to provide their credentials for a wifi the raspi should join after reboot. However, the idea is, that internet is provided to the raspi via ethernet (or dongle=HUAWEI Stick with SIM card but we ignore this case here) UNTIL the user decides to use his "home"-wifi to provide internet access to the raspi. But UNTIL this is the case I want the ethernet to be providing access to internet. Any suggestions welcome. – Slev1n Sep 23 '22 at 13:19
  • @GiacomoCatenazzi: I only have small knowledge about networking and routing. I did not activate/enable routing. I believe the misunderstanding is that I do not want devices connecting to the AP having internet access! The purpose of the AP is explained 2 comments above this one. However, I just dont know how to keep internet acces via eth0 while wlan0 is assigned a static IP via dhcpcd.conf. – Slev1n Sep 23 '22 at 13:23
  • @Slev1n: no. Routing is about enabling traffic to enter from one port and exiting to an other port. What you have by default it is just that traffic to and out the box works, but not *routing*, so not allowing a raspberry pi to be a router (which may be dangerous if you connect ethernet and WiFi on same network, as I did. In such case you can create loops and instability of networks. – Giacomo Catenazzi Sep 23 '22 at 13:26
  • @GiacomoCatenazzi: Thank you for the explanation. This is interesting since I do have this setup sometimes here for test purpose (never had this case in the field but possible). I thought the problem would be solved by the metric level/value provided by the routing table ('sudo route -n'). eth0 has a lower metric by default compared to wlan0 - hence I thought the routine would simpy route any request via the eth0-interface. So far this is also what I have seen during my tests. – Slev1n Sep 23 '22 at 13:33
  • @Milliways: You are right, I have added more information in the original question. I tried to stick to the most relevant points to not overload the question with information. – Slev1n Sep 24 '22 at 16:33

1 Answers1

0

The "tutorial" you linked is old and rather confusing.

It also omits a vital step in setting up an Access Point using dhcpcd

interface wlan0
    …
    nohook wpa_supplicant

This would have to be removed if trying to use for normal WiFi.

I can't guarantee that the process you used will actually work and it is far from clear what you end up with in dhcpcd.conf. There are a number of processes which claim to do this but are rather convoluted (it is just so much easier to add a wpa-supplicant.conf file for desired networks).

NOTE if you want an Access Point with no internet etc you should add nogateway See Prevent dhcpcd from configuring an interface in How do I set up networking/WiFi/static IP address on Raspbian/Raspberry Pi OS?

Milliways
  • 54,718
  • 26
  • 92
  • 182
  • In the "tutorial" I am using, the dhcpcd.conf file will be deleted in client mode and is only existing when in host mode again. Therefore, I do not need the nohook - if I understand you and the concept of nohook correctly?! When a customer is using the webserver to enter the wifi credentials, these credentials are then placed in the wpa_supplicant.conf, the dhcpcd.conf and the dnsmasq.conf are deleted and the system reboots. The RPI joins the wifi in client mode and can connect to the internet. But when in hostmode, eth0 somehow has no route to internet – Slev1n Sep 24 '22 at 16:21
  • Regarding the `nogateway`, I followed your link but I am not sure if I understand your intention correctly. Do you mean, that in host mode, the dhcpcd service is setting the wlan0 interface, which has no internet to the "main" gateway and thus routing all traffic over this interface and hence eth0 is not used anymore? But I thought that the metric value from the routing table would decide, which route the traffic takes? Otherwise the AP works as intended, has no internet, assigns IPs to clients, which can then access the webserver. – Slev1n Sep 24 '22 at 16:37