<?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=OpenVPN%2FStatic_Key</id>
	<title>OpenVPN/Static Key - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=OpenVPN%2FStatic_Key"/>
	<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=OpenVPN/Static_Key&amp;action=history"/>
	<updated>2026-06-19T19:14:59Z</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=OpenVPN/Static_Key&amp;diff=8596&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;  =Static Key VPN=  This is the simplest setup for a VPN configuration for small numbers of users and point-to-point VPN. There are more scalable options for larger OpenVPN ne...&quot;</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=OpenVPN/Static_Key&amp;diff=8596&amp;oldid=prev"/>
		<updated>2015-09-25T03:23:15Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;  =Static Key VPN=  This is the simplest setup for a VPN configuration for small numbers of users and point-to-point VPN. There are more scalable options for larger OpenVPN ne...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
=Static Key VPN=&lt;br /&gt;
&lt;br /&gt;
This is the simplest setup for a VPN configuration for small numbers of users and point-to-point VPN. There are more scalable options for larger OpenVPN networks.&lt;br /&gt;
&lt;br /&gt;
==On The Server==&lt;br /&gt;
&lt;br /&gt;
===Create OpenVPN Server Key===&lt;br /&gt;
&lt;br /&gt;
First, generate a key on the OpenVPN server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ openvpn --genkey --secret static.key&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now copy that VPN file over a secure medium onto the computer you&amp;#039;ll use as the OpenVPN client.&lt;br /&gt;
&lt;br /&gt;
===Server Config File===&lt;br /&gt;
&lt;br /&gt;
Create a server config file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cat server.ovpn&lt;br /&gt;
dev tun&lt;br /&gt;
ifconfig 10.8.0.1 10.8.0.2&lt;br /&gt;
secret static.key&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This server file creates a device called tun (or tun0, or tun1, etc)&lt;br /&gt;
&lt;br /&gt;
It sets up an IP address of 10.8.0.1, with a peer-to-peer IP address of 10.8.0.2 (that&amp;#039;ll be our single client).&lt;br /&gt;
&lt;br /&gt;
Finally, we point it to our static key.&lt;br /&gt;
&lt;br /&gt;
===Server Firewall Script===&lt;br /&gt;
&lt;br /&gt;
The server firewall script looks like the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Flush&lt;br /&gt;
iptables -F&lt;br /&gt;
&lt;br /&gt;
# allow SSH/HTTP/HTTPS&lt;br /&gt;
iptables -A INPUT  -p tcp --dport 22 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT&lt;br /&gt;
iptables -A INPUT  -p tcp --dport 80 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT&lt;br /&gt;
iptables -A INPUT  -p tcp --dport 443 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Set default policies for INPUT, FORWARD and OUTPUT chains&lt;br /&gt;
iptables -P INPUT DROP&lt;br /&gt;
iptables -P FORWARD DROP&lt;br /&gt;
iptables -P OUTPUT ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Set access for localhost&lt;br /&gt;
iptables -A INPUT -i lo -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Accept packets belonging to established and related connections&lt;br /&gt;
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Allow connections on 1198 for open vpn&lt;br /&gt;
iptables -A INPUT  -p udp --dport 1198 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p udp --dport 1198 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# OpenVPN   # this line is important!&lt;br /&gt;
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 1194 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Allow TUN interface connections to OpenVPN server&lt;br /&gt;
iptables -A INPUT -i tun+ -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
# Allow TUN interface connections to be forwarded through other interfaces&lt;br /&gt;
iptables -A FORWARD -i tun+ -j ACCEPT&lt;br /&gt;
iptables -A FORWARD -i tun+ -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT&lt;br /&gt;
iptables -A FORWARD -i eth0 -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
# NAT the VPN client traffic to the internet&lt;br /&gt;
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE&lt;br /&gt;
&lt;br /&gt;
# all out is ok&lt;br /&gt;
iptables -A OUTPUT -o tun+ -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The NAT rules allow traffic to get to the larger internet; the iptables rule came from here: https://openvpn.net/index.php/open-source/documentation/howto.html#redirect&lt;br /&gt;
&lt;br /&gt;
(Plus more info here: https://community.openvpn.net/openvpn/wiki/NatHack - it basically means, rewrite any VPN traffic to the OpenVPN server so that it looks like it natively came from the OpenVPN server.) &lt;br /&gt;
&lt;br /&gt;
Then restart the networking service on the OpenVPN server machine:&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;
===Forward Packets on Server===&lt;br /&gt;
&lt;br /&gt;
Make sure you are forwarding packets:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo &amp;quot;1&amp;quot; &amp;gt; /proc/sys/net/ipv4/ip_forward&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will ensure that any packet that the network interface receives is forwarded (specifically, forwarded to our tunnel device).&lt;br /&gt;
&lt;br /&gt;
===Start OpenVPN Server===&lt;br /&gt;
&lt;br /&gt;
Now start the OpenVPN server daemon on the OpenVPN server:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ openvpn --config server.conf --daemon&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Final Script===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cat server.sh&lt;br /&gt;
&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# ##########################&lt;br /&gt;
# &lt;br /&gt;
# Run an OpenVPN server &lt;br /&gt;
# at charlesreid1.com&lt;br /&gt;
# &lt;br /&gt;
# UDP port 1194&lt;br /&gt;
#&lt;br /&gt;
# &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -----------------------&lt;br /&gt;
# ip forwarding&lt;br /&gt;
echo &amp;quot;forwarding packets&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;1&amp;quot; &amp;gt; /proc/sys/net/ipv4/ip_forward&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -----------------------&lt;br /&gt;
# Start the OpenVPN server&lt;br /&gt;
echo &amp;quot;starting openvpn server&amp;quot;&lt;br /&gt;
&lt;br /&gt;
killall openvpn&lt;br /&gt;
openvpn --config rojo_server.ovpn&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -----------------------&lt;br /&gt;
# Firewall rules&lt;br /&gt;
echo &amp;quot;setting firewall rules&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Flush&lt;br /&gt;
iptables -F&lt;br /&gt;
&lt;br /&gt;
# -------------&lt;br /&gt;
# BEGIN&lt;br /&gt;
# My Firewall Settings&lt;br /&gt;
&lt;br /&gt;
# allow SSH/HTTP/HTTPS&lt;br /&gt;
iptables -A INPUT  -p tcp --dport 22 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT&lt;br /&gt;
iptables -A INPUT  -p tcp --dport 80 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT&lt;br /&gt;
iptables -A INPUT  -p tcp --dport 443 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Set default policies for INPUT, FORWARD and OUTPUT chains&lt;br /&gt;
iptables -P INPUT DROP&lt;br /&gt;
iptables -P FORWARD DROP&lt;br /&gt;
iptables -P OUTPUT ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Set access for localhost&lt;br /&gt;
iptables -A INPUT -i lo -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Accept packets belonging to established and related connections&lt;br /&gt;
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Allow connections on 1198 for open vpn&lt;br /&gt;
iptables -A INPUT  -p udp --dport 1198 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p udp --dport 1198 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# OpenVPN   # this line is important!&lt;br /&gt;
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 1194 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Allow TUN interface connections to OpenVPN server&lt;br /&gt;
iptables -A INPUT -i tun+ -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
# Allow TUN interface connections to be forwarded through other interfaces&lt;br /&gt;
iptables -A FORWARD -i tun+ -j ACCEPT&lt;br /&gt;
iptables -A FORWARD -i tun+ -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT&lt;br /&gt;
iptables -A FORWARD -i eth0 -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
# NAT the VPN client traffic to the internet&lt;br /&gt;
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE&lt;br /&gt;
&lt;br /&gt;
# all out is ok&lt;br /&gt;
iptables -A OUTPUT -o tun+ -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;done&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# Reload the firewall rules&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;restart networking services&amp;quot;&lt;br /&gt;
service networking restart&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Client==&lt;br /&gt;
&lt;br /&gt;
===Client Config File===&lt;br /&gt;
&lt;br /&gt;
On the client, create your client config file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cat client.ovpn&lt;br /&gt;
&lt;br /&gt;
remote &amp;lt;IP OF OPENVPN SERVER GOES HERE&amp;gt;&lt;br /&gt;
dev tun&lt;br /&gt;
ifconfig 10.8.0.2 10.8.0.1&lt;br /&gt;
secret rojo_static.key&lt;br /&gt;
redirect-gateway def1&lt;br /&gt;
dhcp-option DNS 10.8.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here we&amp;#039;re specifying the location of our OpenVPN server with the IP address&lt;br /&gt;
&lt;br /&gt;
Then we&amp;#039;re specifying a tunnel device with &amp;lt;code&amp;gt;dev tun&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then an IP of 10.8.0.2 with a peer-to-peer connection at 10.8.0.1 with &amp;lt;code&amp;gt;ifconfig&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the static server key,&lt;br /&gt;
&lt;br /&gt;
then &amp;lt;code&amp;gt;redirect-gatway def1&amp;lt;/code&amp;gt; which replaces the gateway router on our machine, so that all traffic, including DNS, will go through our VPN connection.&lt;br /&gt;
&lt;br /&gt;
===Client Firewall Script===&lt;br /&gt;
&lt;br /&gt;
The following are the firewall tables used by OpenVPN, broken down to explain them:&lt;br /&gt;
&lt;br /&gt;
Flush the existing rules in the ip tables: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# --------------------------&lt;br /&gt;
# Firewall rules&lt;br /&gt;
&lt;br /&gt;
iptables -F &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now set default policies for types of packets:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iptables -P INPUT DROP&lt;br /&gt;
iptables -P FORWARD DROP&lt;br /&gt;
iptables -P OUTPUT ACCEPT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Accept packets belonging to accepted connections:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Respond to pings (that&amp;#039;s what the 8 means):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iptables -A INPUT  -p icmp --icmp-type 8 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p icmp --icmp-type 0 -m state --state ESTABLISHED,RELATED -j ACCEPT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open port 1194 for OpenVPN:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iptables -A INPUT  -p udp --dport 1194 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p udp --dport 1194 -j ACCEPT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All outbound packets are OK:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iptables -A OUTPUT -o tun+ -j ACCEPT&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now print the rules:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
iptables -L -v&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See https://forums.openvpn.net/topic7722.html for other info.&lt;br /&gt;
&lt;br /&gt;
===Client Connect===&lt;br /&gt;
&lt;br /&gt;
Now we&amp;#039;ve got the firewall open on the server, and open on the client. We&amp;#039;ve got the OpenVPN daemon running on the server, and all that&amp;#039;s left is the client. Let&amp;#039;s connect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ openvpn --config client.ovpn&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Final Client Script===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cat server.sh&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
#&lt;br /&gt;
# ##########################&lt;br /&gt;
# &lt;br /&gt;
# Run an OpenVPN server &lt;br /&gt;
# at charlesreid1.com&lt;br /&gt;
# &lt;br /&gt;
# UDP port 1194&lt;br /&gt;
#&lt;br /&gt;
# &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -----------------------&lt;br /&gt;
# ip forwarding&lt;br /&gt;
echo &amp;quot;forwarding packets&amp;quot;&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;1&amp;quot; &amp;gt; /proc/sys/net/ipv4/ip_forward&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -----------------------&lt;br /&gt;
# Start the OpenVPN server&lt;br /&gt;
echo &amp;quot;starting openvpn server&amp;quot;&lt;br /&gt;
&lt;br /&gt;
killall openvpn&lt;br /&gt;
openvpn --config rojo_server.ovpn&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# -----------------------&lt;br /&gt;
# Firewall rules&lt;br /&gt;
echo &amp;quot;setting firewall rules&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Flush&lt;br /&gt;
iptables -F&lt;br /&gt;
&lt;br /&gt;
# -------------&lt;br /&gt;
# BEGIN&lt;br /&gt;
# My Firewall Settings&lt;br /&gt;
&lt;br /&gt;
# allow SSH/HTTP/HTTPS&lt;br /&gt;
iptables -A INPUT  -p tcp --dport 22 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT&lt;br /&gt;
iptables -A INPUT  -p tcp --dport 80 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT&lt;br /&gt;
iptables -A INPUT  -p tcp --dport 443 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Set default policies for INPUT, FORWARD and OUTPUT chains&lt;br /&gt;
iptables -P INPUT DROP&lt;br /&gt;
iptables -P FORWARD DROP&lt;br /&gt;
iptables -P OUTPUT ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Set access for localhost&lt;br /&gt;
iptables -A INPUT -i lo -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Accept packets belonging to established and related connections&lt;br /&gt;
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Allow connections on 1198 for open vpn&lt;br /&gt;
iptables -A INPUT  -p udp --dport 1198 -j ACCEPT&lt;br /&gt;
iptables -A OUTPUT -p udp --dport 1198 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# OpenVPN   # this line is important!&lt;br /&gt;
iptables -A INPUT -i eth0 -m state --state NEW -p udp --dport 1194 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Allow TUN interface connections to OpenVPN server&lt;br /&gt;
iptables -A INPUT -i tun+ -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
# Allow TUN interface connections to be forwarded through other interfaces&lt;br /&gt;
iptables -A FORWARD -i tun+ -j ACCEPT&lt;br /&gt;
iptables -A FORWARD -i tun+ -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT&lt;br /&gt;
iptables -A FORWARD -i eth0 -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
# NAT the VPN client traffic to the internet&lt;br /&gt;
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE&lt;br /&gt;
&lt;br /&gt;
# all out is ok&lt;br /&gt;
iptables -A OUTPUT -o tun+ -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;done&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# ----------------------------&lt;br /&gt;
# Reload the firewall rules&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;restart networking services&amp;quot;&lt;br /&gt;
service networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing the Static VPN==&lt;br /&gt;
&lt;br /&gt;
===Wireshark and Ping (Local)===&lt;br /&gt;
&lt;br /&gt;
You can test to make sure that 10.8.0.1 and 10.8.0.2 can see each other on the virtual private network by pinging one from the other.&lt;br /&gt;
&lt;br /&gt;
For example, from the client (10.8.0.2), we can run ping, and specify that ping should use our tunnel device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ping -I tun0 10.8.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now open wireshark and begin a packet capture on the same tun0 interface. You should see the ping and response packets from Wireshark:&lt;br /&gt;
&lt;br /&gt;
[[Image:WiresharkPingVPN.png|800px]]&lt;br /&gt;
&lt;br /&gt;
===Wireshark and Ping (Remote)===&lt;br /&gt;
&lt;br /&gt;
Now you can test all of those firewall rules we set for the OpenVPN server, that set rules for forwarding packets from the tunnel to the ethernet and to the internet at large:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ ping -I tun0 wikipedia.org&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure you can see the ping and response in Wireshark:&lt;br /&gt;
&lt;br /&gt;
[[Image:WiresharkPingVPNRemote.png|800px]]&lt;br /&gt;
&lt;br /&gt;
This ping and response is happening over the OpenVPN tunnel we created, and that tunnel traffic is then being forwarded to the OpenVPN server&amp;#039;s network device.&lt;br /&gt;
&lt;br /&gt;
===Wireshark and Browser===&lt;br /&gt;
&lt;br /&gt;
Now test out that the &amp;lt;code&amp;gt;redirect-gatway&amp;lt;/code&amp;gt; directive in our config file is actually redirecting traffic as expected. Here, we visit Yahoo.com from the OpenVPN client, and check out the packet capture of the tunnel device while we do that. We should see all of our traffic passing through the OpenVPN tunnel:&lt;br /&gt;
&lt;br /&gt;
[[Image:WiresharkVPNYahoo.png|800px]]&lt;br /&gt;
&lt;br /&gt;
Further up there were several DNS packets for yahoo.com, and we can see all of the packet traffic from Yahoo to the OpenVPN client for loading the page.&lt;br /&gt;
&lt;br /&gt;
===Wireshark and SSH===&lt;br /&gt;
&lt;br /&gt;
One more test, just to make sure that the &amp;lt;code&amp;gt;redirect-gateway&amp;lt;/code&amp;gt; directive really redirects ALL traffic, and not just SOME traffic. Let&amp;#039;s SSH to a remote machine, and verify that we can do that. From the OpenVPN client, we run Wireshark. We should see SSH traffic:&lt;br /&gt;
&lt;br /&gt;
[[Image:WiresharkVPNSSH.png|800px]]&lt;br /&gt;
&lt;br /&gt;
Sure enough, there it is! Hooray!&lt;br /&gt;
&lt;br /&gt;
===OpenVPN and WhatIsMyIP.com===&lt;br /&gt;
&lt;br /&gt;
I spent a long time trying to diagnose why, every time I used Google or WhatIsMyIp or a similar service to check my IP address from the OpenVPN client, it would always give the native IP address of the OpenVPN client, instead of the OpenVPN server&amp;#039;s IP address (indicating that for some reason, the traffic to that site was passing through the regular network connection, which should not be allowed by the &amp;lt;code&amp;gt;redirect-gateway&amp;lt;/code&amp;gt; directive.) &lt;br /&gt;
&lt;br /&gt;
I could see my virtual IP, 10.8.0.2. I could also see a native IP, for my ethernet connection (which is how I&amp;#039;m connected to the OopenVPN server). My browser was using the VPN tunnel, because when I was browsing the web I would see corresponding HTTP traffic passing through the tun0 tunnel device, and encrypted TCP data passing through the eth0 device.&lt;br /&gt;
&lt;br /&gt;
So what&amp;#039;s going on here?&lt;br /&gt;
&lt;br /&gt;
Turns out, OpenVPN doesn&amp;#039;t tunnel your IPv6 traffic by default. Because whatismyip.com is capable of using IPv6, the client connects to whatismyip.com via IPv6, &amp;quot;in the clear&amp;quot; - not through the OpenVPN.&lt;br /&gt;
&lt;br /&gt;
==IPv6==&lt;br /&gt;
&lt;br /&gt;
OpenVPN does not create a tunnel for IPv6 traffic by default. &lt;br /&gt;
&lt;br /&gt;
I ran a quick test to uncover this fact. First, I visited a few websites while sniffing the tunnel device with [[Wireshark]]. I saw some traffic, basically what I excpected. But then I did the same thing while sniffing the ethernet device.&lt;br /&gt;
&lt;br /&gt;
I visited Yahoo.com and saw TCP packets going between my local computer&amp;#039;s IPv6 address and some other IPv6 address:&lt;br /&gt;
&lt;br /&gt;
[[Image:WiresharkVPNIPv6.png|800px]]&lt;br /&gt;
&lt;br /&gt;
When I did a reverse whois with the IPv6 address, it was the site I was visiting - Yahoo.com.&lt;br /&gt;
&lt;br /&gt;
In other words, traffic was passing directly from my computer to the sites I was visiting, via IPv6. Even though it was encrypted, it was not going through OpenVPN.&lt;br /&gt;
&lt;br /&gt;
===Server Solution: Enable IPv6 on OpenVPN===&lt;br /&gt;
&lt;br /&gt;
https://community.openvpn.net/openvpn/wiki/IPv6&lt;br /&gt;
&lt;br /&gt;
Confusing.&lt;br /&gt;
&lt;br /&gt;
Not clear whether this works for both IPv4 and IPv6, or just IPv6.&lt;br /&gt;
&lt;br /&gt;
===Client Solution 1: Disable IPv6 Temporarily===&lt;br /&gt;
&lt;br /&gt;
To temporarily disable IPv6:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sysctl -w net.ipv6.conf.all.disable_ipv6=1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To temporarily re-enable IPv6:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sysctl -w net.ipv6.conf.all.disable_ipv6=0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that you should be wary of using this as a temporary solution - as soon as you forget to do it, your VPN session is as good as useless.&lt;br /&gt;
&lt;br /&gt;
===Client Solution 2: Disable IPv6 with Sysctl===&lt;br /&gt;
&lt;br /&gt;
You can disable IPv6 temporarily using sysctl.&lt;br /&gt;
&lt;br /&gt;
Edit &amp;lt;code&amp;gt;/etc/sysctl.conf&amp;lt;/code&amp;gt; and add:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
net.ipv6.conf.all.disable_ipv6 = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and remove your loopback IPv6 interface by commenting out this line from &amp;lt;code&amp;gt;/etc/hosts&amp;lt;/code&amp;gt; (if relevant):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#::1        localhost.localdomain   localhost&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to reboot.&lt;br /&gt;
&lt;br /&gt;
===Client Solution 3: Disable IPv6 in the Kernel===&lt;br /&gt;
&lt;br /&gt;
Edit your boot loader line, to include the flag &amp;lt;code&amp;gt;ipv6.disable=1&amp;lt;/code&amp;gt;, by editing &amp;lt;code&amp;gt;/etc/default/grub&amp;lt;/code&amp;gt; to include the extra portion:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GRUB_CMDLINE_LINUX_DEFAULT=&amp;quot;ipv6.disable=1&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to restart the client machine. Now the client machine will not use IPv6, and all IPv4 traffic is routed through OpenVPN.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==More Gotchas==&lt;br /&gt;
&lt;br /&gt;
===DNS Not Responding===&lt;br /&gt;
&lt;br /&gt;
One other problem I ran into was, all my web traffic was loading really, really slowly. When I looked at it with Wireshark, I saw that all my DNS lookups were being denied.&lt;br /&gt;
&lt;br /&gt;
Turns out, the DNS servers that my computer was using were automatically being grabbed from my wireless router, and populated on boot. And those DNS servers were coming from my ISP - Comcast - whose DNS servers are specifically for Comcast customers, and not for random arbitrary people. &lt;br /&gt;
&lt;br /&gt;
Soooo, the good news was, my DNS queries were not coming from my native IP address, but were properly being sent through the VPN tunnel. Yay! The problem was, those DNS queries were being sent to Comcast&amp;#039;s DNS servers, from the endpoint of the VPN tunnel, which was not using a Comcast ISP. So the DNS queries failed, because of where they were coming from.&lt;br /&gt;
&lt;br /&gt;
The solution? Change my DNS servers to something different, by changing &amp;lt;code&amp;gt;/etc/resolv.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want DNS servers controlled by The Goog, a large corporation that CLAIMS they don&amp;#039;t keep DNS lookups, but probably do, you can add the following to your resolv.conf file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nameserver 8.8.8.8&lt;br /&gt;
nameserver 8.8.8.4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a good &amp;quot;test&amp;quot; DNS server, as it is &amp;quot;always on&amp;quot; and can be used from just about anywhere (but not China).&lt;br /&gt;
&lt;br /&gt;
Wikileaks has a great list of more trustworthy sources of DNS lookups: https://wikileaks.org/wiki/Alternative_DNS&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s OpenDNS: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
nameserver 208.67.222.220&lt;br /&gt;
nameserver 208.67.222.222&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Testing Again==&lt;br /&gt;
&lt;br /&gt;
Once you get OpenVPN working, you can verify it is working.&lt;br /&gt;
&lt;br /&gt;
Fire up Wireshark.&lt;br /&gt;
&lt;br /&gt;
If you monitor the tunnel device &amp;lt;code&amp;gt;tun0&amp;lt;/code&amp;gt; you&amp;#039;ll be able to see all of the traffic to and from the OpenVPN server in the clear. This will be either TCP, HTTP, or HTTPS traffic, as well as DNS queries. The tunnel device is being encrypted before it is sent out over the ethernet connection, and is decrypted at the other end.&lt;br /&gt;
&lt;br /&gt;
If you monitor the ethernet device &amp;lt;code&amp;gt;eth0&amp;lt;/code&amp;gt; you&amp;#039;ll ONLY see encrypted OpenVPN traffic - UDP traffic on port 1194. Traffic passing through the tunnel, which appears in the clear to us when monitoring the tunnel device, is being encrypted before it is sent out over the ethernet device. By the time the packets get to the ethernet device, they&amp;#039;re OpenVPN or TCP packets that are being passed back and forth between two and only two machines: the OpenVPN client and the OpenVPN server. No information about the sites visited, the DNS queries sent, the servers used, etc., can be seen by someone sniffing the ethernet connection.&lt;br /&gt;
&lt;br /&gt;
===Wireshark Statistics===&lt;br /&gt;
&lt;br /&gt;
You can view the protocols of the packets you&amp;#039;ve listened to by clicking Statistics &amp;gt; Protocol Hierarchy. &lt;br /&gt;
&lt;br /&gt;
Depending on your port configuration, you&amp;#039;ll see different things.&lt;br /&gt;
&lt;br /&gt;
Using a stock OpenVPN configuration, and sniffing the ethernet connection eth0, I see lots of OpenVPN UDP traffic on port 1198:&lt;br /&gt;
&lt;br /&gt;
[[Image:WiresharkVPNUDP.png|800px]]&lt;br /&gt;
&lt;br /&gt;
If you use an OpenVPN server connection on a direct port, like port 80, the traffic will show up in Wireshark slightly differently. Instead of being UDP packet traffic on port 1198, which is easily recognized as OpenVPN traffic, the traffic will actually be TCP packets on port 80. In this case, the Wireshark Protocol Hierarchy report will look slightly different:&lt;br /&gt;
&lt;br /&gt;
[[Image:WiresharkVPNTCP.png|800px]]&lt;br /&gt;
&lt;br /&gt;
==Take-Home Message==&lt;br /&gt;
&lt;br /&gt;
No matter what, at the end of the day, if your OpenVPN connection is working, you should see something like this: two computers, passing a lot of traffic back and forth, in some kind of encrypted protocol. You can run Wireshark on your own ethernet device while generating some web traffic over the VPN, and run a Protocol Hierarchy analysis, or a Conversation analysis, and all of your web traffic should match the description above: TCP protocol, encrypted, and only traveling between your computer and the OpenVPN server. If you see any DNS queries with websites you&amp;#039;re visiting, or if you see IPV6 traffic bypassing the OpenVPN and revealing your native IP address to the world, review the steps above, and:&lt;br /&gt;
* Turn on &amp;lt;code&amp;gt;redirect-gateway def1&amp;lt;/code&amp;gt; in your OpenVPN client configuration to route ALL of your traffic through OpenVPN&lt;br /&gt;
* Turn off IPv6 with &amp;lt;code&amp;gt;sysctl -w net.ipv6.conf.all.disable_ipv6=1&amp;lt;/code&amp;gt; to prevent IPv6 bypassing OpenVPN&lt;br /&gt;
&lt;br /&gt;
=Static Key Recap=&lt;br /&gt;
&lt;br /&gt;
We covered the setup of a static key, single-user OpenVPN server running on a remote machine. We covered the OpenVPN installation process, then covered the firewall rules required to run OpenVPN clients and servers, then covered the OpenVPN configuration options that need to be set.&lt;br /&gt;
&lt;br /&gt;
We then showed how to use Wireshark to debug the OpenVPN tunnel and make sure it works properly.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{OpenVPNFlag}}&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
	</entry>
</feed>