I have built OpenVPN on Ubuntu on Raspberry Pi 2.
Connecting to OpenVPN from my Windows 7 client it is flawlessly good.
However, adding configuration of STunnel, I can connect, but cannot visit any website.
And after a short while (around several seconds) after connection, the connection is reset.
I have asked Dr. Google but there is no luck...
Could anyone please kindly help :oops:
OpenVpn server.conf
port 1194
proto tcp
# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
# Use "dev tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# If you want to control access policies
# over the VPN, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use "dev-node" for this.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key). Each client
# and the server must have their own cert and
# key file. The server and all clients will
# use the same ca file.
#
# See the "easy-rsa" directory for a series
# of scripts for generating RSA certificates
# and private keys. Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
ca ca.crt
cert server.crt
key server.key
# Diffie hellman parameters.
# Generate your own with:
# openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh dh4096.pem
# Configure server mode and supply a VPN subnet
# for OpenVPN to draw client addresses from.
# The server will take 10.8.0.1 for itself,
# the rest will be made available to clients.
# Each client will be able to reach the server
# on 10.8.0.1. Comment this line out if you are
# ethernet bridging. See the man page for more info.
server 10.8.0.0 255.255.255.0
# Maintain a record of client virtual IP address
# associations in this file. If OpenVPN goes down or
# is restarted, reconnecting clients can be assigned
# the same virtual IP address from the pool that was
# previously assigned.
;ifconfig-pool-persist ipp.txt
# Configure server mode for ethernet bridging.
# You must first use your OS's bridging capability
# to bridge the TAP interface with the ethernet
# NIC interface. Then you must manually set the
# IP/netmask on the bridge interface, here we
# assume 10.8.0.4/255.255.255.0. Finally we
# must set aside an IP range in this subnet
# (start=10.8.0.50 end=10.8.0.100) to allocate
# to connecting clients. Leave this line commented
# out unless you are ethernet bridging.
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
# Push routes to the client to allow it
# to reach other private subnets behind
# the server. Remember that these
# private subnets will also need
# to know to route the OpenVPN client
# address pool (10.8.0.0/255.255.255.0)
# back to the OpenVPN server.
;push "route 192.168.12.0 255.255.255.0"
;push "route 192.168.99.0 255.255.255.0"
# If enabled, this directive will configure
# all clients to redirect their default
# network gateway through the VPN, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the VPN
# (The OpenVPN server machine may need to NAT
# the TUN/TAP interface to the internet in
# order for this to work properly).
# CAVEAT: May break client's network config if
# client's local DHCP server packets get routed
# through the tunnel. Solution: make sure
# client's local DHCP server is reachable via
# a more specific route than the default route
# of 0.0.0.0/0.0.0.0.
push "redirect-gateway"
# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses. CAVEAT:
# http://openvpn.net/faq.html#dhcpcaveats
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"
# Uncomment this directive to allow different
# clients to be able to "see" each other.
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server's TUN/TAP interface.
client-to-client
# The keepalive directive causes ping-like
# messages to be sent back and forth over
# the link so that each side knows when
# the other side has gone down.
# Ping every 10 seconds, assume that remote
# peer is down if no ping received during
# a 120 second time period.
keepalive 5 30
# For extra security beyond that provided
# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
# openvpn --genkey --secret ta.key
#
# The server and each client must have
# a copy of this key.
# The second parameter should be '0'
# on the server and '1' on the clients.
;tls-auth ta.key 0 # This file is secret
# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
;cipher BF-CBC # Blowfish (default)
cipher AES-128-CBC # AES
;cipher DES-EDE3-CBC # Triple-DES
# Enable compression on the VPN link.
# If you enable it here, you must also
# enable it in the client config file.
comp-lzo
# The maximum number of concurrently connected
# clients we want to allow.
max-clients 10
# It's a good idea to reduce the OpenVPN
# daemon's privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
;user nobody
;group nobody
# The persist options will try to avoid
# accessing certain resources on restart
# that may no longer be accessible because
# of the privilege downgrade.
persist-key
persist-tun
# Output a short status file showing
# current connections, truncated
# and rewritten every minute.
status /var/log/openvpn-status.log
# By default, log messages will go to the syslog (or
# on Windows, if running as a service, they will go to
# the "\Program Files\OpenVPN\log" directory).
# Use log or log-append to override this default.
# "log" will truncate the log file on OpenVPN startup,
# while "log-append" will append to it. Use one
# or the other (but not both).
log /var/log/openvpn.log
log-append /var/log/openvpn.log
# Set the appropriate level of log
# file verbosity.
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 6
# Silence repeating messages. At most 20
# sequential messages of the same message
# category will be output to the log.
mute 20
tun-mtu 1400
tcp-nodelay
stunnel.conf
sslVersion = all
options = NO_SSLv2
chroot = /var/lib/stunnel4/
; PID is created inside the chroot jail
pid = /stunnel4.pid
delay = yes
; Debugging stuff (may useful for troubleshooting)
debug = 7
output = /var/log/stunnel4/stunnel.log
setuid = stunnel4
setgid = stunnel4
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
;compression = zlib
[openvpn]
accept = 443
connect = 1194
cert = /etc/stunnel/server.pem
key = /etc/stunnel/server.key
firewall-setup.sh
#!/bin/bash
# OpenVPN
iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state NEW -p tcp --dport 1194 -j ACCEPT
# Allow TUN interface connections to OpenVPN server
iptables -A INPUT -i tun+ -j ACCEPT
# Allow TUN interface connections to be forwarded through other interfaces
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o tun+ -m state --state RELATED,ESTABLISHED -j ACCEPT
# NAT the VPN client traffic to the internet
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
iptables -A OUTPUT -o tun+ -j ACCEPT
OpenVPN Server Log
Fri May 8 19:21:26 2015 us=653122 y2kbug/127.0.0.1:39740 TCPv4_SERVER WRITE [101] to [AF_INET]127.0.0.1:39740: P_DATA_V1 kid=0 DATA len=100
Fri May 8 19:21:26 2015 us=653693 y2kbug/127.0.0.1:39740 TCPv4_SERVER READ [117] from [AF_INET]127.0.0.1:39740: P_DATA_V1 kid=0 DATA len=116
Fri May 8 19:21:26 2015 us=653918 y2kbug/127.0.0.1:39740 TUN WRITE [62]
Fri May 8 19:21:26 2015 us=661205 y2kbug/127.0.0.1:39740 TCPv4_SERVER READ [85] from [AF_INET]127.0.0.1:39740: P_DATA_V1 kid=0 DATA len=84
Fri May 8 19:21:26 2015 us=661440 y2kbug/127.0.0.1:39740 TUN WRITE [40]
Fri May 8 19:21:26 2015 us=661706 y2kbug/127.0.0.1:39740 NOTE: --mute triggered...
Fri May 8 19:22:30 2015 us=626899 y2kbug/127.0.0.1:39740 1471 variation(s) on previous 20 message(s) suppressed by --mute
Fri May 8 19:22:30 2015 us=627309 y2kbug/127.0.0.1:39740 [y2kbug] Inactivity timeout (--ping-restart), restarting
Fri May 8 19:22:30 2015 us=627497 y2kbug/127.0.0.1:39740 SIGUSR1[soft,ping-restart] received, client-instance restarting
Fri May 8 19:22:30 2015 us=628563 TCP/UDP: Closing socket
OpenVPN Client Log
Fri May 08 19:21:15 2015 OpenVPN 2.3.6 x86_64-w64-mingw32 [SSL (OpenSSL)] [LZO] [PKCS11] [IPv6] built on Mar 19 2015
Fri May 08 19:21:15 2015 library versions: OpenSSL 1.0.1m 19 Mar 2015, LZO 2.08
Enter Management Password:
Fri May 08 19:21:15 2015 MANAGEMENT: TCP Socket listening on [AF_INET]127.0.0.1:25340
Fri May 08 19:21:15 2015 Need hold release from management interface, waiting...
Fri May 08 19:21:15 2015 MANAGEMENT: Client connected from [AF_INET]127.0.0.1:25340
Fri May 08 19:21:16 2015 MANAGEMENT: CMD 'state on'
Fri May 08 19:21:16 2015 MANAGEMENT: CMD 'log all on'
Fri May 08 19:21:16 2015 MANAGEMENT: CMD 'hold off'
Fri May 08 19:21:16 2015 MANAGEMENT: CMD 'hold release'
Fri May 08 19:21:18 2015 MANAGEMENT: CMD 'password [...]'
Fri May 08 19:21:18 2015 WARNING: this configuration may cache passwords in memory -- use the auth-nocache option to prevent this
Fri May 08 19:21:18 2015 WARNING: normally if you use --mssfix and/or --fragment, you should also set --tun-mtu 1500 (currently it is 1400)
Fri May 08 19:21:18 2015 Socket Buffers: R=[8192->8192] S=[8192->8192]
Fri May 08 19:21:18 2015 MANAGEMENT: >STATE:1431084078,RESOLVE,,,
Fri May 08 19:21:18 2015 Attempting to establish TCP connection with [AF_INET]127.0.0.1:1194 [nonblock]
Fri May 08 19:21:18 2015 MANAGEMENT: >STATE:1431084078,TCP_CONNECT,,,
Fri May 08 19:21:18 2015 TCP connection established with [AF_INET]127.0.0.1:1194
Fri May 08 19:21:18 2015 TCPv4_CLIENT link local: [undef]
Fri May 08 19:21:18 2015 TCPv4_CLIENT link remote: [AF_INET]127.0.0.1:1194
Fri May 08 19:21:18 2015 MANAGEMENT: >STATE:1431084078,WAIT,,,
Fri May 08 19:21:19 2015 MANAGEMENT: >STATE:1431084079,AUTH,,,
Fri May 08 19:21:19 2015 TLS: Initial packet from [AF_INET]127.0.0.1:1194, sid=029d8166 4b0f6cac
Fri May 08 19:21:21 2015 VERIFY OK: depth=1, C=HK, ST=HK, L=Hong Kong, O=y2kbug.pw, OU=y2kbug.pw, CN=y2kbug.pw CA, name=EasyRSA, emailAddress=openvpn@y2kbug.pw
Fri May 08 19:21:21 2015 VERIFY OK: nsCertType=SERVER
Fri May 08 19:21:21 2015 VERIFY OK: depth=0, C=HK, ST=HK, L=Hong Kong, O=y2kbug.pw, OU=y2kbug.pw, CN=y2kbug, name=EasyRSA, emailAddress=openvpn@y2kbug.pw
Fri May 08 19:21:23 2015 Data Channel Encrypt: Cipher 'AES-128-CBC' initialized with 128 bit key
Fri May 08 19:21:23 2015 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri May 08 19:21:23 2015 Data Channel Decrypt: Cipher 'AES-128-CBC' initialized with 128 bit key
Fri May 08 19:21:23 2015 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Fri May 08 19:21:23 2015 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 4096 bit RSA
Fri May 08 19:21:23 2015 [y2kbug] Peer Connection Initiated with [AF_INET]127.0.0.1:1194
Fri May 08 19:21:25 2015 MANAGEMENT: >STATE:1431084085,GET_CONFIG,,,
Fri May 08 19:21:26 2015 SENT CONTROL [y2kbug]: 'PUSH_REQUEST' (status=1)
Fri May 08 19:21:26 2015 PUSH: Received control message: 'PUSH_REPLY,redirect-gateway,dhcp-option DNS 8.8.8.8,dhcp-option DNS 8.8.4.4,dhcp-option DNS 208.67.222.222,dhcp-option DNS 208.67.220.220,route 10.8.0.0 255.255.255.0,topology net30,ping 5,ping-restart 30,socket-flags TCP_NODELAY,ifconfig 10.8.0.6 10.8.0.5'
Fri May 08 19:21:26 2015 OPTIONS IMPORT: timers and/or timeouts modified
Fri May 08 19:21:26 2015 OPTIONS IMPORT: --socket-flags option modified
Fri May 08 19:21:26 2015 OPTIONS IMPORT: --ifconfig/up options modified
Fri May 08 19:21:26 2015 OPTIONS IMPORT: route options modified
Fri May 08 19:21:26 2015 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
Fri May 08 19:21:26 2015 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
Fri May 08 19:21:26 2015 MANAGEMENT: >STATE:1431084086,ASSIGN_IP,,10.8.0.6,
Fri May 08 19:21:26 2015 open_tun, tt->ipv6=0
Fri May 08 19:21:26 2015 TAP-WIN32 device [Local Area Connection 10] opened: \\.\Global\{1AFA6EF0-D020-44E6-8617-2EDFEC2D1427}.tap
Fri May 08 19:21:26 2015 TAP-Windows Driver Version 9.21
Fri May 08 19:21:26 2015 Notified TAP-Windows driver to set a DHCP IP/netmask of 10.8.0.6/255.255.255.252 on interface {1AFA6EF0-D020-44E6-8617-2EDFEC2D1427} [DHCP-serv: 10.8.0.5, lease-time: 31536000]
Fri May 08 19:21:26 2015 Successful ARP Flush on interface [47] {1AFA6EF0-D020-44E6-8617-2EDFEC2D1427}
Fri May 08 19:21:31 2015 TEST ROUTES: 2/2 succeeded len=1 ret=1 a=0 u/d=up
Fri May 08 19:21:31 2015 C:\Windows\system32\route.exe ADD 127.0.0.1 MASK 255.255.255.255 192.168.12.1
Fri May 08 19:21:31 2015 ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=10 and dwForwardType=4
Fri May 08 19:21:31 2015 Route addition via IPAPI succeeded [adaptive]
Fri May 08 19:21:31 2015 C:\Windows\system32\route.exe DELETE 0.0.0.0 MASK 0.0.0.0 192.168.12.1
Fri May 08 19:21:31 2015 Route deletion via IPAPI succeeded [adaptive]
Fri May 08 19:21:31 2015 C:\Windows\system32\route.exe ADD 0.0.0.0 MASK 0.0.0.0 10.8.0.5
Fri May 08 19:21:31 2015 ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=20 and dwForwardType=4
Fri May 08 19:21:31 2015 Route addition via IPAPI succeeded [adaptive]
Fri May 08 19:21:31 2015 MANAGEMENT: >STATE:1431084091,ADD_ROUTES,,,
Fri May 08 19:21:31 2015 C:\Windows\system32\route.exe ADD 10.8.0.0 MASK 255.255.255.0 10.8.0.5
Fri May 08 19:21:31 2015 ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=20 and dwForwardType=4
Fri May 08 19:21:31 2015 Route addition via IPAPI succeeded [adaptive]
Fri May 08 19:21:31 2015 Initialization Sequence Completed
Fri May 08 19:21:31 2015 MANAGEMENT: >STATE:1431084091,CONNECTED,SUCCESS,10.8.0.6,127.0.0.1
Fri May 08 19:21:49 2015 write TCPv4_CLIENT: Connection reset by peer (WSAECONNRESET) (code=10054)
Fri May 08 19:21:49 2015 Connection reset, restarting [-1]
Fri May 08 19:21:49 2015 SIGUSR1[soft,connection-reset] received, process restarting
Fri May 08 19:21:49 2015 MANAGEMENT: >STATE:1431084109,RECONNECTING,connection-reset,,
Fri May 08 19:21:49 2015 Restart pause, 5 second(s)
Fri May 08 19:21:54 2015 WARNING: normally if you use --mssfix and/or --fragment, you should also set --tun-mtu 1500 (currently it is 1400)
Fri May 08 19:21:54 2015 Socket Buffers: R=[8192->8192] S=[8192->8192]
Fri May 08 19:21:54 2015 MANAGEMENT: >STATE:1431084114,RESOLVE,,,
Fri May 08 19:21:54 2015 Attempting to establish TCP connection with [AF_INET]127.0.0.1:1194 [nonblock]
Fri May 08 19:21:54 2015 MANAGEMENT: >STATE:1431084114,TCP_CONNECT,,,
Fri May 08 19:21:54 2015 TCP connection established with [AF_INET]127.0.0.1:1194
Fri May 08 19:21:54 2015 TCPv4_CLIENT link local: [undef]
Fri May 08 19:21:54 2015 TCPv4_CLIENT link remote: [AF_INET]127.0.0.1:1194
Fri May 08 19:21:54 2015 MANAGEMENT: >STATE:1431084114,WAIT,,,
Fri May 08 19:21:56 2015 C:\Windows\system32\route.exe DELETE 10.8.0.0 MASK 255.255.255.0 10.8.0.5
Fri May 08 19:21:56 2015 Route deletion via IPAPI succeeded [adaptive]
Fri May 08 19:21:56 2015 C:\Windows\system32\route.exe DELETE 127.0.0.1 MASK 255.255.255.255 192.168.12.1
Fri May 08 19:21:56 2015 Route deletion via IPAPI succeeded [adaptive]
Fri May 08 19:21:56 2015 C:\Windows\system32\route.exe DELETE 0.0.0.0 MASK 0.0.0.0 10.8.0.5
Fri May 08 19:21:56 2015 Route deletion via IPAPI succeeded [adaptive]
Fri May 08 19:21:56 2015 C:\Windows\system32\route.exe ADD 0.0.0.0 MASK 0.0.0.0 192.168.12.1
Fri May 08 19:21:56 2015 ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=10 and dwForwardType=4
Fri May 08 19:21:56 2015 Route addition via IPAPI succeeded [adaptive]
Fri May 08 19:21:56 2015 Closing TUN/TAP interface
Fri May 08 19:21:56 2015 SIGTERM[hard,] received, process exiting
Fri May 08 19:21:56 2015 MANAGEMENT: >STATE:1431084116,EXITING,SIGTERM,,
STunnel Client Log
2015.05.08 19:21:18 LOG5[44]: Service [openvpn] accepted connection from 127.0.0.1:63528
2015.05.08 19:21:18 LOG5[44]: s_connect: connected 124.244.72.97:443
2015.05.08 19:21:18 LOG5[44]: Service [openvpn] connected remote server from 192.168.12.74:63529
2015.05.08 19:21:49 LOG3[44]: SSL_write: Connection reset by peer (WSAECONNRESET) (10054)
2015.05.08 19:21:49 LOG5[44]: Connection reset: 103477 byte(s) sent to SSL, 104414 byte(s) sent to socket
2015.05.08 19:21:54 LOG5[45]: Service [openvpn] accepted connection from 127.0.0.1:63682
2015.05.08 19:22:04 LOG3[45]: s_connect: s_poll_wait 124.244.72.97:443: TIMEOUTconnect exceeded
2015.05.08 19:22:04 LOG5[45]: Connection reset: 0 byte(s) sent to SSL, 0 byte(s) sent to socket
Thanks.