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.
- At the start the rpi is in host mode having a hotspot AP open using dhcpcd.conf for address assigning.
- 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.
- 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.
- 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