I am trying to setup Raspberry Pi as VPN-WiFi access point connecting to AWS VPC. I followed Raspberry Pi as an access point
Here are the all steps I performed in sequence
Installed fresh full Raspbian Stretch on Raspberry Pi 3+, which is connected to local network over ethernet.
#Update Raspbian
sudo apt-get update -y
sudo apt-get dist-upgrade -y
sudo reboot
sudo apt install dnsmasq hostapd -y
sudo nano /etc/dhcpcd.conf
#Added following after # Example static IP configuration:
interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant
sudo systemctl restart dhcpcd
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf
#Added following
interface=wlan0 # Use the require wireless interface - usually wlan0
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h
sudo systemctl reload dnsmasq
sudo nano /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ssid=MyWiFi
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=AccessMyNetwork
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
sudo nano /etc/default/hostapd
#Added following line
DAEMON_CONF="/etc/hostapd/hostapd.conf"
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
sudo nano /etc/sysctl.conf
#Added
net.ipv4.ip_forward=1
sudo apt install hostapd bridge-utils -y
sudo nano /etc/dhcpcd.conf
#Added following lines just before interface wlan0 config I added above
denyinterfaces wlan0
denyinterfaces eth0
sudo nano /etc/network/interfaces
# Added following after source-directory
# Bridge setup
auto br0
iface br0 inet manual
bridge_ports eth0 wlan0
sudo ifup br0
sudo systemctl restart dhcpcd
sudo nano /etc/hostapd/hostapd.conf
#Added bridge=br0 below the interface=wlan0 line and comment out the driver line
bridge=br0
#driver=nl80211
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd
sudo reboot
This what network interface
pi@accesspoint:~ $ ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.24.11.15 netmask 255.255.255.0 broadcast 10.24.11.255
inet6 fe80::4152:f5f5:5bee:6082 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:8e:38:ee txqueuelen 1000 (Ethernet)
RX packets 92 bytes 10655 (10.4 KiB)
RX errors 0 dropped 3 overruns 0 frame 0
TX packets 75 bytes 10841 (10.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether b8:27:eb:db:6d:bb txqueuelen 1000 (Ethernet)
RX packets 64 bytes 8284 (8.0 KiB)
RX errors 0 dropped 1 overruns 0 frame 0
TX packets 102 bytes 14518 (14.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether b8:27:eb:8e:38:ee txqueuelen 1000 (Ethernet)
RX packets 29 bytes 3519 (3.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 38 bytes 6341 (6.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
After doing above steps I cant ssh directly to accesspoint, I have to connect to WiFi Access point (MyWiFi
)created on Raspberry pi first and then ssh to Raspberry pi IP. Is there any way to avoid this ?
OpenVPN Client Installation :
sudo apt-get install openvpn -y
sudo cp /etc/openvpn/client1.ovpn /etc/openvpn/client.conf
sudo systemctl start openvpn@client
pi@accesspoint:~ $ ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.24.11.15 netmask 255.255.255.0 broadcast 10.24.11.255
inet6 fe80::4152:f5f5:5bee:6082 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:8e:38:ee txqueuelen 1000 (Ethernet)
RX packets 2355 bytes 1999824 (1.9 MiB)
RX errors 0 dropped 108 overruns 0 frame 0
TX packets 894 bytes 108321 (105.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether b8:27:eb:db:6d:bb txqueuelen 1000 (Ethernet)
RX packets 4094 bytes 2863772 (2.7 MiB)
RX errors 0 dropped 18 overruns 0 frame 0
TX packets 3289 bytes 660002 (644.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 16 bytes 1631 (1.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16 bytes 1631 (1.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.8.0.2 netmask 255.255.255.0 destination 10.8.0.2
inet6 fe80::48dd:8f8b:8dcd:a059 prefixlen 64 scopeid 0x20<link>
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 100 (UNSPEC)
RX packets 1 bytes 76 (76.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 95 bytes 5492 (5.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether b8:27:eb:8e:38:ee txqueuelen 1000 (Ethernet)
RX packets 2600 bytes 546612 (533.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2446 bytes 1014039 (990.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
pi@accesspoint:~ $ sudo ip route
0.0.0.0/1 via 10.8.0.1 dev tun0
default via 10.24.11.1 dev br0 src 10.24.11.15 metric 204
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.2
10.24.11.0/24 dev br0 proto kernel scope link src 10.24.11.15 metric 204
35.166.225.161 via 10.24.11.1 dev br0
128.0.0.0/1 via 10.8.0.1 dev tun0
pi@accesspoint:~ $ sudo route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.8.0.1 128.0.0.0 UG 0 0 0 tun0
0.0.0.0 10.24.11.1 0.0.0.0 UG 204 0 0 br0
10.8.0.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0
10.24.11.0 0.0.0.0 255.255.255.0 U 204 0 0 br0
35.166.225.161 10.24.11.1 255.255.255.255 UGH 0 0 0 br0
128.0.0.0 10.8.0.1 128.0.0.0 UG 0 0 0 tun0
10.24.11.0/24
Local Ethernet Network
10.2.0.0/16
is VPC network
10.2.2.101
IP of OpenVPN server Private IP
10.8.0.2
is VPN IP for accesspoint
and 10.8.0.1
is VPN IP for OpenVPN server openvpn
Connectivity :
pi@accesspoint:~ $ ping 10.2.2.101
PING 10.2.2.101 (10.2.2.101) 56(84) bytes of data.
64 bytes from 10.2.2.101: icmp_seq=1 ttl=64 time=81.2 ms
pi@accesspoint:~ $ ping 10.2.1.145
PING 10.2.1.145 (10.2.1.145) 56(84) bytes of data.
64 bytes from 10.2.1.145: icmp_seq=1 ttl=63 time=80.5 ms
pi@accesspoint:~ $ ping 10.8.0.1
PING 10.8.0.1 (10.8.0.1) 56(84) bytes of data.
64 bytes from 10.8.0.1: icmp_seq=1 ttl=64 time=80.1 ms
pi@accesspoint:~ $ ping 10.8.0.2
PING 10.8.0.2 (10.8.0.2) 56(84) bytes of data.
64 bytes from 10.8.0.2: icmp_seq=1 ttl=64 time=0.171 ms
sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
pi@accesspoint:~ $ ping -I 10.8.0.2 10.2.1.145
PING 10.2.1.145 (10.2.1.145) from 10.8.0.2 : 56(84) bytes of data.
64 bytes from 10.2.1.145: icmp_seq=1 ttl=63 time=80.9 ms
pi@accesspoint:~ $ ping -I 10.24.11.15 10.2.1.145
(0 received, 100% packet loss)
Added Route :
pi@accesspoint:~ $ sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
pi@accesspoint:~ $ sudo sudo iptables -A FORWARD -i tun0 -o br0 -j ACCEPT
pi@accesspoint:~ $ sudo iptables -A FORWARD -i br0 -o tun0 -j ACCEPT
pi@accesspoint:~ $ ping 10.2.1.145
PING 10.2.1.145 (10.2.1.145) 56(84) bytes of data.
64 bytes from 10.2.1.145: icmp_seq=1 ttl=63 time=82.5 ms
pi@accesspoint:~ $ ping -I 10.24.11.15 10.2.1.145
PING 10.2.1.145 (10.2.1.145) from 10.24.11.15 : 56(84) bytes of data.
64 bytes from 10.2.1.145: icmp_seq=1 ttl=63 time=82.5 ms
pi@accesspoint:~ $ sudo ip route get 10.2.1.145 from 10.8.0.2 iif br0
RTNETLINK answers: Invalid argument
pi@accesspoint:~ $ sudo ip route get 10.2.1.145 from 10.8.0.2 iif tun0
RTNETLINK answers: Invalid argument
pi@accesspoint:~ $ sudo ip route get 10.2.1.145 from 10.24.11.15 iif br0
RTNETLINK answers: Invalid argument
pi@accesspoint:~ $ sudo ip route get 10.2.1.145 from 10.24.11.15 iif tun0
RTNETLINK answers: Invalid argument
pi@accesspoint:~ $ sudo ip netconf show dev tun0
ipv4 dev tun0 forwarding on rp_filter off mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
pi@accesspoint:~ $ sudo ip netconf show dev br0
ipv4 dev br0 forwarding on rp_filter off mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off
I setup another Raspberry Pi (client
) and connected to WiFi access point (MyWiFi
) I created in above steps.
pi@client:~ $ ifconfig
eth0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether b8:27:eb:d2:02:8c txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 73 bytes 6692 (6.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 73 bytes 6692 (6.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.24.11.201 netmask 255.255.255.0 broadcast 10.24.11.255
inet6 fe80::561a:a6ae:7d08:1470 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:87:57:d9 txqueuelen 1000 (Ethernet)
RX packets 7277 bytes 792141 (773.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 28592 bytes 3117200 (2.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
pi@client:~ $ sudo ip route
default via 10.24.11.1 dev wlan0 src 10.24.11.201 metric 303
10.24.11.0/24 dev wlan0 proto kernel scope link src 10.24.11.201 metric 303
pi@client:~ $ sudo route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.24.11.1 0.0.0.0 UG 303 0 0 wlan0
10.24.11.0 0.0.0.0 255.255.255.0 U 303 0 0 wlan0
Connectivity from client :
pi@client:~ $ ping 10.24.11.15
PING 10.24.11.15 (10.24.11.15) 56(84) bytes of data.
64 bytes from 10.24.11.15: icmp_seq=1 ttl=64 time=2.31 ms
pi@client:~ $ ping 10.2.1.145
PING 10.2.1.145 (10.2.1.145) 56(84) bytes of data
(0 received, 100% packet loss)
pi@client:~ $ ping 10.8.0.2
PING 10.8.0.2 (10.8.0.2) 56(84) bytes of data.
(0 received, 100% packet loss)
Adding Routes on accesspoint :
pi@accesspoint:~ $ sudo ip route add 10.2.0.0/16 via 10.8.0.2 dev tun0 proto static
pi@accesspoint:~ $ sudo ip route
0.0.0.0/1 via 10.8.0.1 dev tun0
default via 10.24.11.1 dev br0 src 10.24.11.15 metric 204
10.2.0.0/16 via 10.8.0.2 dev tun0 proto static
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.2
10.24.11.0/24 dev br0 proto kernel scope link src 10.24.11.15 metric 204
35.166.225.161 via 10.24.11.1 dev br0
128.0.0.0/1 via 10.8.0.1 dev tun0
pi@accesspoint:~ $ sudo route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.8.0.1 128.0.0.0 UG 0 0 0 tun0
0.0.0.0 10.24.11.1 0.0.0.0 UG 204 0 0 br0
10.2.0.0 10.8.0.2 255.255.0.0 UG 0 0 0 tun0
10.8.0.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0
10.24.11.0 0.0.0.0 255.255.255.0 U 204 0 0 br0
35.166.225.161 10.24.11.1 255.255.255.255 UGH 0 0 0 br0
128.0.0.0 10.8.0.1 128.0.0.0 UG 0 0 0 tun0
Adding Routes on openvpn server in AWS VPC :
ubuntu@openvpn:~$ sudo route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.2.2.1 0.0.0.0 UG 100 0 0 ens5
10.2.2.0 0.0.0.0 255.255.255.0 U 0 0 0 ens5
10.2.2.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens5
10.8.0.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0
ubuntu@openvpn:~$ sudo ip route add 10.24.11.0/24 via 10.8.0.1 dev tun0 proto static
ubuntu@openvpn:~$ sudo route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.2.2.1 0.0.0.0 UG 100 0 0 ens5
10.2.2.0 0.0.0.0 255.255.255.0 U 0 0 0 ens5
10.2.2.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens5
10.8.0.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0
10.24.11.0 10.8.0.1 255.255.255.0 UG 0 0 0 tun0
Connectivity from OpenVPN Server to accesspoint :
ubuntu@openvpn:~$ ping 10.8.0.2
PING 10.8.0.2 (10.8.0.2) 56(84) bytes of data.
64 bytes from 10.8.0.2: icmp_seq=1 ttl=64 time=80.0 ms
ubuntu@openvpn:~$ ping 10.24.11.15
PING 10.24.11.15 (10.24.11.15) 56(84) bytes of data.
(0 received, 100% packet loss)
Connectivity for client (following command were running simultaneously) :
pi@client:~ $ ping 10.8.0.2
PING 10.8.0.2 (10.8.0.2) 56(84) bytes of data.
^C
--- 10.8.0.2 ping statistics ---
12 packets transmitted, 0 received, 100% packet loss, time 11416ms
pi@accesspoint:~ $ sudo tcpdump -ni br0 'icmp'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on br0, link-type EN10MB (Ethernet), capture size 262144 bytes
11:22:23.054146 IP 10.24.11.201 > 10.8.0.2: ICMP echo request, id 2619, seq 1, length 64
11:22:24.084698 IP 10.24.11.201 > 10.8.0.2: ICMP echo request, id 2619, seq 2, length 64
11:22:25.126055 IP 10.24.11.201 > 10.8.0.2: ICMP echo request, id 2619, seq 3, length 64
pi@accesspoint:~ $ sudo tcpdump -ni tun0 'icmp'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on tun0, link-type RAW (Raw IP), capture size 262144 bytes
^C
(0 packets captured)
And (following command were running simultaneously)
pi@client:~ $ ping 10.2.1.145
PING 10.2.1.145 (10.2.1.145) 56(84) bytes of data.
^C
--- 10.2.1.145 ping statistics ---
17 packets transmitted, 0 received, 100% packet loss, time 16644ms
pi@accesspoint:~ $ sudo tcpdump -ni br0 'icmp'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on br0, link-type EN10MB (Ethernet), capture size 262144 bytes
11:24:27.609493 IP 10.24.11.201 > 10.2.1.145: ICMP echo request, id 3222, seq 5, length 64
11:24:28.644693 IP 10.24.11.201 > 10.2.1.145: ICMP echo request, id 3222, seq 6, length 64
pi@accesspoint:~ $ sudo tcpdump -ni tun0 'icmp'
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on tun0, link-type RAW (Raw IP), capture size 262144 bytes
^C
0 packets captured
0 packets received by filter
0 packets dropped by kernel
I tried to re-do entire set-up in a clean way.
I can't ping AWS VPC IP's from client
which is connected to access point MyWiFi
, all connectivity works from accesspoint
node.
(Office Network) 10.24.11.1/24 (AWS VPC) 10.2.0.0/16 +--------------------------------------------+ +----------------------------------+ | | | | | OpenVPN Client (Pi) | | OpenVPN Server (Ubuntu) | | | | | | +--------------------------+ | | +--------------------------+ | | | | | | | | | | eth0 | | |tun0 | | | | | <--+-->| 10.8.0.2|<--|--+----|->|10.8.0.1 10.2.2.101 |ens5| | | | | | | | | | br0 |10.24.11.15 | | | | | | | | | | | | | | | | wlan0 | | | | | | | +--------------------------+ | | +--------------------------+ | | ^ | | | | | | | | | WiFi Client | | | | | +------------------+ | | | +----------+ | | |wlan0:10.24.11.201| | | | | Host 1 | | | | |--+ | | | | | | +------------------+ | | |10.2.1.145| | +--------------------------------------------+ | +----------+ | +----------------------------------+
OpenVPN Server
route :
ubuntu@openvpn:~$ ip route
default via 10.2.2.1 dev ens5 proto dhcp src 10.2.2.101 metric 100
10.2.2.0/24 dev ens5 proto kernel scope link src 10.2.2.101
10.2.2.1 dev ens5 proto dhcp scope link src 10.2.2.101 metric 100
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.1
10.24.11.0/24 via 10.8.0.2 dev tun0 proto static src 10.8.0.1
OpenVPN Client
route :
pi@accesspoint:~ $ ip route
default via 10.24.11.1 dev br0 src 10.24.11.15 metric 203
10.2.0.0/16 via 10.8.0.1 dev tun0 proto static src 10.8.0.2
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.2
10.24.11.0/24 dev br0 proto kernel scope link src 10.24.11.15 metric 203
35.176.225.61 via 10.24.11.1 dev br0
WiFi Client
route :
pi@client:~ $ ip route
default via 10.24.11.1 dev wlan0 src 10.24.11.201 metric 303
10.2.0.0/16 via 10.24.11.15 dev wlan0 proto static
10.24.11.0/24 dev wlan0 proto kernel scope link src 10.24.11.201 metric 303
ip route
. It's better readable for me... – Ingo May 02 '19 at 00:03