I have made some router with VPN and you may get some ideas from How To Create A Private Subnet Behind Raspberry Pi? and from Raspberry pi as access point with vpn. But your wifi repeater does not work so I suggest to make it first running without fiddling with a VPN tunnel. If it works as expected then you should add the VPN tunnel. You also want to have special access conditions and a failover and no, there is nothing simple you missed ;-)
So lets start to improve this answer interactively in this steps:
- make access point running incl. ssh
- add VPN tunnel
- configure restrictions
- lets talk about failover
As far as I understand you can connect to the access point (AP) and you can connect another station also connected to the AP but you cannot get into the internet and you cannot ssh into the RasPi. Check if ip forwarding is active and the default route is set to the internet router:
rpi ~$ cat /proc/sys/net/ipv4/ip_forward # should give 1
1
rpi ~$ ip route show
default via 192.168.1.1 dev wlan0 proto static
192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.2
192.168.50.0/24 dev ap0 proto kernel scope link src 192.168.50.1
The line with default must point to the internet router and the device must be wlan0.
Then NAT (network address translation) must be enabled. Check with:
rpi ~$ sudo iptables --table nat --list POSTROUTING --verbose
Chain POSTROUTING (policy ACCEPT 5 packets, 355 bytes)
pkts bytes target prot opt in out source destination
13 974 MASQUERADE all -- any wlan0 anywhere anywhere
For ssh you should enable and start the service on the RasPi with:
rpi ~$ sudo systemctl enable ssh.service --now
and then from a linux computer try to connect with verbose messages and look what's going wrong:
station ~$ ssh -v pi@192.168.50.1
Belonging to name resolution you should first make it run only with ip addresses. If you are sure that DNS server can be addressed by ip address you can look what's wrong with DNS. Systemd-networkd presents default DNS server anywhere in the internet to the clients so you should be able to resolve internet names like google.com
. If internet connection is broken then default DNS is also not working. If you use names in your local network managed by your own DNS server you can configure systemd-netword to present this server to its clients.
Check if you have enabled systemd name resolving with:
rpi ~$ sudo systemctl enable systemd-resolved.service
rpi ~$ sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
With cat /etc/resolv.conf
systemd-networkd shows its default DNS server if you don't have configure some:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 2001:4860:4860::8888
# Too many DNS servers configured, the following entries may be ignored.
nameserver 2001:4860:4860::8844
For example with systemd-networkd on configuration for wlan0 you can define your own DNS server 192.168.10.10 for the RasPi itself with:
[Match]
Name=wlan0
[Network]
Address=192.168.10.2/24
Gateway=192.168.10.1
DNS=192.168.10.10 8.8.8.8
To give your own DNS server to the stations associated to the access point, set it on the configuration for ap0 with:
[Match]
Name=ap0
[Network]
Address=192.168.50.1/24
IPForward=yes
DHCPServer=yes
[DHCPServer]
DNS=192.168.10.10 8.8.8.8
ssh -v
complains that it cannot connect? For DNS if have updated my answer. – Ingo Oct 12 '18 at 14:06default via 10.180.223.1 dev wlan0 proto dhcp src 10.180.223.30 metric 1024
. In my setup there is nohostapd
anddnsmasq
used. So what you are trying? – Ingo May 19 '20 at 08:55