Step by step to install OpenVPN inside a Jail in FreeNAS 11.1-U1

BullsEyeFR78

Cadet
Joined
Mar 23, 2020
Messages
5
Hi,
First of all, thanks a lot for the detailed guide. Although, I can't manage to make it fully work...

I'm running Freenas 11.3-U1 and installed a brand new jail for OpenVPN. Did someone already manage to make it work on this version?
In fact, I'm able to establish the VPN between a remote device (I've tried on Windows and Android). But, I can't access anyhting on the other side of the VPN. My remote devices get the IP address 10.8.0.6 with a gateway on 10.8.0.5. I can't even ping this one. Same for the other side 10.8.0.1 or 10.8.0.2. I see traffic in the logs on the server, but I think it's just the keep alive feature.


Please find the server configuration below:

Code:
#################################################
# Sample OpenVPN 2.0 config file for            #
# multi-client server.                          #
#                                               #
# This file is for the server side              #
# of a many-clients <-> one-server              #
# OpenVPN configuration.                        #
#                                               #
# OpenVPN also supports                         #
# single-machine <-> single-machine             #
# configurations (See the Examples page         #
# on the web site for more info).               #
#                                               #
# This config should work on Windows            #
# or Linux/BSD systems.  Remember on            #
# Windows to quote pathnames and use            #
# double backslashes, e.g.:                     #
# "C:\\Program Files\\OpenVPN\\config\\foo.key" #
#                                               #
# Comments are preceded with '#' or ';'         #
#################################################

# Which local IP address should OpenVPN
# listen on? (optional)
;local a.b.c.d

# Which TCP/UDP port should OpenVPN listen on?
# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one.  You will need to
# open up this port on your firewall.
port 1194

# TCP or UDP server?
;proto tcp
proto udp

# "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

# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel if you
# have more than one.  On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don't need this.
;dev-node MyTap

# 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 /usr/local/etc/openvpn/keys/ca.crt
cert /usr/local/etc/openvpn/keys/openvpn-server.crt
key /usr/local/etc/openvpn/keys/openvpn-server.key  # This file should be kept secret

# Diffie hellman parameters.
# Generate your own with:
#   openssl dhparam -out dh2048.pem 2048
dh /usr/local/etc/openvpn/keys/dh.pem

# Network topology
# Should be subnet (addressing via IP)
# unless Windows clients v2.0.9 and lower have to
# be supported (then net30, i.e. a /30 per client)
# Defaults to net30 (not recommended)
;topology subnet

# 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

# Configure server mode for ethernet bridging
# using a DHCP-proxy, where clients talk
# to the OpenVPN server-side DHCP server
# to receive their IP address allocation
# and DNS server addresses.  You must first use
# your OS's bridging capability to bridge the TAP
# interface with the ethernet NIC interface.
# Note: this mode only works on clients (such as
# Windows), where the client-side TAP adapter is
# bound to a DHCP client.
;server-bridge

# 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.2.0 255.255.255.0"

# To assign specific IP addresses to specific
# clients or if a connecting client has a private
# subnet behind it that should also have VPN access,
# use the subdirectory "ccd" for client-specific
# configuration files (see man page for more info).

# EXAMPLE: Suppose the client
# having the certificate common name "Thelonious"
# also has a small subnet behind his connecting
# machine, such as 192.168.40.128/255.255.255.248.
# First, uncomment out these lines:
;client-config-dir ccd
;route 192.168.40.128 255.255.255.248
# Then create a file ccd/Thelonious with this line:
#   iroute 192.168.40.128 255.255.255.248
# This will allow Thelonious' private subnet to
# access the VPN.  This example will only work
# if you are routing, not bridging, i.e. you are
# using "dev tun" and "server" directives.

# EXAMPLE: Suppose you want to give
# Thelonious a fixed VPN IP address of 10.9.0.1.
# First uncomment out these lines:
;client-config-dir ccd
;route 10.9.0.0 255.255.255.252
# Then add this line to ccd/Thelonious:
#   ifconfig-push 10.9.0.1 10.9.0.2

# Suppose that you want to enable different
# firewall access policies for different groups
# of clients.  There are two methods:
# (1) Run multiple OpenVPN daemons, one for each
#     group, and firewall the TUN/TAP interface
#     for each group/daemon appropriately.
# (2) (Advanced) Create a script to dynamically
#     modify the firewall in response to access
#     from different clients.  See man
#     page for more info on learn-address script.
;learn-address ./script

# 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
# or bridge the TUN/TAP interface to the internet
# in order for this to work properly).
;push "redirect-gateway def1 bypass-dhcp"

# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses.  CAVEAT:
# http://openvpn.net/faq.html#dhcpcaveats
# The addresses below refer to the public
# DNS servers provided by opendns.com.
;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

# Uncomment this directive if multiple clients
# might connect with the same certificate/key
# files or common names.  This is recommended
# only for testing purposes.  For production use,
# each client should have its own certificate/key
# pair.
#
# IF YOU HAVE NOT GENERATED INDIVIDUAL
# CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
# EACH HAVING ITS OWN UNIQUE "COMMON NAME",
# UNCOMMENT THIS LINE OUT.
;duplicate-cn

# 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 10 120

# 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 /usr/local/etc/openvpn/keys/ta.key 0 # This file is secret
remote-cert-tls client

# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
# Note that v2.4 client/server will automatically
# negotiate AES-256-GCM in TLS mode.
# See also the ncp-cipher option in the manpage
cipher AES-256-CBC

# Enable compression on the VPN link and push the
# option to the client (v2.4+ only, for earlier
# versions see below)
;compress lz4-v2
;push "compress lz4-v2"

# For compression compatible with older clients use comp-lzo
# 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 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         openvpn.log
;log-append  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

# Notify the client that when the server restarts so it
# can automatically reconnect.
explicit-exit-notify 1



Please find below the client configuration:

Code:
##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server.     #
#                                            #
# This configuration can be used by multiple #
# clients, however each client should have   #
# its own cert and key files.                #
#                                            #
# On Windows, you might want to rename this  #
# file so it has a .ovpn extension           #
##############################################

# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client

# Use the same setting as you are using on
# the server.
# 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

# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel
# if you have more than one.  On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap

# Are we connecting to a TCP or
# UDP server?  Use the same setting as
# on the server.
;proto tcp
proto udp

# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote MYDOMAIN 1194
;remote my-server-2 1194

# Choose a random host from the remote
# list for load-balancing.  Otherwise
# try hosts in the order specified.
;remote-random

# Keep trying indefinitely to resolve the
# host name of the OpenVPN server.  Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite

# Most clients don't need to bind to
# a specific local port number.
nobind

# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nobody

# Try to preserve some state across restarts.
persist-key
persist-tun

# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here.  See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

# Wireless networks often produce a lot
# of duplicate packets.  Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings

# SSL/TLS parms.
# See the server config file for more
# description.  It's best to use
# a separate .crt/.key file pair
# for each client.  A single ca
# file can be used for all clients.
ca ca.crt
cert Parker.crt
key Parker.key

# Verify server certificate by checking that the
# certicate has the correct key usage set.
# This is an important precaution to protect against
# a potential attack discussed here:
#  http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the keyUsage set to
#   digitalSignature, keyEncipherment
# and the extendedKeyUsage to
#   serverAuth
# EasyRSA can do this for you.
remote-cert-tls server

# If a tls-auth key is used on the server
# then every client must also have the key.
tls-auth ta.key 1

# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
# Note that v2.4 client/server will automatically
# negotiate AES-256-GCM in TLS mode.
# See also the ncp-cipher option in the manpage
cipher AES-256-CBC

# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
#comp-lzo

# Set log file verbosity.
verb 3

# Silence repeating messages
;mute 20



Please find below the log from the Android device:

Code:
23:42:33.230 -- ----- OpenVPN Start -----

23:42:33.231 -- EVENT: CORE_THREAD_ACTIVE

23:42:33.234 -- OpenVPN core 3.git::728733ae:Release android arm64 64-bit PT_PROXY built on Aug 14 2019 14:13:26

23:42:33.279 -- Frame=512/2048/512 mssfix-ctrl=1250

23:42:33.292 -- UNUSED OPTIONS
4 [resolv-retry] [infinite]
5 [nobind]
6 [persist-key]
7 [persist-tun]
15 [verb] [3]

23:42:33.299 -- EVENT: RESOLVE

23:42:33.327 -- Contacting 90.127.x.x:1194 via UDP

23:42:33.328 -- EVENT: WAIT

23:42:33.345 -- Connecting to [MYDOMAIN]:1194 (90.127.x.x) via UDPv4

23:42:33.351 -- EVENT: CONNECTING

23:42:33.360 -- Tunnel Options:V4,dev-type tun,link-mtu 1557,tun-mtu 1500,proto UDPv4,keydir 1,cipher AES-256-CBC,auth SHA1,keysize 256,tls-auth,key-method 2,tls-client

23:42:33.360 -- Creds: UsernameEmpty/PasswordEmpty

23:42:33.361 -- Peer Info:
IV_GUI_VER=OC30Android
IV_VER=3.git::728733ae:Release
IV_PLAT=android
IV_NCP=2
IV_TCPNL=1
IV_PROTO=2
IV_AUTO_SESS=1


23:42:33.367 -- VERIFY OK : depth=1
cert. version     : 3
serial number     : E9:98:98:E0:A2:99:C8:BF
issuer name       : CN=OpenVPN FreeNAS CA
subject name      : CN=OpenVPN FreeNAS CA
issued  on        : 2020-03-23 16:50:22
expires on        : 2030-03-21 16:50:22
signed using      : RSA with SHA-256
RSA key size      : 2048 bits
basic constraints : CA=true
key usage         : Key Cert Sign, CRL Sign


23:42:33.368 -- VERIFY OK : depth=0
cert. version     : 3
serial number     : 65:70:FE:4B:0D:27:BF:E3:0B:0D:24:9C:3C:C1:18:EF
issuer name       : CN=OpenVPN FreeNAS CA
subject name      : CN=openvpn-server
issued  on        : 2020-03-23 16:51:08
expires on        : 2023-03-08 16:51:08
signed using      : RSA with SHA-256
RSA key size      : 2048 bits
basic constraints : CA=false
subject alt name  : openvpn-server
key usage         : Digital Signature, Key Encipherment
ext key usage     : TLS Web Server Authentication


23:42:33.413 -- SSL Handshake: TLSv1.2/TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384

23:42:33.414 -- Session is ACTIVE

23:42:33.414 -- EVENT: GET_CONFIG

23:42:33.425 -- Sending PUSH_REQUEST to server...

23:42:33.425 -- OPTIONS:
0 [route] [192.168.2.0] [255.255.255.0]
1 [route] [10.8.0.1]
2 [topology] [net30]
3 [ping] [10]
4 [ping-restart] [120]
5 [ifconfig] [10.8.0.6] [10.8.0.5]
6 [peer-id] [0]
7 [cipher] [AES-256-GCM]


23:42:33.426 -- PROTOCOL OPTIONS:
  cipher: AES-256-GCM
  digest: SHA1
  compress: NONE
  peer ID: 0

23:42:33.426 -- EVENT: ASSIGN_IP

23:42:33.576 -- Connected via tun

23:42:33.579 -- EVENT: CONNECTED info='MYDOMAIN:1194 (90.127.x.x) via /UDPv4 on tun/10.8.0.6/ gw=[10.8.0.5/]' trans=TO_CONNECTED



One thing I've noticed on the server logs is that it's written everywhere UDPv6. IPv6 is disabled for this jail. Could it be related?

Thanks in avance for your help.

Cheers.
 

BullsEyeFR78

Cadet
Joined
Mar 23, 2020
Messages
5
Hi Bibi,

Thanks for the quick answer. I've created another Jail using your script. Still the same. When I try to ping devices on my local network from remote, it doesn't work. Also, if I try to reach the admin page of my Freenas on HTTP, it doesn't respond. I'm clueless... IS there any test I could carry out to fully validate my connection ?

Cheers.

Use this
 

Bibi40k

Contributor
Joined
Jan 26, 2018
Messages
136
Hi,
there is no a simple answer. There are a lot of users with this problem.
Did you forward UPT or TCP on your router ? Is it capable of NAT.. i don't know if this is the problem, i'm just asking/guessing ...
 

BullsEyeFR78

Cadet
Joined
Mar 23, 2020
Messages
5
Yes, UDP port 1194 redirected to local IP of my OpenVPN jail.

Hi,
there is no a simple answer. There are a lot of users with this problem.
Did you forward UPT or TCP on your router ? Is it capable of NAT.. i don't know if this is the problem, i'm just asking/guessing ...
 

BullsEyeFR78

Cadet
Joined
Mar 23, 2020
Messages
5
When I disable the NAT rule on my router, connections fails on the remote device. So, NAT is working.
 

BullsEyeFR78

Cadet
Joined
Mar 23, 2020
Messages
5
I've checked the running services, and I think there's something wrong there, unless I'm mistaken.

root@OpenVPN:~ # service openvpn status
openvpn is running as pid 38013.
root@OpenVPN:~ # service ipfw status
ipfw is enabled
root@OpenVPN:~ # service ipfw start
ifconfig: tun1: bad value

tun259
ifconfig: ioctl SIOCSIFNAME (set name): File exists

Firewall rules loaded.
root@OpenVPN:~ #


Does it mean the firewall and routing services are not working. This would make completely sense as there is no traffic.
 

galantis

Cadet
Joined
Feb 3, 2020
Messages
7
Hi,
First of all, thanks a lot for the detailed guide. Although, I can't manage to make it fully work...

I'm running Freenas 11.3-U1 and installed a brand new jail for OpenVPN. Did someone already manage to make it work on this version?
In fact, I'm able to establish the VPN between a remote device (I've tried on Windows and Android). But, I can't access anyhting on the other side of the VPN. My remote devices get the IP address 10.8.0.6 with a gateway on 10.8.0.5. I can't even ping this one. Same for the other side 10.8.0.1 or 10.8.0.2. I see traffic in the logs on the server, but I think it's just the keep alive feature.


Please find the server configuration below:

Code:
#################################################
# Sample OpenVPN 2.0 config file for            #
# multi-client server.                          #
#                                               #
# This file is for the server side              #
# of a many-clients <-> one-server              #
# OpenVPN configuration.                        #
#                                               #
# OpenVPN also supports                         #
# single-machine <-> single-machine             #
# configurations (See the Examples page         #
# on the web site for more info).               #
#                                               #
# This config should work on Windows            #
# or Linux/BSD systems.  Remember on            #
# Windows to quote pathnames and use            #
# double backslashes, e.g.:                     #
# "C:\\Program Files\\OpenVPN\\config\\foo.key" #
#                                               #
# Comments are preceded with '#' or ';'         #
#################################################

# Which local IP address should OpenVPN
# listen on? (optional)
;local a.b.c.d

# Which TCP/UDP port should OpenVPN listen on?
# If you want to run multiple OpenVPN instances
# on the same machine, use a different port
# number for each one.  You will need to
# open up this port on your firewall.
port 1194

# TCP or UDP server?
;proto tcp
proto udp

# "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

# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel if you
# have more than one.  On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don't need this.
;dev-node MyTap

# 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 /usr/local/etc/openvpn/keys/ca.crt
cert /usr/local/etc/openvpn/keys/openvpn-server.crt
key /usr/local/etc/openvpn/keys/openvpn-server.key  # This file should be kept secret

# Diffie hellman parameters.
# Generate your own with:
#   openssl dhparam -out dh2048.pem 2048
dh /usr/local/etc/openvpn/keys/dh.pem

# Network topology
# Should be subnet (addressing via IP)
# unless Windows clients v2.0.9 and lower have to
# be supported (then net30, i.e. a /30 per client)
# Defaults to net30 (not recommended)
;topology subnet

# 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

# Configure server mode for ethernet bridging
# using a DHCP-proxy, where clients talk
# to the OpenVPN server-side DHCP server
# to receive their IP address allocation
# and DNS server addresses.  You must first use
# your OS's bridging capability to bridge the TAP
# interface with the ethernet NIC interface.
# Note: this mode only works on clients (such as
# Windows), where the client-side TAP adapter is
# bound to a DHCP client.
;server-bridge

# 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.2.0 255.255.255.0"

# To assign specific IP addresses to specific
# clients or if a connecting client has a private
# subnet behind it that should also have VPN access,
# use the subdirectory "ccd" for client-specific
# configuration files (see man page for more info).

# EXAMPLE: Suppose the client
# having the certificate common name "Thelonious"
# also has a small subnet behind his connecting
# machine, such as 192.168.40.128/255.255.255.248.
# First, uncomment out these lines:
;client-config-dir ccd
;route 192.168.40.128 255.255.255.248
# Then create a file ccd/Thelonious with this line:
#   iroute 192.168.40.128 255.255.255.248
# This will allow Thelonious' private subnet to
# access the VPN.  This example will only work
# if you are routing, not bridging, i.e. you are
# using "dev tun" and "server" directives.

# EXAMPLE: Suppose you want to give
# Thelonious a fixed VPN IP address of 10.9.0.1.
# First uncomment out these lines:
;client-config-dir ccd
;route 10.9.0.0 255.255.255.252
# Then add this line to ccd/Thelonious:
#   ifconfig-push 10.9.0.1 10.9.0.2

# Suppose that you want to enable different
# firewall access policies for different groups
# of clients.  There are two methods:
# (1) Run multiple OpenVPN daemons, one for each
#     group, and firewall the TUN/TAP interface
#     for each group/daemon appropriately.
# (2) (Advanced) Create a script to dynamically
#     modify the firewall in response to access
#     from different clients.  See man
#     page for more info on learn-address script.
;learn-address ./script

# 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
# or bridge the TUN/TAP interface to the internet
# in order for this to work properly).
;push "redirect-gateway def1 bypass-dhcp"

# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses.  CAVEAT:
# http://openvpn.net/faq.html#dhcpcaveats
# The addresses below refer to the public
# DNS servers provided by opendns.com.
;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

# Uncomment this directive if multiple clients
# might connect with the same certificate/key
# files or common names.  This is recommended
# only for testing purposes.  For production use,
# each client should have its own certificate/key
# pair.
#
# IF YOU HAVE NOT GENERATED INDIVIDUAL
# CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
# EACH HAVING ITS OWN UNIQUE "COMMON NAME",
# UNCOMMENT THIS LINE OUT.
;duplicate-cn

# 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 10 120

# 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 /usr/local/etc/openvpn/keys/ta.key 0 # This file is secret
remote-cert-tls client

# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
# Note that v2.4 client/server will automatically
# negotiate AES-256-GCM in TLS mode.
# See also the ncp-cipher option in the manpage
cipher AES-256-CBC

# Enable compression on the VPN link and push the
# option to the client (v2.4+ only, for earlier
# versions see below)
;compress lz4-v2
;push "compress lz4-v2"

# For compression compatible with older clients use comp-lzo
# 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 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         openvpn.log
;log-append  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

# Notify the client that when the server restarts so it
# can automatically reconnect.
explicit-exit-notify 1



Please find below the client configuration:

Code:
##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server.     #
#                                            #
# This configuration can be used by multiple #
# clients, however each client should have   #
# its own cert and key files.                #
#                                            #
# On Windows, you might want to rename this  #
# file so it has a .ovpn extension           #
##############################################

# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client

# Use the same setting as you are using on
# the server.
# 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

# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel
# if you have more than one.  On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap

# Are we connecting to a TCP or
# UDP server?  Use the same setting as
# on the server.
;proto tcp
proto udp

# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote MYDOMAIN 1194
;remote my-server-2 1194

# Choose a random host from the remote
# list for load-balancing.  Otherwise
# try hosts in the order specified.
;remote-random

# Keep trying indefinitely to resolve the
# host name of the OpenVPN server.  Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite

# Most clients don't need to bind to
# a specific local port number.
nobind

# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nobody

# Try to preserve some state across restarts.
persist-key
persist-tun

# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here.  See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

# Wireless networks often produce a lot
# of duplicate packets.  Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings

# SSL/TLS parms.
# See the server config file for more
# description.  It's best to use
# a separate .crt/.key file pair
# for each client.  A single ca
# file can be used for all clients.
ca ca.crt
cert Parker.crt
key Parker.key

# Verify server certificate by checking that the
# certicate has the correct key usage set.
# This is an important precaution to protect against
# a potential attack discussed here:
#  http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the keyUsage set to
#   digitalSignature, keyEncipherment
# and the extendedKeyUsage to
#   serverAuth
# EasyRSA can do this for you.
remote-cert-tls server

# If a tls-auth key is used on the server
# then every client must also have the key.
tls-auth ta.key 1

# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
# Note that v2.4 client/server will automatically
# negotiate AES-256-GCM in TLS mode.
# See also the ncp-cipher option in the manpage
cipher AES-256-CBC

# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
#comp-lzo

# Set log file verbosity.
verb 3

# Silence repeating messages
;mute 20



Please find below the log from the Android device:

Code:
23:42:33.230 -- ----- OpenVPN Start -----

23:42:33.231 -- EVENT: CORE_THREAD_ACTIVE

23:42:33.234 -- OpenVPN core 3.git::728733ae:Release android arm64 64-bit PT_PROXY built on Aug 14 2019 14:13:26

23:42:33.279 -- Frame=512/2048/512 mssfix-ctrl=1250

23:42:33.292 -- UNUSED OPTIONS
4 [resolv-retry] [infinite]
5 [nobind]
6 [persist-key]
7 [persist-tun]
15 [verb] [3]

23:42:33.299 -- EVENT: RESOLVE

23:42:33.327 -- Contacting 90.127.x.x:1194 via UDP

23:42:33.328 -- EVENT: WAIT

23:42:33.345 -- Connecting to [MYDOMAIN]:1194 (90.127.x.x) via UDPv4

23:42:33.351 -- EVENT: CONNECTING

23:42:33.360 -- Tunnel Options:V4,dev-type tun,link-mtu 1557,tun-mtu 1500,proto UDPv4,keydir 1,cipher AES-256-CBC,auth SHA1,keysize 256,tls-auth,key-method 2,tls-client

23:42:33.360 -- Creds: UsernameEmpty/PasswordEmpty

23:42:33.361 -- Peer Info:
IV_GUI_VER=OC30Android
IV_VER=3.git::728733ae:Release
IV_PLAT=android
IV_NCP=2
IV_TCPNL=1
IV_PROTO=2
IV_AUTO_SESS=1


23:42:33.367 -- VERIFY OK : depth=1
cert. version     : 3
serial number     : E9:98:98:E0:A2:99:C8:BF
issuer name       : CN=OpenVPN FreeNAS CA
subject name      : CN=OpenVPN FreeNAS CA
issued  on        : 2020-03-23 16:50:22
expires on        : 2030-03-21 16:50:22
signed using      : RSA with SHA-256
RSA key size      : 2048 bits
basic constraints : CA=true
key usage         : Key Cert Sign, CRL Sign


23:42:33.368 -- VERIFY OK : depth=0
cert. version     : 3
serial number     : 65:70:FE:4B:0D:27:BF:E3:0B:0D:24:9C:3C:C1:18:EF
issuer name       : CN=OpenVPN FreeNAS CA
subject name      : CN=openvpn-server
issued  on        : 2020-03-23 16:51:08
expires on        : 2023-03-08 16:51:08
signed using      : RSA with SHA-256
RSA key size      : 2048 bits
basic constraints : CA=false
subject alt name  : openvpn-server
key usage         : Digital Signature, Key Encipherment
ext key usage     : TLS Web Server Authentication


23:42:33.413 -- SSL Handshake: TLSv1.2/TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384

23:42:33.414 -- Session is ACTIVE

23:42:33.414 -- EVENT: GET_CONFIG

23:42:33.425 -- Sending PUSH_REQUEST to server...

23:42:33.425 -- OPTIONS:
0 [route] [192.168.2.0] [255.255.255.0]
1 [route] [10.8.0.1]
2 [topology] [net30]
3 [ping] [10]
4 [ping-restart] [120]
5 [ifconfig] [10.8.0.6] [10.8.0.5]
6 [peer-id] [0]
7 [cipher] [AES-256-GCM]


23:42:33.426 -- PROTOCOL OPTIONS:
  cipher: AES-256-GCM
  digest: SHA1
  compress: NONE
  peer ID: 0

23:42:33.426 -- EVENT: ASSIGN_IP

23:42:33.576 -- Connected via tun

23:42:33.579 -- EVENT: CONNECTED info='MYDOMAIN:1194 (90.127.x.x) via /UDPv4 on tun/10.8.0.6/ gw=[10.8.0.5/]' trans=TO_CONNECTED



One thing I've noticed on the server logs is that it's written everywhere UDPv6. IPv6 is disabled for this jail. Could it be related?

Thanks in avance for your help.

Cheers.

Running into similar issues on 11.3-U1 as well, see post #259.
I'm seriously doubting if there's even anyone who managed to get it working in 11.3. This FN version doesn't really seem a recipe for success if I'm reading the various threads that are passing by.
I stumbled upon this thread describing jail networking issues as well. It triggered the creation of this bug. Let's put our hope in 11.3-U2.
If I find some time maybe I'll try getting it to work in 11.2 to rule out any other misconfigurations.
 

Marcelofs1

Dabbler
Joined
Jul 17, 2015
Messages
24
Ok, some small updates.
1 - I deleted ALL jails related to OpenVPN
2 - Followed the automatic install based on this script by @Bibi40k
3 - When running, it loaded all old inputs (incuding the cert passwords) - script runs really fast like 30 secs total
4 - Email did not work but I got the file generated and load into my cellphone (Android 10)

Connected at the first attempt (that was the first time I got success using the automatic script). While connected to the same wi-fi network I was able to connect and browse internet - yay!

Turned off the wi-fi on the phone and tried from LTE. I connected on the first attempt but internet browsing did not work. I am now getting the configuration files to compare and see if I can find the reason for this difference. My router seems to be configured correctly as I can connect from LTE. It is unclear to me why I cannot reach internet from inside the jail when connecting over LTE.
If found, I will update here.
 

napalmd

Dabbler
Joined
Aug 24, 2017
Messages
11
Hi. I also followed the script from Bibi40k but can't get it to work. already tried 2 times, deleting old jail and rebooting server, same results.
many errors are returned during script, and at the end the openvpn service is not running and cert files are not created...
Code:
root@freenas2[~/OpenVPN-on-FreeNAS-in-iocage]# ./install.sh

Iocage name not set, default Name is [OpenVPN]: openvpn
Jail IP not set, default is [192.168.1.66]: 192.168.1.62
External PORT not set, default is [1194]:
Interface name not set, default is [vnet0]:

Jail creation in progress...
openvpn successfully created!

Testing Host DNS response to pkg.freebsd.org
Testing openvpn's SRV response to pkg.freebsd.org
pkg.freebsd.org's SRV record could not be verified.

Testing openvpn's DNSSEC response to pkg.freebsd.org
pkg.freebsd.org could not be reached via DNSSEC.

Testing openvpn's DNS response to pkg.freebsd.org
pkg.freebsd.org could not be reached via DNS, check openvpn's network configuration

cp: /mnt/storage6/iocage/jails/openvpn/root/usr/local/share/examples/openvpn/sample-config-files/server.conf: No such file or directory
cp: /mnt/storage6/iocage/jails/openvpn/root/usr/local/share/examples/openvpn/sample-config-files/client.conf: No such file or directory
cp: /mnt/storage6/iocage/jails/openvpn/root/usr/local/share/easy-rsa/vars: No such file or directory
cp: /mnt/storage6/iocage/jails/openvpn/root/usr/local/share/easy-rsa: No such file or directory
sed: 1: "s|{IP_RANGE}|192.168.1. ...": unescaped newline inside substitute pattern
Please type Country Code [US]: PT
Please type State/Province [California]: Braga
Please type City/Locality [San Francisco]: Braga
Please type Organization [Copyleft Certificate Co]: myorg
Please type E-mail [me@example.net]: myorg@myorg.pt
Please type Organizational Unit [My Organizational Unit]:

Generating ...
'/root/openvpn-configs/server/easy-rsa/pki' dir...
cp: /root/openvpn-configs/server/easy-rsa/vars: No such file or directory
/root/OpenVPN-on-FreeNAS-in-iocage/scripts/keys.sh: line 12: cd: /root/openvpn-configs/server/easy-rsa: No such file or directory

Building Certificate Authority...
'/root/openvpn-configs/server/easy-rsa/pki/ca.crt'
'/root/openvpn-configs/server/easy-rsa/pki/private/ca.key'
/root/OpenVPN-on-FreeNAS-in-iocage/scripts/keys.sh: line 23: cd: /root/openvpn-configs/server/easy-rsa: No such file or directory

Building Server Certificates...
'/root/openvpn-configs/server/easy-rsa/pki/reqs/openvpn-server.req'
'/root/openvpn-configs/server/easy-rsa/pki/private/openvpn-server.key'
/root/OpenVPN-on-FreeNAS-in-iocage/scripts/keys.sh: line 34: cd: /root/openvpn-configs/server/easy-rsa: No such file or directory

Generateing Diffie Hellman Parameters...
'/root/openvpn-configs/server/easy-rsa/pki/dh.pem'
/root/OpenVPN-on-FreeNAS-in-iocage/scripts/keys.sh: line 44: cd: /root/openvpn-configs/server/easy-rsa: No such file or directory

Generating TA key...
'/root/openvpn-configs/server/easy-rsa/ta.key'
/root/OpenVPN-on-FreeNAS-in-iocage/scripts/keys.sh: line 54: cd: /root/openvpn-configs/server/easy-rsa: No such file or directory

Actual clients/users list:
Enter clients names/usernames for OpenVPN separated by 'space' (you wife kid1 kid2): coelhos

New clients/users list: myname

Building Client Certificate for 'myname'...
/root/OpenVPN-on-FreeNAS-in-iocage/scripts/keys.sh: line 81: cd: /root/openvpn-configs/server/easy-rsa: No such file or directory
/root/OpenVPN-on-FreeNAS-in-iocage/scripts/keys.sh: line 90: cd: /root/openvpn-configs/server/easy-rsa: No such file or directory
cp: pki/issued/myname.crt: No such file or directory
cp: pki/private/myname.key: No such file or directory

The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly, please wait...
pkg: Error fetching http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly/Latest/pkg.txz: No address record
A pre-built version of pkg could not be found for your system.
Consider changing PACKAGESITE or installing it from ports: 'ports-mgmt/pkg'.
Command: pkg upgrade -y failed!
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg from pkg+http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly, please wait...
pkg: Error fetching http://pkg.FreeBSD.org/FreeBSD:11:amd64/quarterly/Latest/pkg.txz: No address record
A pre-built version of pkg could not be found for your system.
Consider changing PACKAGESITE or installing it from ports: 'ports-mgmt/pkg'.
Command: pkg update failed!
* Stopping openvpn
  + Executing prestop OK
  + Stopping services OK
  + Tearing down VNET OK
  + Removing devfs_ruleset: 5 OK
  + Removing jail process OK
  + Executing poststop OK
* Starting openvpn
  + Started OK
  + Using devfs_ruleset: 5
  + Configuring VNET OK
  + Using IP options: vnet
  + Starting services OK
  + Executing poststart OK

Starting sendmail.
Starting sendmail_msp_queue.
tar: Removing leading '/' from member names
a root/openvpn-configs/clients/myname.ovpn
Sending mail to "edited"
jexec: execvp: mpack: No such file or directory
Command: mpack -s OpenVPN files OpenVPN-Clients.tar "edited" failed!
Installation Complete!
Log into your router and forward external port  to internal 192.168.1.62:
Log into OpenVPN iocage with 'iocage console OpenVPN'
 

napalmd

Dabbler
Joined
Aug 24, 2017
Messages
11
I solved my problem by following the entire first post tutorial, and then it was giving Cannot allocate TUN/TAP dev dynamically error, and then I followed this instructions to fix it:

Now it is working. thanks

now I would like to create another vpn user. how to do it?
 

bryce

Explorer
Joined
Apr 15, 2014
Messages
97
Ok, used your script, worked perfectly. However, I am not able to ping or access the FreeNAS webui once connected to the VPN. Shouldn't I be able to?

EDIT: I just realized something:

push "route 192.168.1.0 255.255.255.0"

Isn't this my gateway? My current router is getting it's IP assigned as 192.168.1.254. So should I be setting the route to that instead?

push "route 192.168.1.254 255.255.255.255

Or am I not reading this correctly?

I've been at this for hours, will try again in the morning.
 
Last edited:

napalmd

Dabbler
Joined
Aug 24, 2017
Messages
11
Ok, used your script, worked perfectly. However, I am not able to ping or access the FreeNAS webui once connected to the VPN. Shouldn't I be able to?

EDIT: I just realized something:

push "route 192.168.1.0 255.255.255.0"

Isn't this my gateway? My current router is getting it's IP assigned as 192.168.1.254. So should I be setting the route to that instead?

push "route 192.168.1.254 255.255.255.255

Or am I not reading this correctly?

I've been at this for hours, will try again in the morning.

If your router where freenas is installed is 192.168.1.254, then push "route 192.168.1.0 255.255.255.0" is correct.
must be something else... maybe the remote machine local network has the same subnet? even if it does I tested myself that and I could connect to freenas webgui...
 

bryce

Explorer
Joined
Apr 15, 2014
Messages
97
That's what I thought napalmd.

I saw this a few pages back in this thread.

To allow full NAT and full traffic redirect uncomment

Code:
topology subnet


Code:
push "redirect-gateway def1 bypass-dhcp"


Code:
push "dhcp-option DNS <Your DNS - possibly from local router>"

So, adding "topology subnet" and the above options I still connect, can browse the web, but not access any local resources.

Here are all my config files: https://pastebin.com/ab4sDJpY
 
Last edited:

albertredneck

Dabbler
Joined
Aug 27, 2019
Messages
19
Guys, very late to the party, I'm sorry.

I want remote access to my Freenas and I'm using ssh tunneling at the moment (no password auth, only certificate). I was wondering if I really need VPN to improve securtiy (my ssh port is exposed to the internet).

If so, what should I do? follow this guide? I've just seen a Community Plugin "Open VPN Server". Should I use that instead?
 

toxykdude

Cadet
Joined
May 9, 2020
Messages
1
Hi @Bibi40k, first thanks a lot for your script and guideness

I'm running FreeNAS-11.3-U1 and started the script but it sudenly stops with an error, and it writes nothing to the log.

Don't really know whats wrong with it.

Thanks a lot if you can help

[..] checking config dirs... [success]

[..] make a bkp of 'server.conf' file to conf dir... [success]
[..] make a bkp of 'client.conf' file to conf dir... [success]
[..] make a bkp of 'easy-rsa/vars' file to conf dir... [success]

[..] copy 'ipfw.rules' file to conf dir... [success]
[..] copy 'newsyslog.conf' file to conf dir... [success]
[..] copy 'syslog.conf' file to conf dir... [success]
[..] copy 'rc.conf' file to conf dir... [success]

[..] adjust values in 'rc.conf' file... [success]

[..] copy 'rc.conf|ipfw.rules|syslog.conf|newsyslog.conf' files to jail... [success]

[..] copy 'easy-rsa' dir to conf dir... [success]
[..] copy 'openvpn.conf' file to conf dir... [success]
[..] copy 'vars' file to conf dir... [success]

[..] adjust values in 'openvpn.conf' file... sed: 1: "s|{IP_RANGE}|192.168.10 ...": unescaped newline inside substitute pattern


Something went wrong, exiting.
[info] Display error(s) in a sec.

Log file: /OpenVPN-on-FreeNAS-in-iocage/openvpn-configs/ovpn-install.log
 

Bibi40k

Contributor
Joined
Jan 26, 2018
Messages
136
Hi, i already answered. Looks like you wrote a wrong formated IP. Please post your 'openvpn.conf' content
 
Top