Linux – OpenVPN split tunel

linuxopenvpnrouting

I've been trying to set up vpn just for one specific ip address. What I want is to have so all traffic that is sent to single ip ( 1.2.3.4 for now ) would go through openvpn client.

My current network setup is as follows:

  1. My computer ( connected to 192.168.1.1 )
  2. My server Server has 2 network devices:
    2.1. eth0 – connection to internet
    2.2. eth1 – lan connection: 192.168.1.1

OpenVPN client configuration:

setenv FORWARD_COMPATIBLE 1
client
server-poll-timeout 4
nobind
remote uk-ln-001.privatetunnel.com 1194 udp
remote uk-ln-001.privatetunnel.com 1194 udp
remote uk-ln-001.privatetunnel.com 443 tcp
remote uk-ln-001.privatetunnel.com 1194 udp
remote uk-ln-001.privatetunnel.com 1194 udp
remote uk-ln-001.privatetunnel.com 1194 udp
remote uk-ln-001.privatetunnel.com 1194 udp
remote uk-ln-001.privatetunnel.com 1194 udp
dev tun
dev-type tun
ns-cert-type server
reneg-sec 604800
sndbuf 100000
rcvbuf 100000
comp-lzo no
verb 3
setenv PUSH_PEER_INFO

<ca>**********</ca>
<cert>**********</cert>
<key>**********</key>

key-direction 1
<tls-auth>***********</tls-auth>

OpenVPN client startup:

Wed Dec  4 15:39:24 2013 OpenVPN 2.3.2 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [eurephia] [MH] [IPv6] built on Nov 28 2013
Wed Dec  4 15:39:24 2013 Control Channel Authentication: tls-auth using INLINE static key file
Wed Dec  4 15:39:24 2013 Outgoing Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
Wed Dec  4 15:39:24 2013 Incoming Control Channel Authentication: Using 160 bit message hash 'SHA1' for HMAC authentication
Wed Dec  4 15:39:24 2013 Socket Buffers: R=[8388608->200000] S=[212992->200000]
Wed Dec  4 15:39:24 2013 UDPv4 link local: [undef]
Wed Dec  4 15:39:24 2013 UDPv4 link remote: [AF_INET]5.152.200.199:1194
Wed Dec  4 15:39:24 2013 TLS: Initial packet from [AF_INET]5.152.200.199:1194, sid=13b5c2ca 7e02a311
Wed Dec  4 15:39:24 2013 VERIFY OK: depth=1, CN=OpenVPN CA
Wed Dec  4 15:39:24 2013 VERIFY OK: nsCertType=SERVER
Wed Dec  4 15:39:24 2013 VERIFY OK: depth=0, CN=OpenVPN Server
Wed Dec  4 15:39:24 2013 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
Wed Dec  4 15:39:24 2013 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Wed Dec  4 15:39:24 2013 Data Channel Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
Wed Dec  4 15:39:24 2013 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Wed Dec  4 15:39:24 2013 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 1024 bit RSA
Wed Dec  4 15:39:24 2013 [OpenVPN Server] Peer Connection Initiated with [AF_INET]5.152.200.199:1194
Wed Dec  4 15:39:27 2013 SENT CONTROL [OpenVPN Server]: 'PUSH_REQUEST' (status=1)
Wed Dec  4 15:39:27 2013 PUSH: Received control message: 'PUSH_REPLY,explicit-exit-notify,topology subnet,route-delay 5 30,dhcp-pre-release,dhcp-renew,dhcp-release,route-metric 101,ping 12,ping-restart 50,redirect-gateway def1,redirect-gateway bypass-dhcp,redirect-gateway autolocal,route-gateway 5.5.0.1,dhcp-option DNS 10.9.0.1,dhcp-option DNS 8.8.4.4,register-dns,comp-lzo yes,ifconfig 5.5.158.58 255.255.0.0'
Wed Dec  4 15:39:27 2013 Unrecognized option or missing parameter(s) in [PUSH-OPTIONS]:4: dhcp-pre-release (2.3.2)
Wed Dec  4 15:39:27 2013 Unrecognized option or missing parameter(s) in [PUSH-OPTIONS]:5: dhcp-renew (2.3.2)
Wed Dec  4 15:39:27 2013 Unrecognized option or missing parameter(s) in [PUSH-OPTIONS]:6: dhcp-release (2.3.2)
Wed Dec  4 15:39:27 2013 Unrecognized option or missing parameter(s) in [PUSH-OPTIONS]:16: register-dns (2.3.2)
Wed Dec  4 15:39:27 2013 OPTIONS IMPORT: timers and/or timeouts modified
Wed Dec  4 15:39:27 2013 OPTIONS IMPORT: explicit notify parm(s) modified
Wed Dec  4 15:39:27 2013 OPTIONS IMPORT: LZO parms modified
Wed Dec  4 15:39:27 2013 OPTIONS IMPORT: --ifconfig/up options modified
Wed Dec  4 15:39:27 2013 OPTIONS IMPORT: route options modified
Wed Dec  4 15:39:27 2013 OPTIONS IMPORT: route-related options modified
Wed Dec  4 15:39:27 2013 OPTIONS IMPORT: --ip-win32 and/or --dhcp-option options modified
Wed Dec  4 15:39:27 2013 ROUTE_GATEWAY 78.62.63.254/255.255.192.0 IFACE=eth0 HWADDR=90:2b:34:dc:f3:a8
Wed Dec  4 15:39:27 2013 TUN/TAP device tun0 opened
Wed Dec  4 15:39:27 2013 TUN/TAP TX queue length set to 100
Wed Dec  4 15:39:27 2013 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
Wed Dec  4 15:39:27 2013 /sbin/ip link set dev tun0 up mtu 1500
Wed Dec  4 15:39:27 2013 /sbin/ip addr add dev tun0 5.5.158.58/16 broadcast 5.5.255.255
Wed Dec  4 15:39:32 2013 ROUTE remote_host is NOT LOCAL
Wed Dec  4 15:39:32 2013 /sbin/ip route add 5.152.200.199/32 via 78.62.63.254
Wed Dec  4 15:39:32 2013 /sbin/ip route add 0.0.0.0/1 via 5.5.0.1
Wed Dec  4 15:39:32 2013 /sbin/ip route add 128.0.0.0/1 via 5.5.0.1
Wed Dec  4 15:39:32 2013 /sbin/ip route add 10.10.10.0/24 via 5.5.0.1 metric 101
Wed Dec  4 15:39:32 2013 Initialization Sequence Completed

Problems that I have:
1. If I run openvpn client.ovpn, it routes all traffic through vpn and My computer has no internet connection at all.
2. I was unable to figure out how to route only all traffic that comes from My computer and has destination address 1.2.3.4 trough a vpn connection.

Best Answer

You can start by adding the route-nopull option to your client configuration. By doing no routes will be changed on your client machine.

After that you can add route statements to your OpenVPN config to setup any static routes that are required for specific hosts or networks. You might add something like route 1.2.3.0 255.255.255.0 to your config so that network would be routed to across the vpn.