From ParabolaWiki
Jump to: navigation, search
OpenVPN in Linux containers

This article describes a basic installation and configuration of OpenVPN, suitable for private and small business use. For more detailed information, please see the OpenVPN 2.3 man page and the OpenVPN documentation. OpenVPN is a robust and highly flexible VPN daemon. It supports SSL/TLS security, Ethernet bridging, TCP or UDP tunnel transport through proxies or NAT. Additionally it has support for dynamic IP addresses and DHCP, scalability to hundreds or thousands of users, and portability to most major OS platforms.

OpenVPN is tightly bound to the OpenSSL library, and derives much of its crypto capabilities from it. It supports conventional encryption using a pre-shared secret key (Static Key mode) or public key security (SSL/TLS mode) using client & server certificates. Additionally it supports unencrypted TCP/UDP tunnels.

OpenVPN is designed to work with the TUN/TAP virtual networking interface that exists on most platforms. Overall, it aims to offer many of the key features of IPSec but with a relatively lightweight footprint. OpenVPN was written by James Yonan and is published under the GNU General Public License (GPL).

1 Install OpenVPN

Install the openvpn package.

Note: The software contained in this package supports both server and client mode, so install it on all machines that need to create VPN connections.

2 Kernel configuration

Note: OpenVPN requires TUN/TAP support, which is already configured in the default kernel. Users of custom kernel should make sure to enable the tun module as below.
Kernel config file
 Device Drivers
  --> Network device support
    [M] Universal TUN/TAP device driver support

Read Kernel modules for more information.

3 Connect to a VPN provided by a third party

To connect to a VPN service provided by a third party, most of the following can most likely be ignored, especially regarding server setup. Begin with #The client config profile and skip ahead to #Starting OpenVPN after that. One should use the provider certificates and instructions, for instance see: Airvpn.

Note: Most gratis VPN providers will (often only) offer PPTP, which is drastically easier to setup and configure, but is not secure.

4 Create a Public Key Infrastructure (PKI) from scratch

When setting up an OpenVPN server, users need to create a Public Key Infrastructure (PKI) which is detailed in the easy-rsa article. Once the needed certificates, private keys, and associated files are created via following the steps in the separate article, one should have 5 files in /etc/openvpn at this point:

  • /etc/openvpn/ca.crt
  • /etc/openvpn/dh.pem
  • /etc/openvpn/servername.crt and /etc/openvpn/servername.key
  • /etc/openvpn/ta.key

5 A basic L3 IP routing configuration

Note: Unless otherwise explicitly stated, the rest of this article assumes this basic configuration.

OpenVPN is an extremely versatile piece of software and many configurations are possible, in fact machines can be both "servers" and "clients", blurring the distinction between server and client.

What really distinguishes a server from a client (apart from the type of certificate used) is the configuration file itself. The OpenVPN daemon start-up script reads all the *.conf configuration files it finds in /etc/openvpn on start-up and acts accordingly. If it finds more than one configuration file, it will start one OpenVPN process per configuration file.

This article explains how to set up a server named elmer and a client that connects to it named bugs. More servers and clients can easily be added by creating more key/certificate pairs and adding more server and client configuration files.

5.1 Example configuration

The OpenVPN package comes with a collection of example configuration files for different purposes. The sample server and client configuration files make an ideal starting point for a basic OpenVPN setup with the following features:

  • Uses Public Key Infrastructure (PKI) for authentication.
  • Creates a VPN using a virtual TUN network interface (OSI L3 IP routing).
  • Listens for client connections on UDP port 1194 (OpenVPN's official IANA port number).
  • Distributes virtual addresses to connecting clients from the subnet.

For more advanced configurations, please see the official OpenVPN 2.3 man page and the OpenVPN documentation.

5.2 The server configuration file

Note: Note that if the server is behind a firewall or a NAT translating router, the OpenVPN port must be forward on to the server.

Copy the example server configuration file to /etc/openvpn/server.conf:

# cp /usr/share/openvpn/examples/server.conf /etc/openvpn/server.conf

Edit the file making a minimum of the following changes:

ca /etc/openvpn/ca.crt
cert /etc/openvpn/servername.crt
key /etc/openvpn/servername.key  # This file should be kept secret
dh /etc/openvpn/dh.pem
tls-auth /etc/openvpn/ta.key 0
user nobody
group nobody

5.2.1 Hardening the server

If security is a priority, additional configuration is recommended including: limiting the server to use a strong cipher/auth method and limiting the newer tls ciphers. Do so by adding the following to /etc/openvpn/server.conf

cipher AES-256-CBC
auth SHA512
tls-version-min 1.2
Note: The .ovpn client profile MUST contain a matching cipher and auth line to work properly (at least with the iOS and Android client)!

5.2.2 Deviating from the standard port and/or protocol

Some public/private network admins may not allow OpenVPN connections on its default port and/or protocol. One strategy to circumvent this is to mimic https/SSL traffic which is very likely unobstructed.

To do so, configure /etc/openvpn/server.conf as such:

port 443
proto tcp
Note: The .ovpn client profile MUST contain a matching port and proto line to work properly! TCP vs UDP

There are subtle differences between TCP and UDP.


  • So-called "stateful protocol."
  • High reliability due to error correction (i.e. waits for packet acknowledgment).
  • Potentially slower than UDP.


  • So-called "stateless protocol."
  • Less reliable than TCP as no error correction is in use.
  • Potentially faster than TCP.

5.3 The client config profile (OpenVPN)

Copy the example client configuration file to /etc/openvpn/client.conf:

# cp /usr/share/openvpn/examples/client.conf /etc/openvpn/client.conf

Edit the following:

  • The remote directive to reflect either the server's Fully Qualified Domain Name, hostname (as known to the client), or its IP address.
  • Uncomment the user and group directives to drop privileges.
  • The ca, cert, and key parameters to reflect the path and names of the keys and certificates.
  • Enable the SSL/TLS HMAC handshake protection. Note the use of the parameter 1 for a client.
remote 1194
user nobody
group nobody
ca /etc/openvpn/ca.crt
cert /etc/openvpn/client.crt
key /etc/openvpn/client.key
tls-auth /etc/openvpn/ta.key 1

5.3.1 Drop root privileges after connecting

Using the options user nobody and group nobody in the configuration file makes OpenVPN drop its privileges after establishing the connection. The downside is that upon VPN disconnect the daemon is unable to delete its set network routes again. If one wants to limit transmitting traffic without the VPN connection, then lingering routes are not desired. Further, it can happen that the OpenVPN server pushes updates to routes at runtime of the tunnel. A client with dropped privileges will be unable to perform the update and exit with an error.

As it could seem to require manual action to manage the routes, the options user nobody and group nobody might seem undesirable. Depending on setup, however, there are four ways to handle these situations:

  • For errors of the unit, a simple way is to edit it and add a Restart=on-failure to the [Service] section. Though, this alone will not delete any obsoleted routes, so it may happen that the restarted tunnel is not routed properly.
  • The package contains the /usr/lib/openvpn/plugins/ (see README in its directory), which can be used to let openvpn fork a process with root privileges with the only task to execute a custom script when receiving a down signal from the main process, which is handling the tunnel with dropped privileges.[1]
  • The OpenVPN HowTo explains another way how to create an unprivileged user mode and wrapper script to have the routes restored automatically.
  • Further, it is possible to let OpenVPN start as a non-privileged user in the first place, without ever running as root, see this OpenVPN wiki HowTo.
Note: The OpenVPN HowTos linked above create a dedicated non-privileged user/group, instead of the already existing nobody. The advantage is that this avoids potential risks when sharing a user among daemons.

5.4 Converting certificates to encrypted .p12 format

Some software will only read VPN certificates that are stored in a password-encrypted .p12 file. These can be generated with the following command:

# openssl pkcs12 -export -inkey keys/bugs.key -in keys/bugs.crt -certfile keys/ca.crt -out keys/bugs.p12

5.5 Testing the OpenVPN configuration

Run # openvpn /etc/openvpn/server.conf on the server, and # openvpn /etc/openvpn/client.conf on the client. Example output should be similar to the following:

# openvpn /etc/openvpn/server.conf
Wed Dec 28 14:41:26 2011 OpenVPN 2.2.1 x86_64-unknown-linux-gnu [SSL] [LZO2] [EPOLL] [eurephia] built on Aug 13 2011
Wed Dec 28 14:41:26 2011 NOTE: OpenVPN 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables
Wed Dec 28 14:41:26 2011 Diffie-Hellman initialized with 2048 bit key
Wed Dec 28 14:41:54 2011 bugs/ MULTI: primary virtual IP for bugs/
Wed Dec 28 14:41:57 2011 bugs/ PUSH: Received control message: 'PUSH_REQUEST'
Wed Dec 28 14:41:57 2011 bugs/ SENT CONTROL [bugs]: 'PUSH_REPLY,route,topology net30,ping 10,ping-restart 120,ifconfig' (status=1)
# openvpn /etc/openvpn/client.conf
Wed Dec 28 14:41:50 2011 OpenVPN 2.2.1 i686-pc-linux-gnu [SSL] [LZO2] [EPOLL] [eurephia] built on Aug 13 2011
Wed Dec 28 14:41:50 2011 NOTE: OpenVPN 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables
Wed Dec 28 14:41:50 2011 LZO compression initialized
Wed Dec 28 14:41:57 2011 GID set to nobody
Wed Dec 28 14:41:57 2011 UID set to nobody
Wed Dec 28 14:41:57 2011 Initialization Sequence Completed

On the server, find the IP address assigned to the tunX device:

# ip addr show
40: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100
    inet peer scope global tun0

Here we see that the server end of the tunnel has been given the IP address

Do the same on the client:

# ip addr show
37: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100
    inet peer scope global tun0

And the client side has been given the IP address

Now try pinging the interfaces.

On the server:

# ping -c3
PING ( 56(84) bytes of data.
64 bytes from icmp_req=1 ttl=64 time=238 ms
64 bytes from icmp_req=2 ttl=64 time=237 ms
64 bytes from icmp_req=3 ttl=64 time=205 ms

--- ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 205.862/227.266/238.788/15.160 ms

On the client:

# ping -c3
PING ( 56(84) bytes of data.
64 bytes from icmp_req=1 ttl=64 time=158 ms
64 bytes from icmp_req=2 ttl=64 time=158 ms
64 bytes from icmp_req=3 ttl=64 time=157 ms

--- ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 157.426/158.278/158.940/0.711 ms
Note: If using a firewall, make sure that IP packets on the TUN device are not blocked.

5.6 Configure the MTU with Fragment and MSS

Note: If you do not configure MTU, then you will notice that small packets like ping and DNS will work, however web browsing will not work.

Now it is time to configure the maximum segment size (MSS). In order to do this we need to discover what is the smallest MTU along the path between the client and server. In order to do this you can ping the server and disable fragmentation. Then specify the max packet size.

The factual accuracy of this article or section is disputed.
Please help improve the article and verify/correct/remove disputed content. (Discuss)
# ping -c5 -M do -s 1500
PING ( 1500(1528) bytes of data.
From ( icmp_seq=1 Frag needed and DF set (mtu = 576)
From ( icmp_seq=1 Frag needed and DF set (mtu = 576)
From ( icmp_seq=1 Frag needed and DF set (mtu = 576)
From ( icmp_seq=1 Frag needed and DF set (mtu = 576)
From ( icmp_seq=1 Frag needed and DF set (mtu = 576)

--- ping statistics ---
0 packets transmitted, 0 received, +5 errors

We received an ICMP message telling us the MTU is 576 bytes. The means we need to fragment the UDP packets smaller then 576 bytes to allow for some UDP overhead.

# ping -c5 -M do -s 548
PING ( 548(576) bytes of data.
556 bytes from icmp_seq=1 ttl=48 time=206 ms
556 bytes from icmp_seq=2 ttl=48 time=224 ms
556 bytes from icmp_seq=3 ttl=48 time=206 ms
556 bytes from icmp_seq=4 ttl=48 time=207 ms
556 bytes from icmp_seq=5 ttl=48 time=208 ms

--- ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4001ms
rtt min/avg/max/mdev = 206.027/210.603/224.158/6.832 ms

After some trial and error..., we discover that we need to fragment packets on 548 bytes. In order to do this we specify this fragment size in the configuration and instruct OpenVPN to fix the Maximum Segment Size (MSS).

remote 1194
fragment 548
mssfix 548

We also need to tell the server about the fragmentation. Note that "mssfix" is NOT needed in the server configuration.

Note: Clients that do not support the 'fragment' directive (e.g. OpenELEC, iOS app) are not able to connect to a server that uses the 'fragment' directive. To support such clients, skip this section and configure the clients with the 'mtu-test' directive described below.
fragment 548
Note: The following will add about 3 minutes to OpenVPN start time. It is advisable to configure the fragment size unless your client is a laptop that will be connecting over many different networks and the bottle neck is on the client side.

You can also allow OpenVPN to do this for you by having OpenVPN do the ping testing every time the client connects to the VPN. Be patient, since your client may not inform you about the test being run and the connection may appear as nonfunctional until finished.

remote 1194
tls-auth /etc/openvpn/ta.key 1

5.7 IPv6

5.7.1 Connect to the server via IPv6

In order to enable Dual Stack for OpenVPN, you have to change proto udp to proto udp6 in both server.conf and client.conf. Afterwards both IPv4 and IPv6 are enabled.

5.7.2 Provide IPv6 inside the tunnel

In order to provide IPv6 inside the tunnel, you need to have a IPv6 prefix routed to your OpenVPN server. Either set up a static route on your gateway (if you have a static block assigned), or use a DHCPv6 client to get a prefix with DHCPv6 Prefix delegation (see IPv6 Prefix delegation for details). You can also use a unique local address from the address block fc00::/7. Both methods have advantages and disadvantages:

  • Many ISPs only provide dynamically changing IPv6 prefixes. OpenVPN does not support prefix changes, so you need to change your server.conf every time the prefix is changed (Maybe can be automated with a script).
  • ULA addresses are not routed to the Internet, and setting up NAT is not as straightforward as with IPv4. So you cannot route the entire traffic over the tunnel. If you only want to connect two sites via IPv6, without the need to connect to the Internet over the tunnel, the ULA addresses may be easier to use.

After you have received a prefix (a /64 is recommended), append the following to the server.conf:

server-ipv6 2001:db8:0:123::/64

This is the IPv6 equivalent to the default network of OpenVPN and needs to be taken from the DHCPv6 client. Or use for example fd00:1234::/64.

If you want to push a route to your home network ( equivalent), also append:

push "route-ipv6 2001:db8:0:abc::/64"

OpenVPN does not yet include DHCPv6, so there is no method to e.g. push DNS server over IPv6. This needs to be done with IPv4. The OpenVPN Wiki provides some other configuration options.

6 Starting OpenVPN

6.1 Manual startup

To troubleshoot a VPN connection, start the client's daemon manually with openvpn /etc/openvpn/client.conf as root. The server can be started the same way using its own configuration file (e.g., openvpn /etc/openvpn/server.conf).

6.2 systemd service configuration

To start OpenVPN automatically at system boot, either for a client or for a server, enable openvpn@<configuration>.service on the applicable machine.

For example, if the client configuration file is /etc/openvpn/client.conf, the service name is openvpn@client.service. Or, if the server configuration file is /etc/openvpn/server.conf, the service name is openvpn@server.service.

6.3 Letting NetworkManager start a connection

On a client you might not always need to run a VPN tunnel and/or only want to establish it for a specific NetworkManager connection. This can be done by adding a script to /etc/NetworkManager/dispatcher.d/. In the following example "Provider" is the name of the NetworkManager connection:


case "$2" in
    if [ "$CONNECTION_ID" == "Provider" ]; then
      systemctl start openvpn@client
    systemctl stop openvpn@client

See NetworkManager#Network services with NetworkManager dispatcher for more details.

6.4 Gnome configuration

If you would like to connect a client to an OpenVPN server through Gnome's built-in network configuration do the following. First, install networkmanager-openvpn. Then go to the Settings menu and choose Network. Click the plus sign to add a new connection and choose VPN. From there you can choose OpenVPN and manually enter the settings. You can also choose to import #The client configuration file, if you have already created one. Yet, be aware NetworkManager does not show error messages for options it does not import. To connect to the VPN simply turn the connection on and check the options are applied as you configured (e.g. via journalctl -b -u NetworkManager).

7 Routing all client traffic through the server

Note: There are potential pitfalls when routing all traffic through a VPN server. Refer to the OpenVPN documentation on this topic for more information.

By default only traffic directly to and from an OpenVPN server passes through the VPN. To have all traffic, including web traffic, pass through the VPN do the following. First add the following to your server's configuration file (i.e., /etc/openvpn/server.conf) [2]:

push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS"

Change to your preferred DNS IP address if configured to run on the same box as the server or else leave it at to use google's DNS.

If you have problems with non responsive DNS after connecting to server, install BIND as simple DNS forwarder and push the IP address of the OpenVPN server as DNS to clients.

After setting up the configuration file, one must enable packet forwarding on the server. Additionally, the server's firewall will need to be set up to allow VPN traffic through it, which is described below for both ufw and iptables.

To allow clients to be able to reach other (private) subnets behind the server, you may want to use the push "route <address pool> <subnet>" option:

push "route"
push "route"

7.1 Firewall configuration

7.1.1 ufw

In order to configure your ufw settings for VPN traffic first add the following to /etc/default/ufw:


Now change /etc/ufw/before.rules, and add the following code after the header and before the "*filter" line. Do not forget to change the IP/subnet mask to match the one in /etc/openvpn/server.conf. The adapter ID in the example is generically called eth0 so edit it for your system accordingly.

# NAT (Network Address Translation) table rules

# Allow traffic from clients to eth0

# do not delete the "COMMIT" line or the NAT table rules above will not be processed

Open OpenVPN port 1194:

# ufw allow 1194

Lastly, reload UFW:

# ufw reload

7.1.2 iptables

In order to allow VPN traffic through your iptables firewall of your server, first create an iptables rule for NAT forwarding [3] on the server, assuming the interface you want to forward to is named eth0:

iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE

If you have difficulty pinging the server through the VPN, you may need to add explicit rules to open up TUN/TAP interfaces to all traffic. If that is the case, do the following [4]:

Warning: There are security implications for the following rules if you do not trust all clients which connect to the server. Refer to the OpenVPN documentation on this topic for more details.
iptables -A INPUT -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A INPUT -i tap+ -j ACCEPT
iptables -A FORWARD -i tap+ -j ACCEPT

Additionally be sure to accept connections from the OpenVPN port (default 1194) and through the physical interface.

When you are satisfied make the changes permanent as shown in iptables#Configuration and usage.

If you have multiple tun or tap interfaces, or more than one VPN configuration, you can "pin" the name of your interface by specifying it in the OpenVPN config file, e.g. tun22 instead of tun. This is advantageous if you have different firewall rules for different interfaces or OpenVPN configurations.

7.2 Prevent leaks if VPN goes down

The idea is simple: prevent all traffic through our default interface (enp3s0 for example) and only allow tun0. If the OpenVPN connection drops, your computer will lose its internet access and therefore, avoid your programs to continue connecting through an insecure network adapter.

Be sure to set up a script to restart OpenVPN if it goes down if you do not want to manually restart it.

7.2.1 ufw

 # Default policies
 ufw default deny incoming
 ufw default deny outgoing
 # Openvpn interface (adjust interface accordingly to your configuration)
 ufw allow in on tun0
 ufw allow out on tun0
 # Local Network (adjust ip accordingly to your configuration)
 ufw allow in on enp3s0 from
 ufw allow out on enp3s0 to
 # Openvpn (adjust port accordingly to your configuration)
 ufw allow out on enp3s0 to any port 1194
 ufw allow in on enp3s0 from any port 1194
Warning: DNS will not work unless you run your own dns server like BIND

Otherwise, you will need to allow dns leak. Be sure to trust your dns server!

 # DNS
 ufw allow in from any to any port 53
 ufw allow out from any to any port 53

8 L3 IPv4 routing

This section describes how to connect client/server LANs to each other using L3 IPv4 routing.

8.1 Prerequisites for routing a LAN

For a host to be able to forward IPv4 packets between the LAN and VPN, it must be able to forward the packets between its NIC and its tun/tap device. See Internet sharing#Enable packet forwarding for configuration details.

8.1.1 Routing tables

The factual accuracy of this article or section is disputed.
Please help improve the article and verify/correct/remove disputed content. (Discuss)

By default, all IP packets on a LAN addressed to a different subnet get sent to the default gateway. If the LAN/VPN gateway is also the default gateway, there is no problem and the packets get properly forwarded. If not, the gateway has no way of knowing where to send the packets. There are a couple of solutions to this problem.

  • Add a static route to the default gateway routing the VPN subnet to the LAN/VPN gateway's IP address.
  • Add a static route on each host on the LAN that needs to send IP packets back to the VPN.
  • Use iptables' NAT feature on the LAN/VPN gateway to masquerade the incoming VPN IP packets.

8.2 Connect the server LAN to a client

The server is on a LAN using the subnet. To inform the client about the available subnet, add a push directive to the server configuration file:
push "route"
Note: To route more LANs from the server to the client, add more push directives to the server configuration file, but keep in mind that the server side LANs will need to know how to route to the client.

8.3 Connect the client LAN to a server


  • Any subnets used on the client side, must be unique and not in use on the server or by any other client. In this example we will use for the clients LAN.
  • Each client's certificate has a unique Common Name, in this case bugs.
  • The server may not use the duplicate-cn directive in its config file.

Create a client configuration directory on the server. It will be searched for a file named the same as the client's common name, and the directives will be applied to the client when it connects.

# mkdir -p /etc/openvpn/ccd

Create a file in the client configuration directory called bugs, containing the iroute directive. It tells the server what subnet should be routed to the client:


Add the client-config-dir and the route directive to the server configuration file. It tells the server what subnet should be routed from the tun device to the server LAN:

client-config-dir ccd
Note: To route more LANs from the client to the server, add more iroute and route directives to the appropriate configuration files, but keep in mind that the client side LANs will need to know how to route to the server.

8.4 Connect both the client and server LANs

Combine the two previous sections:

push "route"
client-config-dir ccd
Note: Remember to make sure that all the LANs or the needed hosts can route to all the destinations.

8.5 Connect clients and client LANs

By default clients will not see each other. To allow IP packets to flow between clients and/or client LANs, add a client-to-client directive to the server configuration file:

In order for another client or client LAN to see a specific client LAN, you will need to add a push directive for each client subnet to the server configuration file (this will make the server announce the available subnet(s) to other clients):

push "route"
push "route"
Note: As always, make sure that the routing is properly configured.


The DNS servers used by the system are defined in /etc/resolv.conf. Traditionally, this file is the responsibility of whichever program deals with connecting the system to the network (e.g. Wicd, NetworkManager, etc.). However, OpenVPN will need to modify this file if you want to be able to resolve names on the remote side. To achieve this in a sensible way, install openresolv, which makes it possible for more than one program to modify resolv.conf without stepping on each-other's toes.

Before continuing, test openresolv by restarting your network connection and ensuring that resolv.conf states that it was generated by resolvconf, and that your DNS resolution still works as before. You should not need to configure openresolv; it should be automatically detected and used by your network system.

For Linux, OpenVPN can send DNS host information, but expects an external process to act on it. This can be done with the client.up and client.down scripts packaged in /usr/share/openvpn/contrib/pull-resolv-conf/. See their comments on how to install them to /etc/openvpn. The following is an excerpt of a resulting client configuration using the scripts in conjunction with resolvconf and options to #Drop root privileges after connecting:

user nobody
group nobody
# Optional, choose a suitable path to chroot into for your system
chroot /srv
script-security 2
up /etc/openvpn/client.up 
plugin /usr/lib/openvpn/plugins/ "/etc/openvpn/client.down tun0"

9.1 Update resolv-conf script

The openvpn-update-resolv-conf script is available as an alternative to packaged scripts. It needs to be saved for example at /etc/openvpn/update-resolv-conf and made executable with chmod.

Once the script is installed add lines like the following into your OpenVPN client configuration file:

script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf

Now, when your launch your OpenVPN connection, you should find that your resolv.conf file is updated accordingly, and also returns to normal when your close the connection.

9.2 Update systemd-resolved script

Since systemd-229, systemd-networkd's systemd-resolved.service has exposed an API through DBus allowing management of DNS configuration on a per-link basis. Tools such as openresolv may not work reliably when /etc/resolv.conf is managed by systemd-resolved, and will not work at all if you are using resolve instead of dns in your /etc/nsswitch.conf file. The update-systemd-resolved script is another alternative and links OpenVPN with systemd-resolved via DBus to update the DNS records.

If you copy the script into /etc/openvpn and mark as executable with chmod, you can add lines like the following into your OpenVPN client configuration file:

script-security 2
setenv PATH /usr/bin
up /etc/openvpn/update-systemd-resolved
down-pre /etc/openvpn/update-systemd-resolved

10 L2 Ethernet bridging

This article or section needs expansion.
Please help expand this article so the intended scope is covered in sufficient detail. (Discuss)

For now see: OpenVPN Bridge

11 Troubleshooting

11.1 Client daemon not restarting after suspend

If you put your client system to sleep, and on resume OpenVPN does not restart, resulting in broken connectivity, create the following file:

if [ "$1" == "pre" ]
  killall openvpn

Make it executable chmod a+x /usr/lib/systemd/system-sleep/


11.2 Connection drops out after some time of inactivity

If the VPN-Connection drops some seconds after it stopped transmitting data and, even though it states it is connected, no data can be transmitted through the tunnel, try adding a keepalivedirective to the server's configuration:

keepalive 10 120

In this case the server will send ping-like messages to all of its clients every 10 seconds, thus keeping the tunnel up. If the server does not receive a response within 120 seconds from a specific client, it will assume this client is down.

A small ping-interval can increase the stability of the tunnel, but will also cause slightly higher traffic. Depending on your connection, also try lower intervals than 10 seconds.

12 See Also

13 Acknowledgement

This wiki article is based on ArchWiki. We may have removed non-FSDG bits from it.