Thursday, February 21, 2013

OpenVPN Configuration for VPC on Ubuntu 12.04

One of my more popular posts so far has been OpenVPN with Amazon VPC. I'm guessing that the lack of a step by step process or, at the very least, the configuration files, has left you annoyed. In this post, I'll give step by step instructions and configuration files to you, so that you can have all the goodness that is a private VPN on VPC.

While the servers that I ran this on are Ubuntu 12.04, it wouldn't surprise me if the configuration and setup worked on various versions of Ubuntu, Debian, Fedora, CentOS, and more.

OpenVPN Installation

The first thing we're going to do is install OpenVPN on all of the servers. If you followed my VPC Setup, this means all four NAT instances, as well as the offsite (office) router, will get the following command.

sudo apt-get install openvpn

This command will install everything you need for the client and server. It will also install the certificate management tools you will need.

Certificate Management

While I don't want to recreate the OpenVPN easy-rsa docs, they are fully complete, and offer little in the way of step by step instructions. I would recommend that, if anything I say is unclear, you go straight to the docs and forget what I said.

The first thing we're going to do is copy the easy-rsa tools to a separate directory. You will want to keep backups of the CA (Certificate Authority) files, private keys, and public keys that will be created in the following commands.

mkdir myopenvpn
cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0/* myopenvpn/
cd myopenvpn/

Now that we have a separate directory to work in, let's create some certificates.

source vars
./build-ca

for host in us-east-1a us-east-1c us-east-1d us-east-1e; do
mkdir $host

./build-dh
mv keys/dh1024.pem $host/

./build-key-server $host
cp keys/$host.crt $host/server.crt
cp keys/$host.csr $host/server.csr
cp keys/$host.key $host/server.key
cp keys/ca.crt $host/ca.crt
done

mkdir office
./build-key office
cp keys/office.crt office/client.crt
cp keys/office.csr office/client.csr
cp keys/office.key office/client.key
cp keys/ca.crt office/ca.crt

At this point, you have 4 directories corresponding to us-east availability zones, and 1 directory for your office. The entire contents of these folders should be distributed to the matching servers.

Once the files are on the NAT instances, run these commands.

sudo chown root:root server.crt server.csr server.key dh1024.pem ca.crt
sudo chmod 600 server.key dh1024.pem
sudo mkdir /etc/openvpn/server
sudo mv server.crt server.csr server.key dh1024.pem ca.crt /etc/openvpn/server

Once the files are on the office router, run these commands.

sudo chown root:root client.crt client.csr client.key ca.crt
sudo chmod 600 client.key
sudo mkdir /etc/openvpn/vpc
sudo mv client.crt client.csr client.key ca.crt /etc/openvpn/vpc

All the certificates are in place now. This is a good time to backup your myopenvpn/keys directory. I would recommend S3, as it's fairly reliable.

OpenVPN Configuration

There will be one configuration file per NAT server in VPC, and there will be 4 configuration files on the office router. All of the NAT configurations will be very similar. Likewise, all of the office configurations will be very similar. I will post the generic files, and then specify changes for each different version of the file.

These configuration files are built for a VPC on 10.0.0.0/16 and an office on 10.1.0.0/16. If yours are different, find and replace the IP address that doesn't match.
Server Configuration

In /etc/openvpn/server.conf:

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

# 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 /etc/openvpn/server/dh1024.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.215.1.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 /etc/openvpn/server/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.10.0 255.255.255.0"
;push "route 192.168.20.0 255.255.255.0"
push "route 10.0.64.0 255.255.192.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.
client-config-dir /etc/openvpn/server/ccd
route 10.1.0.0 255.255.0.0

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

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

# 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 /etc/openvpn/server/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 3

# Silence repeating messages.  At most 20
# sequential messages of the same message
# category will be output to the log.
;mute 20

In /etc/openvpn/server/ccd/office

iroute 10.1.0.0 255.255.0.0

Now, the changes. None of these changes affect /etc/openvpn/server/ccd/office. They only affect /etc/openvpn/server.conf.

us-east-1a

No changes.

us-east-1c

server 10.2.1.0 255.255.255.0 push "route 10.0.64.0 255.255.192.0"

us-east-1d

server 10.2.2.0 255.255.255.0 push "route 10.0.128.0 255.255.192.0"

us-east-1e

server 10.2.3.0 255.255.255.0 push "route 10.0.192.0 255.255.192.0"

Client Configuration

As a template file:

##############################################
# 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 my-server-1 1194
remote useast1a-nat1.lucidchart.com 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

# 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

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

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

# 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 /etc/openvpn/vpc/ca.crt
cert /etc/openvpn/vpc/client.crt
key /etc/openvpn/vpc/client.key

# Verify server certificate by checking
# that the certicate has the nsCertType
# field set to "server".  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 nsCertType
# field set to "server".  The build-key-server
# script in the easy-rsa folder will do this.
ns-cert-type 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.
;cipher x

# 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

/etc/openvpn/us-east-1a.conf

remote us-east-1a-nat.example.com 1194

/etc/openvpn/us-east-1c.conf

remote us-east-1c-nat.example.com 1194

/etc/openvpn/us-east-1d.conf

remote us-east-1d-nat.example.com 1194

/etc/openvpn/us-east-1e.conf

remote us-east-1e-nat.example.com 1194

Firewall

By default, AWS instances allow all traffic through iptables, the Linux firewall. This means that you should only need to worry about the AWS security groups.

OpenVPN, at least in the configuration above, uses UDP port 1194. That's it. Just open that up to your office's public IP address, and you're set.

Running

To run the service, run this command on the NAT instances and the office router.
sudo /etc/init.d/openvpn restart

Conclusion

At this point, you should be able to communicate across all availability zones from your office subnet. If you have an issue with any of them, you can manually run the openvpn service for a particular configuration file.

sudo /etc/init.d/openvpn stop
sudo openvpn --config /etc/openvpn/<file>.conf

The service will run in the foreground, allowing you to see all the output and debug messages.

19 comments:

  1. Hi there,

    this is a great tutorial.

    Following it, I can connect to the VPN from a client.

    But when I start the openvpn, the private instances inside my VPC can't connect to the internet anymore.

    Did you have to edit the iptables to make this work?

    ReplyDelete
  2. Thanks!

    No, I didn't have to make any special edits to iptables to make OpenVPN work on the NAT instances. Here is a copy of the rules on one of those servers.

    matthew@bear:~$ sudo iptables -S -t filter
    -P INPUT ACCEPT
    -P FORWARD ACCEPT
    -P OUTPUT ACCEPT
    -A INPUT -j ACCEPT
    -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
    -A FORWARD -s 10.0.0.0/8 -j ACCEPT
    -A FORWARD -j DROP
    -A OUTPUT -j ACCEPT
    matthew@bear:~$ sudo iptables -S -t nat
    -P PREROUTING ACCEPT
    -P INPUT ACCEPT
    -P OUTPUT ACCEPT
    -P POSTROUTING ACCEPT
    -A POSTROUTING -o eth0 -j MASQUERADE


    To narrow this down, ask yourself these questions.

    1. Can the private instances connect to the internet before you start the OpenVPN server on the NAT instance? If not, it's clearly not OpenVPN.
    2. Can the private instances connect to the internet after you start the OpenVPN server, but before you connect your client? If not, it's the server's configuration. My guess would be a colliding set of IP addresses.
    3. Can the NAT instance connect to the internet after the server is started and after the client is connected? If it can connect, then it's either the routing rules on your subnet, or the server configuration. If it cannot connect, it's the server/client configuration.

    Create a gist of your configuration, and I'll take a look.

    ReplyDelete
  3. So I made some progress.

    My issue was the "route ..." line in the server.conf (look for MATTHEW in the gist)

    https://gist.github.com/AymericG/5410475

    Now, I can connect to the VPN from my laptop and I can ping any instance from it.

    But I cannot access any port even though I have opened all the ports in the security groups. nmap tells me all the ports are "filtered".

    I suspect I might need to tell the AWS gateways to redirect some of the traffic to the server (NAT+OpenServer) but I am not sure. Did you have to change the route tables in the AWS UI?

    Thanks for your help.

    ReplyDelete
    Replies
    1. In your gist, there are a couple of weird things.

      1. You are pushing 2 routes to the client (lines 34,35). The only routes you push to the VPN client are the routes that should go over the VPN. For me, that was 10.0.64.0 255.255.192.0 (the VPC subnet).

      2. The route that you commented out should not be commented out. It should be the subnet of the connected client. For me, that was 10.1.0.0 255.255.0.0 (the Office subnet).

      3. You didn't post the file in /etc/openvpn/server/ccd. The filename should match the office client. The contents should be 'iroute '.

      Delete
  4. Hi there,
    Great tutorial.

    I was able to establish the VPN tunnel, however, I ran into a very strange issue.

    I hope with you experience, you can help me figure things out.
    At my VPN client (my office network), I seem to have problems routing from the tunnel to the vpn-client's private network.

    EC2 Instance (VPN Server)
    172.16.100/24 - AWS private network

    [root@vpn-server ec2-user]# ifconfig | grep addr
    eth0 Link encap:Ethernet HWaddr 02:EF:6D:A2:1A:E2
    inet addr:172.16.100.36 Bcast:172.16.100.255 Mask:255.255.255.0
    inet6 addr: fe80::ef:6dff:fea2:1ae2/64 Scope:Link
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
    inet addr:10.12.14.1 P-t-P:10.12.14.2 Mask:255.255.255.255

    VPN Client
    192.168.0/24 - Office Private Network

    [root@vpn-client openvpn]# ifconfig | grep addr
    eth0 Link encap:Ethernet HWaddr 00:24:1D:C5:00:5A
    inet addr:192.168.0.6 Bcast:192.168.0.255 Mask:255.255.255.0
    inet6 addr: fe80::224:1dff:fec5:5a/64 Scope:Link
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
    inet addr:10.12.14.6 P-t-P:10.12.14.5 Mask:255.255.255.255

    Connectivity Test
    [root@vpn-client openvpn]# ping 172.16.100.36
    PING 172.16.100.36 (172.16.100.36) 56(84) bytes of data.
    64 bytes from 172.16.100.36: icmp_seq=1 ttl=64 time=4.42 ms
    64 bytes from 172.16.100.36: icmp_seq=2 ttl=64 time=4.94 ms
    64 bytes from 172.16.100.36: icmp_seq=3 ttl=64 time=4.44 ms

    [root@vpn-server ec2-user]# ping 192.168.0.6
    PING 192.168.0.6 (192.168.0.6) 56(84) bytes of data.

    Route
    [root@openvpn-client openvpn]# route
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    10.12.14.5 * 255.255.255.255 UH 0 0 0 tun0
    10.12.14.1 10.12.14.5 255.255.255.255 UGH 0 0 0 tun0
    172.16.100.0 10.12.14.5 255.255.255.0 UG 0 0 0 tun0
    192.168.0.0 * 255.255.255.0 U 0 0 0 eth0
    link-local * 255.255.0.0 U 1002 0 0 eth0
    default gateway.mobilea 0.0.0.0 UG 0 0 0 eth0

    [root@openvpn-server ec2-user]# route
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    default ip-172-16-100-1 0.0.0.0 UG 0 0 0 eth0
    10.12.14.0 ip-10-12-14-2.a 255.255.255.0 UG 0 0 0 tun0
    ip-10-12-14-2.a * 255.255.255.255 UH 0 0 0 tun0
    instance-data.a * 255.255.255.255 UH 0 0 0 eth0
    172.16.100.0 * 255.255.255.0 U 0 0 0 eth0
    192.168.0.0 ip-10-12-14-2.a 255.255.255.0 UG 0 0 0 tun0

    [root@openvpn-server openvpn]# sysctl -a | grep ip_forward
    net.ipv4.ip_forward = 1

    [root@openvpn-client openvpn]# sysctl -a | grep ip_forward
    net.ipv4.ip_forward = 1

    It's strange that I can ping from the VPN client to the VPN server's private network, but, I could not ping from the VPN server to the VPN client's private network.
    I've ensured that iptables for both filter and NAT table are without rules. Any thoughts on this?
    Thanks in advance!

    ReplyDelete
    Replies
    1. Make sure your configuration is similar around `client-config-dir`

      Delete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Hi Matthew
    good tutorial

    In the company, we have two networks 1) 192.168.0.0/24 and 2) 192.168.1.1/24, and I can see network 2) from network 1).

    My linux server openvpn, are at network 192.168.1.0/24 with Ip address 192.168.0.30 and DHCP between 192.168.1.32 - 50.

    When I connected it, I can see all computer in netwotk 1) but I can not see network 2)..

    Please, could yo help me...

    Thanks a lot

    ReplyDelete
  7. Try putting this in your server configuration:

    push "route 192.168.0.0 255.255.255.0"
    push "route 192.168.1.0 255.255.255.0"

    Without seeing your configuration, I assume that it's the routing tables on the VPN client. These tables are managed by the "push route" commands.

    ReplyDelete
  8. thank you very much for answering,,
    I did that but does not work..
    I leave my settings

    my interfaces:::::::
    auto lo
    iface lo inet loopback

    auto eth0
    iface eth0 int static
    address 192.168.1.11
    netmask 255.255.255.0
    gateway 192.168.1.1

    auto eth1
    iface eth1 inet manual
    auto br0
    iface br0 int static
    address 192.168.1.12
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    bridges-port eth1
    bridge-prio 1000

    my server.conf ::::::

    mode server
    tls-server
    port 1194
    proto udp
    dev tap0
    up "/etc/openvpn/up.sh br0 tap0 1500"
    down /etc/openvpn/down.sh br0 tap0"

    ca.crt
    cert server.crt
    key server.key
    dh dh1024.pem
    server-bridge 192.168.1.12 255.255.255.0 192.168.1.30 192.168.1.60
    push "router 192.168.0.0 255.255.255.0"
    push "route 192.168.1.0 255.255.255.0"
    push "dhcp-option dns 192.168.1.4"
    push "dhcp-option 8.8.8.8"
    client-to-client
    keepalive 10 120
    tls-auth ta.key
    comp-lzo
    user nobody
    group group
    max-client 30
    persist-ky
    persist-tun
    status openvpn-status.log
    verb 3

    my Client:::::::::::

    Client
    dev tap0
    proto udp
    remote 39.70.63.23 1194
    resolv-retry infinitive
    nobind
    persist-key
    persist-tun
    ca.crt
    cert client1.crt
    key client1.key
    ns-cert-type server
    tls-auth ta.key 1
    cipher BF-CBC
    comp-lzo
    verb 3

    how I make for server bring the clients to the network that can not see.

    thanks again for your help

    ReplyDelete
    Replies
    1. Looks like you've done a number of things that I'm not at all familiar with. Namely:

      1. tap interfaces ("dev tap0")
      2. ethernet bridging ("server-bridge")
      3. router options ("push router...")

      While the settings that I included in my post are working, I can't guarantee that modifications to them will work.

      I'm sorry that I wasn't more helpful.

      Delete
  9. Thanks matthew, I found the problem,

    in my network interfaces, I had

    network 192.168.1.0 255.255.255.0

    I put 192.168.0.0 255.255.0.0

    and Work!!!

    bye

    ReplyDelete
  10. Matthew,
    Great article. I am a bit wet behind the ears in terms of my VPN knowledge. Say I wanted to host a VPN server on an aws instance. Could I created another instance that would be able to hit the VPN instance and connect to an outside user on another network? Is there another/better way of architecting this idea?

    ReplyDelete
    Replies
    1. Just to clarify:

      server A is the VPN server
      server B is connected to A
      server C is connected to A
      Can server B talk to server C?

      If that's your question, then yes. In fact, consider the same scenario plus the following:

      server D is connected to A
      server D is the router for servers E, F, G
      can server B connect to server E,F,G?

      The answer is still yes.

      both of these options deal with the client-config-dir, route, and iroute directives found in my post.

      No, I don't think there's a better way to do this.

      If I misunderstood your question, my bad. Feel free to rephrase and try again.

      Delete
  11. One important detail that is not mentioned here: "Source/dest check" must be disabled on the OpenVPN instance.

    I was banging my head against a brick wall for hours...

    ReplyDelete
    Replies
    1. that sucks, and is definitely true. I didn't mention it in this post because my VPN servers are my NAT servers in AWS. Part of setting up the NAT server is turning off the "Source/Dest Check". My bad.

      Delete
  12. Hi Matthew, thanks for the informative posts. I've got everything working except on small think. When a SIP call is being setup, RTP seems to go into a black hole when attempts to route it back through the VPN. Any ideas? I can provide dump.pcap as well as openvpn confs.

    ReplyDelete
    Replies
    1. I've got no experience with SIP or RTP. Sorry.

      When I ran into those kinds of issues during setup (keeping in mind this was 3.5 years ago), I seem to remember it was always the routing of the packets on the NAT'd server that gave me the issues. Hope that helps, but it probably won't.

      Delete
    2. No worries, I think I've discovered the issue. If running OpenVPN in a NAT scenario e.g. (pbx on 10.0.0.0) (openvpn eth0:10.0.0.xx, tun0:172.16.0.xx) (priv network 192.168.88.0 vpn_out:172.16.0.xx) OpenVPN and/or linux routing needs possibly modify headers. The only way I've gotten it to work is with Cisco IP phones which themselves let you fine tune the NAT Support Parameters e.g. handle VIA received and handle VIA rport. Just wish I could find a bit of info on this topic regarding linux routing and OpenVPN :-) The NAT ..ing kills it most polys and yealinks. A smart SIP OpenVPN would be very cool!

      Delete