OpenVPN : routing all traffic through the VPN tunnel

I’m really into OpenVPN these days, see my two previous posts about it :

Setting up OpenVPN for your road warriors :
http://blog.wains.be/index.php/2008/07/15/a-vpn-for-remote-users-with-openvpn/

Setting up a VPN between two sites :
http://blog.wains.be/index.php/2008/06/07/routed-openvpn-between-two-subnets-behind-nat-gateways/

Today : how to route all traffic through the OpenVPN tunnel

On the server side :

First of all, if you want to route all your traffic through the VPN tunnel, you need to turn on IP forwarding (also called routing) and add a masquerading rule on the server (where eth0 is the device connecting you to the internet) :

echo "1" > /proc/sys/net/ipv4/ip_forward

iptables -t nat -A POSTROUTING -s 10.30.0.0/24 -o eth0 -j MASQUERADE

To make routing persistent, see http://blog.wains.be/index.php/2006/06/06/enable-ip-forward-under-rhelcentos/

Then, here’s the OpenVPN configuration :

port 10000
proto udp
dev tun
comp-lzo
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
duplicate-cn
server 10.30.0.0 255.255.255.0
client-to-client
push "dhcp-option DOMAIN local.example.org"
push "dhcp-option DNS 172.16.7.253"
push "redirect-gateway def1"
keepalive 10 120
persist-key
persist-tun
user nobody
group nogroup
log vpn.log
verb 1
chroot /tmp

You can see the option redirect-gateway that is responsible for creating all the routes on the client computer when the connection is set up.

The two other push options are only taken into account by Windows clients (to my knowledge).
If you want to change the DNS resolution of your linux clients, you need to use the up and down options on the client (see below).

Client configuration :

vpn.conf :

client
dev tun
proto udp
remote vpn.example.org
port 10000
nobind
comp-lzo
persist-key
persist-tun
ca ./ca.crt
cert ./user.crt
key ./user.key 
verb 5
up ./up.sh
down ./down.sh
ping 60
ping-restart 120

up.sh :

#!/bin/sh
mv /etc/resolv.conf /etc/resolv.conf.bak
echo "search local.example.org" > /etc/resolv.conf
echo "nameserver 172.16.7.253" >> /etc/resolv.conf

down.sh :

#!/bin/sh
mv /etc/resolv.conf.bak /etc/resolv.conf

When connecting to the server (with verbose option set to 5), we can see the server pushing the route settings to the client.

Fri Jul 18 23:22:19 2008 us=838005 ifconfig tun0 10.30.0.6 pointopoint 10.30.0.5 mtu 1500
Fri Jul 18 23:22:19 2008 us=843211 route add -net 72.x.x.x netmask 255.255.255.255 gw 172.16.7.253
Fri Jul 18 23:22:19 2008 us=845178 route add -net 0.0.0.0 netmask 128.0.0.0 gw 10.30.0.5
Fri Jul 18 23:22:19 2008 us=848568 route add -net 128.0.0.0 netmask 128.0.0.0 gw 10.30.0.5
Fri Jul 18 23:22:19 2008 us=850460 route add -net 10.30.0.0 netmask 255.255.255.0 gw 10.30.0.5

On the client, the routes :

$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
72.x.x.x  172.16.7.253   255.255.255.255 UGH   0      0        0 wlan0
10.30.0.5       0.0.0.0         255.255.255.255 UH    0      0        0 tun0
172.16.7.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0
10.30.0.0       10.30.0.5       255.255.255.0   UG    0      0        0 tun0
0.0.0.0         10.30.0.5       128.0.0.0       UG    0      0        0 tun0
128.0.0.0       10.30.0.5       128.0.0.0       UG    0      0        0 tun0
0.0.0.0         172.16.7.253   0.0.0.0         UG    0      0        0 wlan0

31 thoughts on “OpenVPN : routing all traffic through the VPN tunnel

  1. Hello Sébastien,

    I have this openvpn starting string on the server side:

    openvpn –float –port 1196 –cipher AES-256-CBC –dev tun –dev-node /dev/tun –ifconfig 10.0.0.5 10.0.0.6 –persist-tun –persist-local-ip –persist-remote-ip –comp-lzo –push “dhcp-option DOMAIN xyz.com” –push “dhcp-option DNS 69.64.45.76″ –push “dhcp-option DNS 69.64.44.50″ –push “redirect-gateway def1″ –ping 15 –ping-restart 300 –verb 5 –secret /etc/openvpn/vpn.key –persist-key –chroot /home/nobody –user nobody –group nobody &> /root/vpn.txt&

    And this one on the client side:

    openvpn –float –remote abc.xyz.com –port 1196 –cipher AES-256-CBC –dev tun –dev-node /dev/tun –ifconfig 10.0.0.6 10.0.0.5 –persist-tun –persist-local-ip –persist-remote-ip –comp-lzo –ping 15 –ping-restart 300 –verb 5 –secret /etc/openvpn/vpn.key –persist-key –chroot /home/nobody –user nobody –group nobody &> /root/vpn.txt&

    Starting it up, it works wonderfully well, both machines communicate perfectly, but my client isn’t changing its own routes as you claim. Do you see something wrong I might be doing for it not work?

    Thank you,
    Tiago from Brazil

  2. Hi,

    This has been tested on Debien Etch, openvpn version 2.0.

    Which version of openvpn are you using ?

  3. Hi Sébastien,

    Thx for the HowTo.
    I got it working finally, but I can not use my server as DNS for the VPN.
    with
    push “dhcp-option DNS [external-dns-server-address]”
    it works
    but with
    push “dhcp-option DNS [my-Server-address]”
    it won’t.
    In my LAN I use the Server as DNS and have DNS-forwarding enabled on it.

    Do you have any Idea?

    Taraman

  4. Taraman,

    When you say it’s not working.. I assume your VPN client correctly gets the local DNS in /etc/resolv.conf but the DNS is not resolving ?

    If it is your problem, you just need to allow queries for the VPN range in your DNS.

    Cheers

  5. Hi Sébastien,
    great howto!I would like to ask you something…i configured tun device, and i pushed 2 routes of internal network succesfully, and internal dns.
    When i connect from outside to the server, i get the routing to the internal routes through virtual adapter, while the other destinations routed through my gateway.But i got all dns lookups through virtual adapter.
    Is it possible to split dns resolution?
    Thx!
    Andrea

    • Hi,

      There must be a way but I’m not aware of anything easy to implement.

      Since I assume you are a residential user, the quickest way I can think of is :
      - don’t make the vpn send the DNS information to the client
      - store hostnames of remote machine in your hosts file

  6. Hi,
    Having a heck of a time w/ this – 2 linux boxes doing site2site. Tunnel works great but I can’t get to the Internet from a laptop on the “client” side of the tunnel. I see the DNS query traverse the tunnel but then nothing. Linux boxes are multi-homed – any special procedures in this case?

    Thanks..

  7. Hi Sébastien,

    What if I want to use my another public IP address, like eth0:1 ? I can’t do:
    iptables -t nat -A POSTROUTING -s 10.30.0.0/24 -o eth0:1 -j MASQUERADE
    cause I’m getting error:
    weird character in interface `eth0:1′ (No aliases, :, ! or *)

    any idea what shall i do ?

  8. Are you sure it’s not working ?
    You can get this error message and it could work actually.

  9. Hi please Can you help me, as I’m not sure where the problem is, server or client ?
    I want to route all internet traffic through the openvpn server.
    I can log into the openvpn, and ping from the client

    Server routing
    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    10.8.0.2 * 255.255.255.255 UH 0 0 0 tun0
    ctcash.com.hk * 255.255.255.255 UH 0 0 0 eth0
    173.224.118.75 * 255.255.255.255 UH 0 0 0 eth0
    cphdns.com * 255.255.255.255 UH 0 0 0 eth0
    172.18.254.0 10.8.0.2 255.255.255.252 UG 0 0 0 tun0
    173.224.112.0 * 255.255.255.192 U 0 0 0 eth0
    10.8.0.0 10.8.0.2 255.255.255.0 UG 0 0 0 tun0
    173.224.118.0 * 255.255.255.0 U 0 0 0 eth0
    169.254.0.0 * 255.255.0.0 U 0 0 0 eth0
    default 173.224.112.1 0.0.0.0 UG 0 0 0 eth0

    Client routing

    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    10.8.0.5 * 255.255.255.255 UH 0 0 0 tun0
    173.224.112.50 172.18.254.10 255.255.255.255 UGH 0 0 0 eth1
    10.8.0.0 10.8.0.5 255.255.255.0 UG 0 0 0 tun0
    172.18.254.0 * 255.255.255.0 U 2 0 0 eth1
    loopback * 255.0.0.0 U 0 0 0 lo
    default 10.8.0.5 0.0.0.0 UG 0 0 0 tun0

    Server.conf
    # Which local IP address should OpenVPN
    # listen on? (optional)
    local 173.224.112.50

    # 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/easy-rsa/2.0/keys/ca.crt
    cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
    key /etc/openvpn/easy-rsa/2.0/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/easy-rsa/2.0/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.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 172.18.254.10 255.255.255.0″
    ;push “route 192.168.20.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 172.18.254.10 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 172.18.254.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 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 FilesOpenVPNlog” 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

  10. If you use the config in the post, it should work flawlessly.
    I’m not sure about some configuration you’ve used.. (bypass-dhcp in push redirect ?)

  11. Hello,

    Thanks for posting this, but i get problem with testing this.
    How do you keep the openvpn connection alive when you try to route all traffic throu it?
    dont you need to exclude the ip address of the openvpn server from that route?

    When the connection is established and routing setup i get “write UDPv4: No route to host (code=65)”.

  12. @ R :
    please post your routes and what you get in the openvpn logs..
    i’ve been using this particular configuration for the past 2 years now, and it works like a charm.

    Thanks

  13. Hello, Thanks for the quick replay.
    I am posting the end parts of the logfiles.
    To me it seems like i am missing a route to exclude the openvpn-server from the default route.

    Ok logfile from client side:

    Wed Aug 11 19:22:22 2010 /sbin/ifconfig tun0 10.0.13.6 10.0.13.5 mtu 1500 netmask 255.255.255.255 up
    Wed Aug 11 19:22:22 2010 /sbin/route add -net 67.202.109.113 0.0.0.0 255.255.255.255
    add net 67.202.109.113: gateway 0.0.0.0
    Wed Aug 11 19:22:22 2010 /sbin/route add -net 0.0.0.0 10.0.13.5 128.0.0.0
    add net 0.0.0.0: gateway 10.0.13.5
    Wed Aug 11 19:22:22 2010 /sbin/route add -net 128.0.0.0 10.0.13.5 128.0.0.0
    add net 128.0.0.0: gateway 10.0.13.5
    Wed Aug 11 19:22:22 2010 /sbin/route add -net 10.0.13.0 10.0.13.5 255.255.255.0
    add net 10.0.13.0: gateway 10.0.13.5
    Wed Aug 11 19:22:22 2010 Initialization Sequence Completed
    Wed Aug 11 19:22:22 2010 write UDPv4: No route to host (code=65)
    Wed Aug 11 19:22:23 2010 write UDPv4: No route to host (code=65)
    …. (keeps repeating the same line)

    Server openvpn logfile:

    Wed Aug 11 17:24:45 2010 MULTI: Learn: 10.0.13.6 -> clinet1/87.234.219.140:53919
    Wed Aug 11 17:24:45 2010 MULTI: primary virtual IP for clinet1/87.234.219.140:53919:
    10.0.13.6
    Wed Aug 11 17:24:47 2010 clinet1/87.234.219.140:53919 PUSH: Received control message:
    ‘PUSH_REQUEST’
    Wed Aug 11 17:24:47 2010 clinet1/87.234.219.140:53919 SENT CONTROL [clinet1]: ‘PUSH_R
    EPLY,redirect-gateway def1,route 10.0.13.0 255.255.255.0,topology net30,ping 10,ping-
    restart 60,ifconfig 10.0.13.6 10.0.13.5′ (status=1)

    routes on client side:

    > netstat -rn
    Routing tables

    Internet:
    Destination Gateway Flags Refs Use Netif Expire
    0/1 10.0.13.5 UGSc 1 0 tun0
    default 192.168.1.1 UGSc 4 11 en1
    10.0.13/24 10.0.13.5 UGSc 0 0 tun0
    10.0.13.5 10.0.13.6 UH 5 0 tun0
    67.202.109.113/32 0.0.0.0 UGSc 1 0 en1

  14. there’s indeed something wrong

    here are my routes when going through openvpn :

    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    83.134.43.129 192.168.154.41 255.255.255.255 UGH 0 0 0 eth0
    10.20.10.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun0
    192.168.154.40 0.0.0.0 255.255.255.248 U 1 0 0 eth0
    10.20.10.0 10.20.10.5 255.255.255.0 UG 0 0 0 tun0
    0.0.0.0 10.20.10.5 128.0.0.0 UG 0 0 0 tun0
    128.0.0.0 10.20.10.5 128.0.0.0 UG 0 0 0 tun0
    0.0.0.0 192.168.154.41 0.0.0.0 UG 0 0 0 eth0

    192.168.154.41 is my LAN gateway
    83.134.43.129 is the OpenVPN server
    10.20.10.5 is the tunnel PtP IP

    This is my route when not using OpenVPN :

    Kernel IP routing table
    Destination Gateway Genmask Flags MSS Window irtt Iface
    192.168.154.40 0.0.0.0 255.255.255.248 U 0 0 0 eth0
    0.0.0.0 192.168.154.41 0.0.0.0 UG 0 0 0 eth0

    So yes, you’re definitely missing some routes needed for this to work.
    What kind of distribution are you using ? Which version of OpenVPN ?

  15. Hi, i am using MacOSX 10.6 and “OpenVPN 2.1.1 i386-apple-darwin10.4.0 [SSL] [LZO2] built on Aug 6 2010″ on the client side and “OpenVPN 2.1_rc11 x86_64-pc-linux-gnu [SSL] [LZO2] [EPOLL] [PKCS11]” on the server side.

    Are you using a Linux distro?

    Cheers
    Robert

  16. I’m using Viscosity under Mac OS X, it comes with OpenVPN 2.1 and works perfectly. On the server side, OpenVPN 2.1 rc11. Viscosity is not free but there’s a trial period, you should probably give it a try..

    Here’s my current server config :

    port 21523
    proto udp
    dev-type tun
    dev vpn-gw-udp
    comp-lzo
    ca ca.crt
    cert server.crt
    key server.key
    dh dh1024.pem
    duplicate-cn
    server 10.20.30.0 255.255.255.0
    client-to-client
    push “dhcp-option DOMAIN intranet.example.com”
    push “dhcp-option DNS 192.168.1.1″
    push “redirect-gateway def1″
    keepalive 10 120
    persist-key
    persist-tun
    user nobody
    group nogroup
    log /var/log/openvpn.log
    verb 3
    chroot /tmp

    My server NAT table :

    # iptables -t nat -L -nv
    Chain PREROUTING (policy ACCEPT 164K packets, 14M bytes)
    pkts bytes target prot opt in out source destination

    Chain POSTROUTING (policy ACCEPT 6084K packets, 415M bytes)
    pkts bytes target prot opt in out source destination
    16 1054 MASQUERADE all — * eth0 10.20.30.0/24 !192.168.1.0/24

    Chain OUTPUT (policy ACCEPT 6084K packets, 415M bytes)
    pkts bytes target prot opt in out source destination

    Client config :

    client
    dev tun
    proto udp
    remote remote.example.com
    port 21523
    comp-lzo
    nobind
    persist-key
    persist-tun
    ca ./conf/ca.crt
    cert ./conf/client.crt
    key ./conf/client.key
    ns-cert-type server
    verb 5
    up ./conf/up.sh
    down ./conf/down.sh
    ping 60
    ping-restart 120
    script-security 3

  17. Seb, all I can say is a big thank you for being so persistent in assisting those of us who weren’t as fortunate as you to get it working with no fuss! :)

    I am using openvpn 2.2 on a linux debian server and openvpn 2.2 on OSX as a client and was trying to first of all use the ‘redirect-gateway def1′ directive and then various other means (manually adding routes especially) to try to get it working. I was getting the ‘no route to host’ error when I used redirect-gateway, and then ‘no space left in buffer’ on the client side at other times, suggesting to me that there was possibly a routing problem (some sort of loop perhaps).

    Not being at all familiar with routing past the basic concepts I found it hard to know which routes to add to make it work.

    However, the posting of your ‘before and after’ routes allowed me to reverse engineer it for my own situation and write a script to add the routes manually. Now it’s working!

    Thanks so much. It had caused me many a long night up trying to work this out.

    No idea why using the openvpn redirect-gateway didn’t work for me, but it definitely didn’t create the necessary routes in my situation.

    • Hi Jason,

      Glad it finally worked out ! Hope this will help others in figuring out their issues.

      Which version of Debian do you use on the server side ? I’m on Debian Lenny (current stable), OpenVPN 2.1~rc11-1. This version pushes the routes fine.

      On the client side, I’ve used various version of OpenVPN 2.1 on Ubuntu 9.x and 10.x, and Viscosity on Mac OS X.

      Viscosity has this version built-in :

      $ ./openvpn –version
      OpenVPN 2.0.9 i386-apple-darwin9.0.0 [SSL] [LZO] built on Oct 29 2007
      Developed by James Yonan
      Copyright (C) 2002-2005 OpenVPN Solutions LLC

      Did the log say anything about route addition while connecting ? Or maybe failure to use the route command for some reason ?

      Anyway, glad you found the issues, seems like it’s always a DNS problem, or more commonly a route problem.

      Cheers

  18. Hi,
    I have a tp-wr1043nd with dd-wrt and a openvpn conected with a vpn server, my firewall rule is:
    iptables -A POSTROUTING -t nat -o tun0 -j MASQUERADE
    at momento every ip is behind the vpn.
    How can I set for example from 192.168.1.0/25 with openvpn and 192.168.1.128/25 without ?

    Best regards

  19. Hi
    Thanks for the interest, now I’ m at work so I have a little problem to give you other information.
    wich kind of information do you need ifconfig, route -n, or….?
    I will as soon as possible.

    Best regards

  20. Dear Wains

    i have the following scenario,
    openvpn server: eth0: 91.142.60.180 (internet), eth1: 192.168.70.70 /24 (private), VPN subnet: 10.30.31.0/24
    i created an openvpn server so i can access all my devices on the private LAN from anywhere on the internet.
    the VPN connection is working well, however i am not able to access any device on the private subnet unless i add
    a route in the device as following:
    ip route 10.30.31.0 255.555.255.0 192.168.70.70
    question 1: what is the rule i should put in iptables in order to NAT the VPN subnet to 192.168.70.70, like this i avoid each time adding a route to each device i wanna access.
    question2: what is the rule i should put in iptables so i route all my internet traffic via the vpn tunnel and get assigned the source ip: 91.142.60.180 to the outside world ( i already added for this case “redirect-gateway” in the client config file on my PC).
    thx in advance

    • 1) you don’t have to NAT, just use a route statement to your LAN in your client vpn config

      2) iptables -t nat -A POSTROUTING -s 10.30.31.0/24 -o eth0 -j MASQUERADE

  21. Sorry if that’s a wrong place I’m writting under, but after few hours googling couldn’t find better place with lots of info about route traffic for vpn tunnels.

    This is how my network looks like:
    My home router/gateway IP – 192.168.1.1
    My home server IP – 192.168.1.2
    My home laptop IP – 192.168.1.3
    My home public IP – 123.123.123.123

    My work router/gateway IP – 192.168.10.1
    My work laptop IP – 192.168.10.50
    My work public IP – 101.101.101.101

    My home server is a VPN server with IP address 10.0.0.1
    My home laptop is a VPN client with IP address 10.0.0.6
    My work laptop is a VPN client with IP address 10.0.0.10

    I use OpenVPN with client to client option and everything is working fine, all clients are connected to my home public IP address.

    Here is my question:
    Is there any way that I could route all traffic from my home laptop through my work laptop ? To be visible in the world as IP 101.101.101.101 instead of 123.123.123.123 ?

    PS. Please don’t tell that it’s not possible because there’s no way I can have IP address 123.123.123.123 ;)

  22. How about this, can you figure out the server config for this client config?
    Please…
    client
    dev tun
    route-method exe
    route-delay 2
    redirect-gateway
    pull
    persist-key
    lport %local2%
    mssfix 1400
    verb 1
    auth-user-pass
    reneg-sec 0
    inactive 1200 50000
    remote random
    remote %rmte1%
    remote %rmte2%
    hand-window 120
    persist-local-ip
    persist-remote-ip
    auth-retry nointeract
    float
    mute-replay-warnings
    script-security 2 system
    tls-client
    dhcp-option DISABLE-NBT

    —–BEGIN CERTIFICATE—–
    blah blah
    —–END CERTIFICATE—–

Comments are closed.