1

Today I set up my Raspberry Pi with dnsmasq and hostapd so it's built-in wireless interface would always be used as an access point (AP), so I could connect to it with my phone and SSH/VNC into it whenever, without worrying about having WiFi or a mobile hotspot available.

This uses the built-in WiFi interface.

I can connect to the AP with my phone, and SSH/VNC into the Pi just fine, however if I connect a USB WiFi adapter to the Pi, to allow it to connect to an existing WiFi network, I can't SSH/VNC into the Pi using a device on THAT network.

SSH'ing into the Pi via it's own AP still works fine, but I'd like to be able to get both working, so I can use my home WiFi network (with internet access) to connect to the Pi when I'm home, and use it's own hosted Access Point to connect to the Pi when I'm out and about.

I noticed that if I remove the line that I have marked below (in my /etc/dhcpcd.conf file) and run sudo systemctl restart dnsmasq hostapd dhcpcd, I can access the Pi as a client on my home network, but this disallows any device to connect to the Pi's AP. (I'm guessing it's because the Pi's AP no longer has a Gateway, since that static IP is what happens to be the Pi AP's Gateway? I'm not too sure).

I've been at this for hours and still can't seem to make any progress.

/etc/dhcpcd.conf:

interface wlan0
static ip_address=192.168.4.1/24  # <========= This is that line
nohook wpa_supplicant

/etc/dnsmasq.conf

interface=wlan0
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
server=8.8.8.8

/etc/hostapd/hostapd.conf:

interface=wlan0
ssid=MyAwesomeNetwork
hw_mode=g
channel=7
wpa=2
wpa_passphrase=SecurityIsMyPassion
wpa_key_mgmt=WPA-PSK
country_code=US

Thank you for reading this and I hope I've provided sufficient information, as well as a somewhat-informative explanation on what I'm aiming to accomplish. :)

3
  • 1
    What exactly you have done with the "USB WiFi adapter"? -- To be honest, your objective of asking this question is not clear for me.
    – M. Rostami
    Feb 29, 2020 at 18:42
  • I haven't done anything with it. I just plugged it in to the Pi and connected to my home WiFi network with it. Basically, I'm trying to be able to SSH into my Pi from both a device on the same network as it's wlan1 adapter, OR a device connected directly to the Pi via it's own hosted AP (running on the wlan0 interface). wlan1 is a client and wlan0 is an AP.
    – Leo Takacs
    Feb 29, 2020 at 19:26
  • Ok, thanks. What's the problem? Did you configure it and find any problem/error?
    – M. Rostami
    Feb 29, 2020 at 19:57

1 Answer 1

1

RESOLVED! I figured out what was going on! My home WiFi network provides 192.168.4.X IP addresses to its client. This was interfering with the 192.168.4.X IP addresses that my Raspberry Pi's AP was assigning to ITS clients.

To fix it, simply change the Gateway as well as the IP range in your configuration files:

/etc/dhcpcd.conf:

#static ip_address=192.168.4.1/24 #Not working
static ip_address=192.168.50.1/24 #Fixed!

/etc/dnsmasq.conf:

#dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h #Not working
dhcp-range=192.168.50.2,192.168.50.20,255.255.255.0,24h #Fixed!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.