OK: Following the rules as far as I can will make this a LONG post.
Problem
I can connect to the server from my Android phone running the OpenVPN Connect app when the phone is connected to a WiFi LAN.
It can be the same LAN as where the server runs or a different LAN, in which case the traffic is routed via the Internet (two routers involved in my house).
But even though the connection is successful I cannot reach anything at all on the server LAN or the Internet when OpenVPN is connected!
This is contrary to how it works with PPTP VPN, where I can access all resources on my home LAN and also browse the internet while connected.
So there is some difference in configuration somewhere....
1. Server config files
/etc/openvpn/server.conf
local 192.168.0.150
dev tun
proto udp
port 1194
ca /etc/openvpn/easy-rsa/keys/ca.crt
cert /etc/openvpn/easy-rsa/keys/BBOpenVPN.crt
key /etc/openvpn/easy-rsa/keys/BBOpenVPN.key
dh /etc/openvpn/easy-rsa/keys/dh1024.pem
server 10.8.0.0 255.255.255.0
ifconfig 10.8.0.1 10.8.0.2
push "route 10.8.0.1 255.255.255.255"
push "route 10.8.0.0 255.255.255.0"
push "route 192.168.0.150 255.255.255.0"
push "dhcp-option DNS 192.168.0.129"
push "redirect-gateway def1"
client-to-client
duplicate-cn
keepalive 10 120
tls-auth /etc/openvpn/easy-rsa/keys/ta.key 0
cipher AES-128-CBC
comp-lzo
user nobody
group nogroup
persist-key
persist-tun
status /var/log/openvpn-status.log 20
log /var/log/openvpn.log
verb 1
/etc/sysctl.conf
net.ipv4.ip_forward=1
vm.panic_on_oom = 0
vm.dirty_expire_centisecs = 1000
vm.dirty_writeback_centisecs = 1500
kernel.random.write_wakeup_threshold=128
kernel.random.read_wakeup_threshold=32
kernel.random.poolsize=512
kernel.random.entropy_avail=4096
vm.min_free_kbytes=16384
vm.swappiness=10
/etc/network/if-up.d/secure-rmc
#!/bin/bash
dec_to_bin() {
local remainder=''
local string=''
local number=$1
while [ 1 ]
do
let "remainder = $number % 2"
let "result = ($number / 2)"
number=$result
string=$remainder$string
if [ "$result" == 0 ]
then
break
fi
done
echo $string
}
bin_to_dec() {
local toprocess=$1
local result=0
while [ 1 ]
do
let "result = ($result*2)+${toprocess:0:1}"
toprocess=${toprocess:1}
if [ "$toprocess" == "" ]
then
break
fi
done
echo $result
}
ip_octet_to_bin() {
local oct=`dec_to_bin $1`
while [ ${#oct} -lt 8 ] ; do
oct=0$oct
done
echo $oct
}
ip_to_bin() {
local ip=$1
local first=`echo $ip | cut -d. -f1 | awk '{print $1}'`
local second=`echo $ip | cut -d. -f2 | awk '{print $1}'`
local third=`echo $ip | cut -d. -f3 | awk '{print $1}'`
local fourth=`echo $ip | cut -d. -f4 | awk '{print $1}'`
first=`ip_octet_to_bin $first`
second=`ip_octet_to_bin $second`
third=`ip_octet_to_bin $third`
fourth=`ip_octet_to_bin $fourth`
echo $first$second$third$fourth
}
bin_to_ip() {
local first=${1:0:8}
local second=${1:8:8}
local third=${1:16:8}
local fourth=${1:24:8}
first=`bin_to_dec $first`
second=`bin_to_dec $second`
third=`bin_to_dec $third`
fourth=`bin_to_dec $fourth`
echo $first.$second.$third.$fourth
}
bit_and() {
local in1=$1
local in2=$2
local out=''
while [ 1 ] ; do
local toadd=0
if [ "${in1:0:1}" == 1 ] ; then
if [ "${in2:0:1}" == 1 ] ; then
toadd=1
fi
fi
out=$out$toadd
in1=${in1:1}
in2=${in2:1}
if [ ${#in1} == 0 ] ; then
break
fi
done
echo $out;
}
get_subnet() {
local ip=`/sbin/ifconfig $1 | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`
local mask=`/sbin/ifconfig $1 | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f4 | awk '{ print $1}'`
ip=`ip_to_bin $ip`
if [ ${#ip} -eq 0 ]; then
logger -t secure-rmc "$1 has no IP"
exit 1
fi
mask=`ip_to_bin $mask`
local subnet=`bit_and $ip $mask`
local counter=0
local todo=$mask
while [ 1 ] ; do
if [ "${todo:0:1}" == 1 ] ; then
let "counter = $counter + 1"
fi
todo=${todo:1}
if [ "${#todo}" == 0 ] ; then
break
fi
done
subnet=`bin_to_ip $subnet`
subnet=$subnet/$counter
echo $subnet
}
logger -t iptables "Configuring ip tables for interface $IFACE"
if [ "$IFACE" != "lo" ]; then
NETMASK=$(get_subnet $IFACE)
if [ ${#NETMASK} -eq 0 ]; then
logger -t secure-rmc "netmask not found"
exit 1
fi
iptables -A INPUT -s $NETMASK -i $IFACE -j ACCEPT
iptables -t nat -A INPUT -i eth0 -p udp -m udp --dport 1194 -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source 192.168.0.150
iptables -A INPUT -i $IFACE -j DROP
fi
/etc/firewall-openvpn-rules.sh
#!/bin/sh
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source 192.168.0.150
2. My goal
Run an OpenVPN server on my home LAN such that I can connect to it from places like public WiFi, hotels abroad etc and securely do my stuff like I was back home in my own house.
3. Server Logfiles
/var/log/openvpn.log
These are the log entries following a successful connect attempt from an Android client on the same LAN as the server:
Tue May 6 01:53:24 2014 us=500585 MULTI: multi_create_instance called
Tue May 6 01:53:24 2014 us=501520 192.168.0.141:60884 Re-using SSL/TLS context
Tue May 6 01:53:24 2014 us=512470 192.168.0.141:60884 LZO compression initialized
Tue May 6 01:53:24 2014 us=582730 192.168.0.141:60884 Control Channel MTU parms [ L:1558 D:166 EF:66 EB:0 ET:0 EL:0 ]
Tue May 6 01:53:24 2014 us=583081 192.168.0.141:60884 Data Channel MTU parms [ L:1558 D:1450 EF:58 EB:135 ET:0 EL:0 AF:3/1 ]
Tue May 6 01:53:24 2014 us=583901 192.168.0.141:60884 Local Options String: 'V4,dev-type tun,link-mtu 1558,tun-mtu 1500,proto UDPv4,comp-lzo,keydir 0,cipher AES-128-CBC,auth SHA1,keysize 128,tls-auth,key-method 2,tls-server'
Tue May 6 01:53:24 2014 us=584093 192.168.0.141:60884 Expected Remote Options String: 'V4,dev-type tun,link-mtu 1558,tun-mtu 1500,proto UDPv4,comp-lzo,keydir 1,cipher AES-128-CBC,auth SHA1,keysize 128,tls-auth,key-method 2,tls-client'
Tue May 6 01:53:24 2014 us=584779 192.168.0.141:60884 Local Options hash (VER=V4): 'a2e63101'
Tue May 6 01:53:24 2014 us=585070 192.168.0.141:60884 Expected Remote Options hash (VER=V4): '272f1b58'
Tue May 6 01:53:24 2014 us=585652 192.168.0.141:60884 TLS: Initial packet from [AF_INET]192.168.0.141:60884, sid=9e66a288 233f6d54
Tue May 6 01:53:24 2014 us=785840 192.168.0.141:60884 VERIFY OK: depth=1, /C=US/ST=CA/L=SanFrancisco/O=Fort-Funston/OU=changeme/CN=changeme/name=changeme/emailAddress=mail@host.domain
Tue May 6 01:53:24 2014 us=788086 192.168.0.141:60884 VERIFY OK: depth=0, /C=US/ST=CA/L=SanFrancisco/O=Fort-Funston/OU=changeme/CN=BosseS4M/name=changeme/emailAddress=mail@host.domain
Tue May 6 01:53:24 2014 us=835097 192.168.0.141:60884 Data Channel Encrypt: Cipher 'AES-128-CBC' initialized with 128 bit key
Tue May 6 01:53:24 2014 us=839758 192.168.0.141:60884 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Tue May 6 01:53:24 2014 us=840010 192.168.0.141:60884 Data Channel Decrypt: Cipher 'AES-128-CBC' initialized with 128 bit key
Tue May 6 01:53:24 2014 us=840227 192.168.0.141:60884 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Tue May 6 01:53:24 2014 us=844813 192.168.0.141:60884 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 1024 bit RSA
Tue May 6 01:53:24 2014 us=845271 192.168.0.141:60884 [BosseS4M] Peer Connection Initiated with [AF_INET]192.168.0.141:60884
Tue May 6 01:53:24 2014 us=845894 BosseS4M/192.168.0.141:60884 MULTI_sva: pool returned IPv4=10.8.0.6, IPv6=bccd:800:8ced:200:14c2:700:5c68:5201
Tue May 6 01:53:24 2014 us=846510 BosseS4M/192.168.0.141:60884 MULTI: Learn: 10.8.0.6 -> BosseS4M/192.168.0.141:60884
Tue May 6 01:53:24 2014 us=846732 BosseS4M/192.168.0.141:60884 MULTI: primary virtual IP for BosseS4M/192.168.0.141:60884: 10.8.0.6
Tue May 6 01:53:25 2014 us=857041 BosseS4M/192.168.0.141:60884 PUSH: Received control message: 'PUSH_REQUEST'
Tue May 6 01:53:25 2014 us=857354 BosseS4M/192.168.0.141:60884 send_push_reply(): safe_cap=960
Tue May 6 01:53:25 2014 us=857907 BosseS4M/192.168.0.141:60884 SENT CONTROL [BosseS4M]: 'PUSH_REPLY,route 10.8.0.1 255.255.255.255,route 10.8.0.0 255.255.255.0,route 192.168.0.150 255.255.255.0,dhcp-option DNS 192.168.0.129,redirect-gateway def1,route 10.8.0.0 255.255.255.0,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5' (status=1)
/var/log/openvpn.log
These are the log entries following a successful connect attempt from an Android client on a different LAN as the server:
Tue May 6 02:03:25 2014 us=969635 MULTI: multi_create_instance called
Tue May 6 02:03:25 2014 us=970235 88.129.163.74:43632 Re-using SSL/TLS context
Tue May 6 02:03:25 2014 us=970514 88.129.163.74:43632 LZO compression initialized
Tue May 6 02:03:25 2014 us=971292 88.129.163.74:43632 Control Channel MTU parms [ L:1558 D:166 EF:66 EB:0 ET:0 EL:0 ]
Tue May 6 02:03:25 2014 us=971549 88.129.163.74:43632 Data Channel MTU parms [ L:1558 D:1450 EF:58 EB:135 ET:0 EL:0 AF:3/1 ]
Tue May 6 02:03:25 2014 us=972089 88.129.163.74:43632 Local Options String: 'V4,dev-type tun,link-mtu 1558,tun-mtu 1500,proto UDPv4,comp-lzo,keydir 0,cipher AES-128-CBC,auth SHA1,keysize 128,tls-auth,key-method 2,tls-server'
Tue May 6 02:03:25 2014 us=972399 88.129.163.74:43632 Expected Remote Options String: 'V4,dev-type tun,link-mtu 1558,tun-mtu 1500,proto UDPv4,comp-lzo,keydir 1,cipher AES-128-CBC,auth SHA1,keysize 128,tls-auth,key-method 2,tls-client'
Tue May 6 02:03:25 2014 us=972728 88.129.163.74:43632 Local Options hash (VER=V4): 'a2e63101'
Tue May 6 02:03:25 2014 us=973005 88.129.163.74:43632 Expected Remote Options hash (VER=V4): '272f1b58'
Tue May 6 02:03:25 2014 us=973390 88.129.163.74:43632 TLS: Initial packet from [AF_INET]88.129.163.74:43632, sid=ce82ec77 5e3057e7
Tue May 6 02:03:26 2014 us=211346 88.129.163.74:43632 VERIFY OK: depth=1, /C=US/ST=CA/L=SanFrancisco/O=Fort-Funston/OU=changeme/CN=changeme/name=changeme/emailAddress=mail@host.domain
Tue May 6 02:03:26 2014 us=213695 88.129.163.74:43632 VERIFY OK: depth=0, /C=US/ST=CA/L=SanFrancisco/O=Fort-Funston/OU=changeme/CN=BosseS4M/name=changeme/emailAddress=mail@host.domain
Tue May 6 02:03:26 2014 us=263651 88.129.163.74:43632 Data Channel Encrypt: Cipher 'AES-128-CBC' initialized with 128 bit key
Tue May 6 02:03:26 2014 us=263989 88.129.163.74:43632 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Tue May 6 02:03:26 2014 us=264188 88.129.163.74:43632 Data Channel Decrypt: Cipher 'AES-128-CBC' initialized with 128 bit key
Tue May 6 02:03:26 2014 us=264396 88.129.163.74:43632 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Tue May 6 02:03:26 2014 us=273090 88.129.163.74:43632 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 1024 bit RSA
Tue May 6 02:03:26 2014 us=273520 88.129.163.74:43632 [BosseS4M] Peer Connection Initiated with [AF_INET]88.129.163.74:43632
Tue May 6 02:03:26 2014 us=273926 BosseS4M/88.129.163.74:43632 MULTI_sva: pool returned IPv4=10.8.0.6, IPv6=bccd:800:8ced:200:14c2:700:f408:5101
Tue May 6 02:03:26 2014 us=274516 BosseS4M/88.129.163.74:43632 MULTI: Learn: 10.8.0.6 -> BosseS4M/88.129.163.74:43632
Tue May 6 02:03:26 2014 us=274717 BosseS4M/88.129.163.74:43632 MULTI: primary virtual IP for BosseS4M/88.129.163.74:43632: 10.8.0.6
Tue May 6 02:03:27 2014 us=285953 BosseS4M/88.129.163.74:43632 PUSH: Received control message: 'PUSH_REQUEST'
Tue May 6 02:03:27 2014 us=286300 BosseS4M/88.129.163.74:43632 send_push_reply(): safe_cap=960
Tue May 6 02:03:27 2014 us=286844 BosseS4M/88.129.163.74:43632 SENT CONTROL [BosseS4M]: 'PUSH_REPLY,route 10.8.0.1 255.255.255.255,route 10.8.0.0 255.255.255.0,route 192.168.0.150 255.255.255.0,dhcp-option DNS 192.168.0.129,redirect-gateway def1,route 10.8.0.0 255.255.255.0,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5' (status=1)
4. Client files
I have no idea how I can find the log or conf files on the Android OpenVPN Connect client!
I have looked in both the phone memory and in the SD-card but found nothing.