# GAH!  OpenVPN Won't Route!!!  [SOLVED!!!]

## wswartzendruber

Okay, I'm about two f***ing seconds away from tearing all the hair out of my head!!!

SCENARIO:  I got a virtual private server with VPSlink, got them to enable TUN/TAP, and setup an OpenVPN server.  Great!  When I connect, the server can ping the client and the client can ping the server.  I'm using 10.8.0.0/24 for my VPN configuration.  Now, I CANNOT connect to a DAMN thing outside the 10.8.0.0 subnet.  I want to use this VPN server as a virtual gateway to the internet.  So here goes:

Server config file:

```
#################################################

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

# TCP or UDP server?

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 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 /etc/openvpn/keys/ca.crt

cert /etc/openvpn/keys/server.crt

key /etc/openvpn/keys/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/keys/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.8.0.1 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

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

# 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

# Select a cryptographic cipher.

# This config item must be copied to

# the client config file as well.

cipher AES-256-CBC   # AES

# Enable compression on the VPN link.

# If you enable it here, you must also

# enable it in the client config file.

comp-lzo

# 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 3
```

I've tried all sorts of route pushing, but can't get anything to work.  I told the kernel to enable IPv4 forwarding and that's good to go.  I'm not even running a firewall!  What the F@#$#%@#@$!!!

----------

## kashani

Two questions. 

1. Have you enabled TCP forwarding in the kernel and at run time? You can verify by doing running cat /proc/sys/net/ipv4/ip_forward and making sure it returns 1.

2. Are you using NAT to hide the 10/8 network from the rest of world? Your network provider won't allow 10/8 networks into their network or past it so it might be that the packets are dying because you're not NAT-ing them to a public IP.

kashani

----------

## wswartzendruber

 *kashani wrote:*   

> Two questions. 
> 
> 1. Have you enabled TCP forwarding in the kernel and at run time? You can verify by doing running cat /proc/sys/net/ipv4/ip_forward and making sure it returns 1.
> 
> 2. Are you using NAT to hide the 10/8 network from the rest of world? Your network provider won't allow 10/8 networks into their network or past it so it might be that the packets are dying because you're not NAT-ing them to a public IP.
> ...

 

Okay, there we go.  I got IPv4 forwarding enabled, but I don't know about using NAT to hide things.  I moved the VPN server subnet to 192.168.100.0/24.  Now, what's all this NAT hiding business?

----------

## kashani

192.168.0.0/16 has exactly the same problem as 10/8 as both are part of RFC 1918 space. 

Say I'm your hosting provider and I'm not a complete imbecile. I set my routers up to route my block of public IP's I've been assigned, in this case 64.1.1.0/20. As a good netizen I'll put filters on my routers that will drop packets from IP's that aren't part of my public IP's internally. Additionally I'll stop RFC 1918 space and unassigned public space from coming into my network. 

On the network provider side to the hosting provider they will additionally allow only my assigned public IP space. Well in theory this is what is done, but real policies tend to be less strict. However they will always filter RFC 1918 space as well. 

Then in the Internet at large, since RFC 1918 space is reserved, there are no routes for it. That means that my network has no idea how to get to 10.x.x.x because there are no routes for it. Well occasionally someone leaks these routes into a routing table and that routing engineer gets made fun of at the next NANOG conference. 

So back to NAT. NAT is generally run on firewalls so that admins can use RFC 1918 internally and then it translated to the public IP of the firewall hence the name Network Address Translation. In your case it's fine to run a private network of 10.x.x.x for you TAP/Tun connection, but once you want to leave the end point you'll need to use iptables to translate the private IP of the client into the public IP of the server. 

kashani

* fixed some typos and grammar

----------

## wswartzendruber

So I do have to use iptables to setup NAT?

----------

## Stever

Yep, NAT is configured in iptables.  There is a section in http://www.gentoo.org/doc/en/home-router-howto.xml that gives the basic idea, or you can use something like shorewall (what I use) to set it up for you as in http://www.shorewall.net/two-interface.htm .

HTH

----------

## wswartzendruber

YES!!!  YES!!!  YES!!!  YES!!!  YES!!!

Now, here's the iptables script I hacked together:

 *Quote:*   

> #!/bin/bash
> 
> IPTABLES='/sbin/iptables'
> 
> # Set interface values
> ...

 

This is a combination of two different scripts.  How can this be improved?  I don't want to allow ANYTHING on venet0 in except for TCP 22 and TCP 443.  Interface tun0 needs to be completely unrestricted.  Can my script be improved?

----------

