<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Ubuntu%2FBespin%2FOld%2FAP_PIA_Tunnel</id>
	<title>Ubuntu/Bespin/Old/AP PIA Tunnel - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Ubuntu%2FBespin%2FOld%2FAP_PIA_Tunnel"/>
	<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Ubuntu/Bespin/Old/AP_PIA_Tunnel&amp;action=history"/>
	<updated>2026-06-16T04:09:45Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=Ubuntu/Bespin/Old/AP_PIA_Tunnel&amp;diff=28501&amp;oldid=prev</id>
		<title>Unknown user: Admin moved page Ubuntu/Bespin/AP PIA Tunnel to Ubuntu/Bespin/Old/AP PIA Tunnel</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Ubuntu/Bespin/Old/AP_PIA_Tunnel&amp;diff=28501&amp;oldid=prev"/>
		<updated>2020-08-19T00:49:27Z</updated>

		<summary type="html">&lt;p&gt;Admin moved page &lt;a href=&quot;/wiki/Ubuntu/Bespin/AP_PIA_Tunnel&quot; class=&quot;mw-redirect&quot; title=&quot;Ubuntu/Bespin/AP PIA Tunnel&quot;&gt;Ubuntu/Bespin/AP PIA Tunnel&lt;/a&gt; to &lt;a href=&quot;/wiki/Ubuntu/Bespin/Old/AP_PIA_Tunnel&quot; title=&quot;Ubuntu/Bespin/Old/AP PIA Tunnel&quot;&gt;Ubuntu/Bespin/Old/AP PIA Tunnel&lt;/a&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 00:49, 19 August 2020&lt;/td&gt;
				&lt;/tr&gt;
&lt;!-- diff cache key wikidb:diff::1.12:old-28482:rev-28501 --&gt;
&lt;/table&gt;</summary>
		<author><name>Unknown user</name></author>
	</entry>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=Ubuntu/Bespin/Old/AP_PIA_Tunnel&amp;diff=28482&amp;oldid=prev</id>
		<title>Unknown user: Created page with &quot;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: * &lt;code&gt;wlan0&lt;/code&gt; on 192.168.0.0...&quot;</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Ubuntu/Bespin/Old/AP_PIA_Tunnel&amp;diff=28482&amp;oldid=prev"/>
		<updated>2020-08-19T00:07:36Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;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: * &amp;lt;code&amp;gt;wlan0&amp;lt;/code&amp;gt; on 192.168.0.0...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The last step here is to provide an internet gateway for the AP, and to do it via the VPN tunnel.&lt;br /&gt;
&lt;br /&gt;
The current network setup is as follows:&lt;br /&gt;
* &amp;lt;code&amp;gt;wlan0&amp;lt;/code&amp;gt; on 192.168.0.0/24 - provides internet connection&lt;br /&gt;
* &amp;lt;code&amp;gt;wlan1&amp;lt;/code&amp;gt; on 192.168.10.0/24 - access point network&lt;br /&gt;
* &amp;lt;code&amp;gt;tun1&amp;lt;/code&amp;gt; on 10.96.10.0/24 - private IP for VPN tunnel&lt;br /&gt;
&lt;br /&gt;
===Bridged network vs routed network===&lt;br /&gt;
&lt;br /&gt;
There are (at least) two ways we can do this:&lt;br /&gt;
&lt;br /&gt;
* 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.&lt;br /&gt;
* 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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
We will use a routed network for this setup.&lt;br /&gt;
&lt;br /&gt;
===Creating the routed network===&lt;br /&gt;
&lt;br /&gt;
Start by installing the netfilter-persistent tool, which will make it easy to save the iptables configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get -y install netfilter-persistent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
set -e&lt;br /&gt;
&lt;br /&gt;
ipt=&amp;quot;sudo /sbin/iptables&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# start by flushing all rules and setting defaults&lt;br /&gt;
$ipt -F&lt;br /&gt;
# should we do this?&lt;br /&gt;
#$ipt -P INPUT DROP&lt;br /&gt;
#$ipt -P FORWARD DROP&lt;br /&gt;
$ipt -P INPUT ACCEPT&lt;br /&gt;
$ipt -P FORWARD ACCEPT&lt;br /&gt;
$ipt -P OUTPUT ACCEPT&lt;br /&gt;
$ipt -t nat -F&lt;br /&gt;
$ipt -t mangle -F&lt;br /&gt;
$ipt -F&lt;br /&gt;
$ipt -X&lt;br /&gt;
&lt;br /&gt;
##################################&lt;br /&gt;
# PIA VPN Tunnels&lt;br /&gt;
&lt;br /&gt;
# These are PIA tunnels that handle traffic from APs&lt;br /&gt;
PIA_AP_TUNNELS=&amp;quot;tun1&amp;quot;&lt;br /&gt;
for TUN in TUNNELS; do&lt;br /&gt;
    # Accept all traffic coming in from tunnel&lt;br /&gt;
    $ipt -A INPUT -i ${TUN} -j ACCEPT&lt;br /&gt;
    # Masquaerade outgoing traffic leaving via the tunnel&lt;br /&gt;
    $ipt -t nat -A POSTROUTING -o ${TUN} -j MASQUERADE&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
##################################&lt;br /&gt;
# AP-PIA Tunneling&lt;br /&gt;
&lt;br /&gt;
# Forward outgoing traffic for APs through tunnel&lt;br /&gt;
AP=&amp;quot;wlan1&amp;quot;&lt;br /&gt;
TUN=&amp;quot;tun1&amp;quot;&lt;br /&gt;
# Allow traffic on the TUN interface.&lt;br /&gt;
$ipt -A INPUT   -i ${TUN} -j ACCEPT&lt;br /&gt;
$ipt -A FORWARD -i ${TUN} -j ACCEPT&lt;br /&gt;
$ipt -A OUTPUT  -o ${TUN} -j ACCEPT&lt;br /&gt;
# Allow forwarding traffic from the VPN&lt;br /&gt;
$ipt -A FORWARD -i ${TUN} -o ${AP} -j ACCEPT&lt;br /&gt;
$ipt -A FORWARD -i ${AP} -o ${TUN} -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Make rules persistent&lt;br /&gt;
sudo netfilter-persistent save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
hat tip:&lt;br /&gt;
* [https://serverfault.com/questions/431593/iptables-forwarding-between-two-interface]&lt;br /&gt;
* [https://www.raspberrypi.org/documentation/configuration/wireless/access-point-routed.md]&lt;br /&gt;
* [https://serverfault.com/questions/453254/routing-between-two-networks-on-linux]&lt;br /&gt;
* [https://www.digitalocean.com/community/tutorials/how-to-list-and-delete-iptables-firewall-rules]&lt;br /&gt;
&lt;br /&gt;
This stores the iptables configuration in &amp;lt;code&amp;gt;/etc/iptables/&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Joining AP==&lt;br /&gt;
&lt;br /&gt;
Join the wifi network from another laptop or phone.&lt;br /&gt;
&lt;br /&gt;
Verify that you receive an IP address and that your device can be pinged from bespin.&lt;br /&gt;
&lt;br /&gt;
Check your IP address from the device (whatsmyip.org) to ensure it is coming from the PIA region specified.&lt;br /&gt;
&lt;br /&gt;
===Troubleshooting EAPOL Timeout===&lt;br /&gt;
&lt;br /&gt;
If your test computer/laptop/phone connects to the network and authenticates okay but the EAPOL handshake step keeps timing out, it&amp;#039;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 (&amp;lt;code&amp;gt;sudo hostapd -d /etc/hostapd/hostapd.conf&amp;lt;/code&amp;gt;) and try to join the wifi network with another computer.&lt;br /&gt;
&lt;br /&gt;
===Troubleshooting Joining Wifi===&lt;br /&gt;
&lt;br /&gt;
View the kernel IP routing table and review it to make sure things are wired up correctly:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
netstat -rn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check iptables rules with this command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo iptables -S&lt;br /&gt;
# or&lt;br /&gt;
sudo iptables -L&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To limit to input/output rules only, do this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo iptables -L INPUT&lt;br /&gt;
sudo iptables -L OUTPUT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check that traffic is flowing okay:&lt;br /&gt;
&lt;br /&gt;
On bespin, run &amp;lt;code&amp;gt;tcpdump -i tun1&amp;lt;/code&amp;gt; (monitoring the openvpn tunnel) and &amp;lt;code&amp;gt;tcpdump -i wlan1&amp;lt;/code&amp;gt; (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.&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
The packets should also be going in &amp;#039;&amp;#039;&amp;#039;both&amp;#039;&amp;#039;&amp;#039; 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.&lt;br /&gt;
&lt;br /&gt;
Help from here: [https://serverfault.com/questions/453254/routing-between-two-networks-on-linux]&lt;br /&gt;
&lt;br /&gt;
===More Troubleshooting===&lt;br /&gt;
&lt;br /&gt;
If you restart the networking service on bespin, like this&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo service networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
then you&amp;#039;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.&lt;br /&gt;
&lt;br /&gt;
We specified the device name as part of udev, specifically the file &amp;lt;code&amp;gt;/etc/udev/rules.d/70-persistent-net.rules &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
So we need to reload udev:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo udevadm control --reload-rules &amp;amp;&amp;amp; udevadm trigger&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Well crap, that doesn&amp;#039;t work. If you reload the networking service, wifi breaks because wpa_supplicant reverts to a stupid network interface scheme, and apparently you&amp;#039;re hosed until you restart.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Bespin]]&lt;br /&gt;
[[Category:Machine]]&lt;br /&gt;
[[Category:PIA]]&lt;br /&gt;
[[Category:VPN]]&lt;br /&gt;
[[Category:Hostapd]]&lt;/div&gt;</summary>
		<author><name>Unknown user</name></author>
	</entry>
</feed>