Ubuntu/Bespin: Difference between revisions
From charlesreid1
| Line 19: | Line 19: | ||
=VPN Tunnel= | =VPN Tunnel= | ||
[[Ubuntu/Bespin/PIA]] | |||
=Connect AP to VPN Tunnel= | =Connect AP to VPN Tunnel= | ||
Revision as of 03:01, 18 August 2020
All the setup involved for bespin, a Ubuntu 18.04 desktop server.
Inital Setup
Gnome Setup
Ansible Setup
Wifi Access Point Setup
Ubuntu/Bespin/Old/Wifi AP Setup
VPN Tunnel
Connect AP to VPN Tunnel
The last step here is to provide an internet gateway for the AP, and to do it via the VPN tunnel.
The current network setup is as follows:
wlan0on 192.168.0.0/24 - provides internet connectionwlan1on 192.168.10.0/24 - access point networktun1on 10.96.10.0/24 - private IP for VPN tunnel
Bridged network vs routed network
There are (at least) two ways we can do this:
- Bridged network - this uses a virtual network device called a bridge to allow two network interfaces to see traffic from each other. This can be thought of as connecting two network interfaces to a switch, done virtually on the local machine.
- Routed network - this keeps the two network interfaces separate, and uses iptables to forward traffic from one device to another. This uses masquerading, which means that the server takes packets destined for external networks and proxies them, sending them out over the VPN tunnel, and returning the result to the client when it arrives.
Bridged networks are useful if you want clients on the AP to obtain IP addresses from the wifi router providing bespin with internet. In this scenario, clients would see the 192.168.0.0/24 network, just like bespin does, and would receive IP addresses on that network instead of 192.168.10.0/24.
Routed networks keep the networks associated with each network interface isolated. Packets only pass from one network interface to another if iptables has a rule to do that.
We will use a routed network for this setup.
Creating the routed network
Start by installing the netfilter-persistent tool, which will make it easy to save the iptables configuration:
sudo apt-get -y install netfilter-persistent
Creating the routed network requires packet forwarding to be enabled (see AP setup for instructions). Set up the routed network by adding iptables rules with the following script:
#!/bin/bash
set -e
ipt="sudo /sbin/iptables"
# start by flushing all rules and setting defaults
$ipt -F
# should we do this?
#$ipt -P INPUT DROP
#$ipt -P FORWARD DROP
$ipt -P INPUT ACCEPT
$ipt -P FORWARD ACCEPT
$ipt -P OUTPUT ACCEPT
$ipt -t nat -F
$ipt -t mangle -F
$ipt -F
$ipt -X
##################################
# PIA VPN Tunnels
# These are PIA tunnels that handle traffic from APs
PIA_AP_TUNNELS="tun1"
for TUN in TUNNELS; do
# Accept all traffic coming in from tunnel
$ipt -A INPUT -i ${TUN} -j ACCEPT
# Masquaerade outgoing traffic leaving via the tunnel
$ipt -t nat -A POSTROUTING -o ${TUN} -j MASQUERADE
done
##################################
# AP-PIA Tunneling
# Forward outgoing traffic for APs through tunnel
AP="wlan1"
TUN="tun1"
# Allow traffic on the TUN interface.
$ipt -A INPUT -i ${TUN} -j ACCEPT
$ipt -A FORWARD -i ${TUN} -j ACCEPT
$ipt -A OUTPUT -o ${TUN} -j ACCEPT
# Allow forwarding traffic from the VPN
$ipt -A FORWARD -i ${TUN} -o ${AP} -j ACCEPT
$ipt -A FORWARD -i ${AP} -o ${TUN} -j ACCEPT
# Make rules persistent
sudo netfilter-persistent save
hat tip:
This stores the iptables configuration in /etc/iptables/
Testing Joining AP
Join the wifi network from another laptop or phone.
Verify that you receive an IP address and that your device can be pinged from bespin.
Check your IP address from the device (whatsmyip.org) to ensure it is coming from the PIA region specified.
Troubleshooting EAPOL Timeout
If your test computer/laptop/phone connects to the network and authenticates okay but the EAPOL handshake step keeps timing out, it's a problem with the DNS server (dnsmasq) not being set up properly. You can see the EAPOL handshake timeout messages when you run hostapd in debug mode (sudo hostapd -d /etc/hostapd/hostapd.conf) and try to join the wifi network with another computer.
Troubleshooting Joining Wifi
View the kernel IP routing table and review it to make sure things are wired up correctly:
netstat -rn
Check iptables rules with this command:
sudo iptables -S # or sudo iptables -L
To limit to input/output rules only, do this:
sudo iptables -L INPUT sudo iptables -L OUTPUT
To check that traffic is flowing okay:
On bespin, run tcpdump -i tun1 (monitoring the openvpn tunnel) and tcpdump -i wlan1 (monitoring traffic on the AP) in side by side windows. Then join the AP from the phone or device and try to access the internet.
You should see packets related to the request that show up in both the tun1 and wlan1 traffic streams, which verifies that traffic is correctly being forwarded from the AP client through bespin and on to the final destination.
The packets should also be going in both directions - to and from the AP client. If they are only going one direction (from the client to the destination) and none are returning, double-check the iptables rules.
Help from here: [5]
More Troubleshooting
If you restart the networking service on bespin, like this
sudo service networking restart
then you'll lose your wifi connection. This is because the networking interface reverts back to looking for the old network interface name (the one with the entire mac address in the name), instead of the renamed version.
We specified the device name as part of udev, specifically the file /etc/udev/rules.d/70-persistent-net.rules
So we need to reload udev:
sudo udevadm control --reload-rules && udevadm trigger
Well crap, that doesn't work. If you reload the networking service, wifi breaks because wpa_supplicant reverts to a stupid network interface scheme, and apparently you're hosed until you restart.
PiHole
Run PiHole in a Docker container, and install it between dnsmasq and the VPN tunnel (so that DNS queries will be filtered by the PiHole).
OpenVPN Server
Real simple: just set up an OpenVPN server.
47 pages later: man that was was intense
Brushup of dnsmasq Config
Updated the dnsmasq config file to the one shown here.
Key changes:
- Specifying the interfaces and listen addresses together (only need one or the other, but just to be sure)
- Using the expanded notation for the server keyword, and using it to specify which DNS nameserver to use for traffic from different sources. Now different LANs can use different DNS.
/etc/dnsmasq.conf
# don't send external traffic that is missing a domain domain-needed # don't send external traffic that has bogus private ip bogus-priv ## set the local domain #domain=anon #local=/anon/ # listen on these interfaces and only these interfaces interface=lo listen-address=127.0.0.1 interface=wlan1 listen-address=192.168.10.1 bind-interfaces # define range of IP addresses to hand out dhcp-range=192.168.10.100,192.168.10.150,255.255.255.0,24h # don't read /etc/resolv.conf no-resolv # define what to do if no name resolution # the notation for server used here is # <dest-ip>/<src-ip> # local dns queries use pihole dns server server=127.53.0.1/127.0.0.1 # lan10 dns queries use pihole dns server server=127.53.0.1/192.168.10.1 ## lan20 dns queries use google #server=8.8.8.8/192.168.20.1 # send dnsmasq logs to a single place log-facility=/var/log/dnsmasq.log
Iptables Reconfiguration
Update the iptables rules to allow better protection of the server and be less permissive:
Wifi Repeater
Eventually we abandoned the idea of running hostapd on bespin to create a wifi network that would tunnel traffic through a PIA VPN tunnel. That job was moved to Thing 1.
We did have a new problem that hostapd could solve: Bespin and a few other computers are far from the wifi router. We want Bespin to provide a wifi repeater so that other computers can talk to Bespin faster than they can talk to the rest of the network. This doesn't make much of a difference, except if you're using services on Bespin, which we are.
Related Pages
- Ubuntu/Bespin/TIL - the summary of "today I learned" things that I learned while setting up Bespin
Ubuntu/Bespin/Second AP Tunnel- this ended in failure, twice. short version: you can't have multiple simultaneous PIA tunnels in OpenVPN without significant extra configuration, so no need to go this above and beyond.