https://wiki.archlinux.org/api.php?action=feedcontributions&user=Mutantoe&feedformat=atomArchWiki - User contributions [en]2024-03-28T13:33:32ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Dynamic_Kernel_Module_Support&diff=568373Dynamic Kernel Module Support2019-03-10T22:07:21Z<p>Mutantoe: /* PKGBUILD */ Replace real domains with example domains</p>
<hr />
<div>[[Category:Kernel]]<br />
[[ja:Dynamic Kernel Module Support]]<br />
[[ru:Dynamic Kernel Module Support]]<br />
[[zh-hans:Dynamic Kernel Module Support]]<br />
From [[wikipedia:Dynamic_Kernel_Module_Support|Wikipedia]]:<br />
<br />
: Dynamic Kernel Module Support (DKMS) is a program/framework that enables generating Linux kernel modules whose sources generally reside outside the kernel source tree. The concept is to have DKMS modules automatically rebuilt when a new kernel is installed. <br />
<br />
This means that a user does not have to wait for a company, project, or package maintainer to release a new version of the module. Since the introduction of [[Pacman#Hooks]], the rebuild of the modules is handled automatically when a kernel is upgraded.<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|dkms}} package and the headers for your kernel (for the default {{Pkg|linux}} kernel this would be {{Pkg|linux-headers}}).<br />
<br />
A good number of modules that lie outside the kernel source tree have a DKMS variant; a few are hosted in the [https://www.archlinux.org/packages/?&q=dkms official repositories], most are found in the [https://aur.archlinux.org/packages/?SeB=n&K=dkms AUR].<br />
<br />
== Upgrades ==<br />
<br />
Though the rebuild of the DKMS modules is usually seamless during a kernel upgrade, it may still happen that the rebuild fails. You should pay extra attention to the [[Pacman]] output. This applies in particular if the system relies on the DKMS module to boot successfully and/or if you use DKMS with a custom kernel not in the [[Official repositories]]. <br />
<br />
To deal with changes in the kernel, fix bugs, or add necessary features consider upgrading the DKMS package before rebooting.<br />
<br />
== Usage ==<br />
<br />
Usage for invoking DKMS manually.<br />
<br />
Tab-completion is available by doing:<br />
<br />
# source /usr/share/bash-completion/completions/dkms<br />
<br />
=== List modules ===<br />
<br />
To list the current status of modules, versions and kernels within the tree:<br />
<br />
# dkms status<br />
<br />
=== Rebuild modules ===<br />
<br />
Rebuild all modules for the currently running kernel:<br />
<br />
# dkms autoinstall<br />
<br />
or for a specific kernel:<br />
<br />
# dkms autoinstall -k 3.16.4-1-ARCH<br />
<br />
To build a ''specific'' module for the currently running kernel:<br />
<br />
# dkms install -m nvidia -v 334.21<br />
<br />
or simply:<br />
<br />
# dkms install nvidia/334.21<br />
<br />
To build a module for ''all'' kernels:<br />
<br />
# dkms install nvidia/334.21 --all<br />
<br />
=== Remove modules ===<br />
<br />
To remove a module (old ones are not automatically removed):<br />
<br />
# dkms remove -m nvidia -v 331.49 --all<br />
<br />
or simply:<br />
<br />
# dkms remove nvidia/331.49 --all<br />
<br />
If the package {{Pkg|dkms}} is removed the information regarding previous module build files is lost. If this is the case, go through {{ic|/usr/lib/modules/KERNELVERSION-ARCH}} and delete all files and directories no longer in use.<br />
<br />
== DKMS package creation ==<br />
<br />
Here are some guidelines to follow when creating a DKMS package.<br />
<br />
=== Package name ===<br />
<br />
DKMS packages are named by appending "''-dkms''" to the original package name.<br />
<br />
The variable {{ic|$_pkgname}} is often used below {{ic|$pkgname}} to describe the package name minus the "''-dkms''" suffix (e.g. {{ic|<nowiki>_pkgname=${pkgname%-*}</nowiki>}}). This is useful to help keep similarities between the original package PKGBUILD and the DKMS variant.<br />
<br />
=== Dependencies ===<br />
<br />
Dependencies should be inherited from the original version with {{Pkg|dkms}} added and {{Pkg|linux-headers}} removed (as it is listed by the dkms package as ''optional'').<br />
<br />
=== Build source location ===<br />
<br />
Build sources should go into (this is the default build directory for DKMS):<br />
<br />
/usr/src/''PACKAGE_NAME''-''PACKAGE_VERSION''<br />
<br />
In the package directory, a DKMS configuration tells DKMS how to build the module ({{ic|dkms.conf}}), including the variables {{ic|PACKAGE_NAME}} and {{ic|PACKAGE_VERSION}}.<br />
<br />
* {{ic|PACKAGE_NAME}} - the actual project name (usually {{ic|$_pkgname}} or {{ic|$_pkgbase}}). <br />
* {{ic|PACKAGE_VERSION}} - by convention this should also be the {{ic|$pkgver}}.<br />
<br />
=== Patching ===<br />
<br />
The sources can be patched either directly in the PKGBUILD or through {{ic|dkms.conf}}.<br />
<br />
=== Module loading automatically in .install ===<br />
<br />
Loading and unloading modules should be left to the user. Consider the possibility a module may crash when loaded.<br />
<br />
Also, please note that you do not have to call {{ic|depmod}} explicitly to update the dependencies of your kernel module. Pacman is now calling DKMS {{ic|dkms install}} and {{ic|dkms remove}} automatically as hooks. {{ic|dkms install}} is making sure {{ic|depmod}} is called at the end of its process. {{ic|dkms install}} depends on {{ic|dkms build}} (to build the source against the current kernel), which itself depends on {{ic|dkms add}} (to add a symlink from {{ic|/var/lib/dkms/<package>/<version>/source}} to {{ic|/usr/src/<package>}}).<br />
<br />
=== namcap output ===<br />
<br />
[[namcap]] (which attempts to check for common mistakes and non-standard decisions in a package) is good practice to use at least once on ''any'' package; however, it has not yet been updated for DKMS specific guidelines.<br />
<br />
For example, DKMS uses {{ic|/usr/src/}} by default, but Namcap believes this to be a non-standard directory, a little contrary to its [[Wikipedia:Filesystem Hierarchy Standard|reference]].<br />
<br />
=== Example ===<br />
<br />
Here is an example package that edits {{ic|dkms.conf}} according to the package name and version.<br />
<br />
==== PKGBUILD ====<br />
<br />
{{hc|PKGBUILD|2=<br />
# Maintainer: foo <foo(at)example(dot)org><br />
# Contributor: bar <bar(at)example(dot)org><br />
<br />
_pkgbase=example<br />
pkgname=example-dkms<br />
pkgver=1<br />
pkgrel=1<br />
pkgdesc="The Example kernel modules (DKMS)"<br />
arch=('i686' 'x86_64')<br />
url="https://www.example.org/"<br />
license=('GPL2')<br />
depends=('dkms')<br />
conflicts=("${_pkgbase}")<br />
install=${pkgname}.install<br />
source=("${url}/files/tarball.tar.gz"<br />
'dkms.conf'<br />
'linux-3.14.patch')<br />
md5sums=(''use <nowiki>'</nowiki>updpkgsums''')<br />
<br />
build() {<br />
cd ${_pkgbase}-${pkgver}<br />
<br />
# Patch<br />
patch -p1 -i "${srcdir}"/linux-3.14.patch<br />
<br />
}<br />
<br />
package() {<br />
# Install<br />
msg2 "Starting make install..."<br />
make DESTDIR="${pkgdir}" install<br />
<br />
# Copy dkms.conf<br />
install -Dm644 dkms.conf "${pkgdir}"/usr/src/${_pkgbase}-${pkgver}/dkms.conf<br />
<br />
# Set name and version<br />
sed -e "s/@_PKGBASE@/${_pkgbase}/" \<br />
-e "s/@PKGVER@/${pkgver}/" \<br />
-i "${pkgdir}"/usr/src/${_pkgbase}-${pkgver}/dkms.conf<br />
<br />
# Copy sources (including Makefile)<br />
cp -r ${_pkgbase}/* "${pkgdir}"/usr/src/${_pkgbase}-${pkgver}/<br />
}<br />
}}<br />
<br />
==== dkms.conf ====<br />
<br />
{{hc|dkms.conf|2=<br />
PACKAGE_NAME="@_PKGBASE@"<br />
PACKAGE_VERSION="@PKGVER@"<br />
MAKE[0]="make --uname_r=$kernelver"<br />
CLEAN="make clean"<br />
BUILT_MODULE_NAME[0]="@_PKGBASE@"<br />
DEST_MODULE_LOCATION[0]="/kernel/drivers/misc"<br />
AUTOINSTALL="yes"<br />
}}<br />
<br />
==== .install ====<br />
<br />
Now pacman has DKMS hooks implemented, you do not have to specify DKMS-specific configuration in your .install file. Calls to {{ic|dkms install}} and {{ic|dkms remove}} will be automatic.<br />
<br />
== See also ==<br />
<br />
* [http://www.linuxjournal.com/article/6896 Linux Journal: Exploring Dynamic Kernel Module Support]</div>Mutantoehttps://wiki.archlinux.org/index.php?title=OpenVPN&diff=507879OpenVPN2018-01-19T21:37:15Z<p>Mutantoe: Fixed Broken Link</p>
<hr />
<div>[[Category:Virtual Private Network]]<br />
[[de:OpenVPN]]<br />
[[ja:OpenVPN]]<br />
[[ru:OpenVPN]]<br />
[[zh-hans:OpenVPN]]<br />
{{Related articles start}}<br />
{{Related|OpenVPN (client) in Linux containers}}<br />
{{Related|OpenVPN (server) in Linux containers}}<br />
{{Related|Easy-RSA}}<br />
{{Related articles end}}<br />
<br />
This article describes a basic installation and configuration of [http://openvpn.net OpenVPN], suitable for private and small business use. For more detailed information, please see the [https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage OpenVPN 2.4 man page] and the [http://openvpn.net/index.php/open-source/documentation OpenVPN documentation]. OpenVPN is a robust and highly flexible [[Wikipedia:VPN|VPN]] daemon. It supports [[Wikipedia:SSL/TLS|SSL/TLS]] security, [[Wikipedia:Bridging_(networking)|Ethernet bridging]], [[Wikipedia:Transmission_Control_Protocol|TCP]] or [[Wikipedia:User_Datagram_Protocol|UDP]] [[Wikipedia:Tunneling_protocol|tunnel transport]] through [[Wikipedia:Proxy_server|proxies]] or [[Wikipedia:Network address translation|NAT]]. Additionally it has support for dynamic IP addresses and [[Wikipedia:Dynamic_Host_Configuration_Protocol|DHCP]], scalability to hundreds or thousands of users, and portability to most major OS platforms.<br />
<br />
OpenVPN is tightly bound to the [http://www.openssl.org OpenSSL] library, and derives much of its crypto capabilities from it. It supports conventional encryption using a [[Wikipedia:Pre-shared_key|pre-shared secret key]] (Static Key mode) or [[Wikipedia:Public_key|public key security]] ([[Wikipedia:SSL/TLS|SSL/TLS]] mode) using client & server certificates. Additionally it supports unencrypted TCP/UDP tunnels.<br />
<br />
OpenVPN is designed to work with the [[Wikipedia:TUN/TAP|TUN/TAP]] virtual networking interface that exists on most platforms. Overall, it aims to offer many of the key features of [[Wikipedia:Ipsec|IPSec]] but with a relatively lightweight footprint. OpenVPN was written by James Yonan and is published under the [[Wikipedia:GNU General Public License|GNU General Public License (GPL)]].<br />
<br />
== Install OpenVPN ==<br />
<br />
[[Install]] the {{Pkg|openvpn}} package, which provides both server and client mode.<br />
<br />
== Kernel configuration ==<br />
<br />
OpenVPN requires TUN/TAP support, which is already configured in the default kernel. Users of custom kernel should make sure to enable the {{ic|tun}} module:<br />
<br />
{{hc|Kernel config file|<br />
Device Drivers<br />
--> Network device support<br />
[M] Universal TUN/TAP device driver support<br />
}}<br />
<br />
Read [[Kernel modules]] for more information.<br />
<br />
== Connect to a VPN provided by a third party ==<br />
<br />
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, see [[:Category:VPN providers]] for examples that can be adapted to other providers. [[OpenVPN (client) in Linux containers]] also has general applicable instructions, while it goes a step further by isolating an OpenVPN client process into a container.<br />
<br />
{{Note|Most free VPN providers will (often only) offer [[PPTP server|PPTP]], which is drastically easier to setup and configure, but [http://poptop.sourceforge.net/dox/protocol-security.phtml not secure].}}<br />
<br />
== Create a Public Key Infrastructure (PKI) from scratch ==<br />
<br />
When setting up an OpenVPN server, users need to create a [[Wikipedia:Public key infrastructure|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 {{ic|/etc/openvpn/server}} at this point:<br />
<br />
ca.crt<br />
dh.pem<br />
servername.crt<br />
servername.key<br />
ta.key<br />
<br />
Alternatively, as of OpenVPN 2.4, one can use Easy-RSA to generate certificates and keys using elliptic curves. See the OpenVPN documentation for details.<br />
<br />
== A basic L3 IP routing configuration ==<br />
<br />
{{Note|Unless otherwise explicitly stated, the rest of this article assumes a basic L3 IP routing configuration.}}<br />
<br />
OpenVPN is an extremely versatile piece of software and many configurations are possible, in fact machines can be both servers and clients.<br />
<br />
With the release of v2.4, server configurations are stored in {{ic|/etc/openvpn/server}} and client configurations are stored in {{ic|/etc/openvpn/client}} and each mode has its own respective systemd unit, namely, {{ic|openvpn-client@.service}} and {{ic|openvpn-server@.service}}.<br />
<br />
=== Example configuration ===<br />
<br />
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:<br />
<br />
* Uses [[Wikipedia:Public key infrastructure|Public Key Infrastructure (PKI)]] for authentication.<br />
* Creates a VPN using a virtual TUN network interface (OSI L3 IP routing).<br />
* Listens for client connections on UDP port 1194 (OpenVPN's official IANA port number[https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml?search=openvpn]).<br />
* Distributes virtual addresses to connecting clients from the 10.8.0.0/24 subnet.<br />
<br />
For more advanced configurations, please see the {{man|8|openvpn}} man page and the [http://openvpn.net/index.php/open-source/documentation OpenVPN documentation].<br />
<br />
=== The server configuration file ===<br />
<br />
{{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.}}<br />
<br />
Copy the example server configuration file {{ic|/usr/share/openvpn/examples/server.conf}} to {{ic|/etc/openvpn/server/server.conf}}.<br />
<br />
Edit the file making a minimum of the following changes:<br />
<br />
{{hc|/etc/openvpn/server/server.conf|<br />
ca ca.crt<br />
cert servername.crt<br />
key servername.key # This file should be kept secret<br />
dh dh.pem<br />
.<br />
tls-crypt ta.key # Replaces ''tls-auth ta.key 0''<br />
.<br />
user nobody<br />
group nobody<br />
}}<br />
<br />
==== Hardening the server ====<br />
<br />
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 {{ic|/etc/openvpn/server/server.conf}}:<br />
<br />
{{hc|/etc/openvpn/server/server.conf|<br />
.<br />
cipher AES-256-CBC<br />
auth SHA512<br />
tls-version-min 1.2<br />
tls-cipher TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA:TLS-DHE-RSA-WITH-AES-128-CBC-SHA:TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA<br />
.<br />
}}<br />
<br />
{{Note|The .ovpn client profile '''must''' contain a matching cipher and auth line to work properly (at least with the iOS and Android client)!}}<br />
<br />
==== Enabling compression ====<br />
<br />
Since OpenVPN v2.4 it is possible to use LZ4 compression over lzo. LZ4 generally offering the best performance with least CPU usage. For backwards compatibility with OpenVPN versions before v2.4, use lzo {{ic|comp-lzo}}. Do '''not''' enable both compression options at the same time.<br />
<br />
To do so, configure {{ic|/etc/openvpn/server/server.conf}} as such:<br />
<br />
{{hc|/etc/openvpn/server/server.conf|<br />
.<br />
compress lz4-v2<br />
push "compress lz4-v2"<br />
.<br />
}}<br />
<br />
On the client set {{ic|--compress lz4}} [https://community.openvpn.net/openvpn/wiki/DeprecatedOptions], although this may be deprecated in the near future.<br />
<br />
==== Deviating from the standard port and/or protocol ====<br />
<br />
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.<br />
<br />
To do so, configure {{ic|/etc/openvpn/server/server.conf}} as such:<br />
{{hc|/etc/openvpn/server/server.conf|<br />
.<br />
port 443<br />
proto tcp<br />
.<br />
}}<br />
<br />
{{Note|The .ovpn client profile '''must''' contain a matching port and proto line to work properly!}}<br />
<br />
===== TCP vs UDP =====<br />
<br />
There are subtle differences between TCP and UDP.<br />
<br />
TCP<br />
<br />
* So-called "stateful protocol."<br />
* High reliability due to error correction (i.e. waits for packet acknowledgment).<br />
* Potentially slower than UDP.<br />
<br />
UDP<br />
<br />
* So-called "stateless protocol."<br />
* Less reliable than TCP as no error correction is in use.<br />
* Potentially faster than TCP.<br />
<br />
{{Note|It is generally a bad idea to use TCP for VPN unless your connection to the server is very stable. High reliability sounds great in theory but any disruption (packet drop, lag spikes, etc...) to the connection will potentially snowball into a [http://sites.inka.de/bigred/devel/tcp-tcp.html TCP Meltdown][http://adsabs.harvard.edu/abs/2005SPIE.6011..138H].}}<br />
<br />
=== The client config profile ===<br />
<br />
Copy the example client configuration file {{ic|/usr/share/openvpn/examples/client.conf}} to {{ic|/etc/openvpn/client/}}.<br />
<br />
Edit the following:<br />
<br />
* The {{ic|remote}} directive to reflect either the server's [[Wikipedia:Fully qualified domain name|Fully Qualified Domain Name]], hostname (as known to the client), or its IP address.<br />
* Uncomment the {{ic|user}} and {{ic|group}} directives to drop privileges.<br />
* The {{ic|ca}}, {{ic|cert}}, and {{ic|key}} parameters to reflect the path and names of the keys and certificates.<br />
* Enable the TLS HMAC handshake protection ({{ic|--tls-crypt}} or {{ic|--tls-auth}}).<br />
<br />
{{hc|/etc/openvpn/client/client.conf|<br />
client<br />
remote elmer.acmecorp.org 1194<br />
.<br />
user nobody<br />
group nobody<br />
ca ca.crt<br />
cert client.crt<br />
key client.key<br />
.<br />
tls-crypt ta.key # Replaces ''tls-auth ta.key 1''<br />
}}<br />
<br />
==== Run as unprivileged user ====<br />
<br />
Using the options {{ic|user nobody}} and {{ic|group nobody}} in the configuration file makes ''OpenVPN'' drop its {{ic|root}} 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 may be considered beneficial. It can also happen, however, 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.<br />
<br />
As it could seem to require manual action to manage the routes, the options {{ic|user nobody}} and {{ic|group nobody}} might seem undesirable. Depending on setup, however, there are different ways to handle these situations: <br />
<br />
* For errors of the unit, a simple way is to [[edit]] it and add a {{ic|1=Restart=on-failure}} to the {{ic|[Service]}} section. Though, this alone will not delete any obsoleted routes, so it may happen that the restarted tunnel is not routed properly. <br />
* The package contains the {{ic|/usr/lib/openvpn/plugins/openvpn-plugin-down-root.so}}, 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 (see also its [https://community.openvpn.net/openvpn/browser/plugin/down-root/README?rev=d02a86d37bed69ee3fb63d08913623a86c88da15 README]).<br />
<br />
The OpenVPN HowTo's linked below go further by creating a dedicated non-privileged user/group, instead of the already existing {{ic|nobody}}. The advantage is that this avoids potential risks when sharing a user among daemons:<br />
* The [https://openvpn.net/index.php/open-source/documentation/howto.html#security OpenVPN HowTo] explains another way how to create an unprivileged user mode and wrapper script to have the routes restored automatically.<br />
* It is possible to let OpenVPN start as a non-privileged user in the first place, without ever running as root, see [https://community.openvpn.net/openvpn/wiki/UnprivilegedUser this OpenVPN wiki] (howto). The howto assumes the presence of System V init, rather than [[Systemd]] and does not cover the handling of {{ic|--up}}/{{ic|--down}} scripts - those should be handled the same way as the ''ip'' command, with additional attention to access rights.<br />
<br />
{{Note|Due to a [https://community.openvpn.net/openvpn/ticket/812 bug] in OpenVPN 2.4.0, the {{ic|persist-tun}} option mentioned in the howtos should '''not''' be used, otherwise new routes/IPs pushed on reconnect will be ignored by the client.}}<br />
<br />
{{Tip|[[#openvpn-unroot]] describes a tool to automate above setup.}}<br />
<br />
=== Converting certificates to encrypted .p12 format ===<br />
<br />
Some software will only read VPN certificates that are stored in a password-encrypted .p12 file. These can be generated with the following command:<br />
{{bc|# openssl pkcs12 -export -inkey keys/bugs.key -in keys/bugs.crt -certfile keys/ca.crt -out keys/bugs.p12}}<br />
<br />
=== Testing the OpenVPN configuration ===<br />
<br />
Run {{ic|# openvpn /etc/openvpn/server/server.conf}} on the server, and {{ic|# openvpn /etc/openvpn/client/client.conf}} on the client. Example output should be similar to the following:<br />
<br />
{{hc|# openvpn /etc/openvpn/server/server.conf|2=<br />
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<br />
Wed Dec 28 14:41:26 2011 NOTE: OpenVPN 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables<br />
Wed Dec 28 14:41:26 2011 Diffie-Hellman initialized with 2048 bit key<br />
.<br />
.<br />
Wed Dec 28 14:41:54 2011 bugs/95.126.136.73:48904 MULTI: primary virtual IP for bugs/95.126.136.73:48904: 10.8.0.6<br />
Wed Dec 28 14:41:57 2011 bugs/95.126.136.73:48904 PUSH: Received control message: 'PUSH_REQUEST'<br />
Wed Dec 28 14:41:57 2011 bugs/95.126.136.73:48904 SENT CONTROL [bugs]: 'PUSH_REPLY,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5' (status=1)<br />
}}<br />
<br />
{{hc|# openvpn /etc/openvpn/client/client.conf|2=<br />
Wed Dec 28 14:41:50 2011 OpenVPN 2.2.1 i686-pc-linux-gnu [SSL] [LZO2] [EPOLL] [eurephia] built on Aug 13 2011<br />
Wed Dec 28 14:41:50 2011 NOTE: OpenVPN 2.1 requires '--script-security 2' or higher to call user-defined scripts or executables<br />
Wed Dec 28 14:41:50 2011 LZO compression initialized<br />
.<br />
.<br />
Wed Dec 28 14:41:57 2011 GID set to nobody<br />
Wed Dec 28 14:41:57 2011 UID set to nobody<br />
Wed Dec 28 14:41:57 2011 Initialization Sequence Completed<br />
}}<br />
<br />
On the server, find the IP address assigned to the tunX device:<br />
<br />
{{hc|# ip addr show|2=<br />
.<br />
.<br />
40: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100<br />
link/none<br />
inet 10.8.0.1 peer 10.8.0.2/32 scope global tun0<br />
}}<br />
<br />
Here we see that the server end of the tunnel has been given the IP address 10.8.0.1.<br />
<br />
Do the same on the client:<br />
<br />
{{hc|# ip addr show|2=<br />
.<br />
.<br />
37: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100<br />
link/none<br />
inet 10.8.0.6 peer 10.8.0.5/32 scope global tun0<br />
}}<br />
<br />
And the client side has been given the IP address 10.8.0.6.<br />
<br />
Now try pinging the interfaces.<br />
<br />
On the server:<br />
<br />
{{hc|# ping -c3 10.8.0.6|2=<br />
PING 10.8.0.6 (10.8.0.6) 56(84) bytes of data.<br />
64 bytes from 10.8.0.6: icmp_req=1 ttl=64 time=238 ms<br />
64 bytes from 10.8.0.6: icmp_req=2 ttl=64 time=237 ms<br />
64 bytes from 10.8.0.6: icmp_req=3 ttl=64 time=205 ms<br />
<br />
--- 10.8.0.6 ping statistics ---<br />
3 packets transmitted, 3 received, 0% packet loss, time 2002ms<br />
rtt min/avg/max/mdev = 205.862/227.266/238.788/15.160 ms<br />
}}<br />
<br />
On the client:<br />
<br />
{{hc|# ping -c3 10.8.0.1|2=<br />
PING 10.8.0.1 (10.8.0.1) 56(84) bytes of data.<br />
64 bytes from 10.8.0.1: icmp_req=1 ttl=64 time=158 ms<br />
64 bytes from 10.8.0.1: icmp_req=2 ttl=64 time=158 ms<br />
64 bytes from 10.8.0.1: icmp_req=3 ttl=64 time=157 ms<br />
<br />
--- 10.8.0.1 ping statistics ---<br />
3 packets transmitted, 3 received, 0% packet loss, time 2001ms<br />
rtt min/avg/max/mdev = 157.426/158.278/158.940/0.711 ms<br />
}}<br />
<br />
{{Note|If using a firewall, make sure that IP packets on the TUN device are not blocked.}}<br />
<br />
=== Configure the MTU with Fragment and MSS ===<br />
<br />
{{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.}}<br />
<br />
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.<br />
<br />
{{Accuracy|Output is different - I do not see anything like {{ic|...Frag needed and DF set...}}}}<br />
<br />
{{hc|# ping -c5 -M do -s 1500 elmer.acmecorp.org|2=<br />
PING elmer.acmecorp.org (99.88.77.66) 1500(1528) bytes of data.<br />
From 1.2.3.4 (99.88.77.66) icmp_seq=1 Frag needed and DF set (mtu = 576)<br />
From 1.2.3.4 (99.88.77.66) icmp_seq=1 Frag needed and DF set (mtu = 576)<br />
From 1.2.3.4 (99.88.77.66) icmp_seq=1 Frag needed and DF set (mtu = 576)<br />
From 1.2.3.4 (99.88.77.66) icmp_seq=1 Frag needed and DF set (mtu = 576)<br />
From 1.2.3.4 (99.88.77.66) icmp_seq=1 Frag needed and DF set (mtu = 576)<br />
<br />
--- core.myrelay.net ping statistics ---<br />
0 packets transmitted, 0 received, +5 errors<br />
}}<br />
<br />
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.<br />
<br />
{{hc|# ping -c5 -M do -s 548 elmer.acmecorp.org|2=<br />
PING elmer.acmecorp.org (99.88.77.66) 548(576) bytes of data.<br />
556 bytes from 99.88.77.66: icmp_seq=1 ttl=48 time=206 ms<br />
556 bytes from 99.88.77.66: icmp_seq=2 ttl=48 time=224 ms<br />
556 bytes from 99.88.77.66: icmp_seq=3 ttl=48 time=206 ms<br />
556 bytes from 99.88.77.66: icmp_seq=4 ttl=48 time=207 ms<br />
556 bytes from 99.88.77.66: icmp_seq=5 ttl=48 time=208 ms<br />
<br />
--- myrelay.net ping statistics ---<br />
5 packets transmitted, 5 received, 0% packet loss, time 4001ms<br />
rtt min/avg/max/mdev = 206.027/210.603/224.158/6.832 ms<br />
}}<br />
<br />
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).<br />
<br />
{{hc|/etc/openvpn/client/client.conf|<br />
remote elmer.acmecorp.org 1194<br />
...<br />
fragment 548<br />
mssfix 548<br />
...}}<br />
<br />
We also need to tell the server about the fragmentation. Note that "mssfix" is NOT needed in the server configuration.<br />
<br />
{{Note|Clients that do not support the 'fragment' directive (e.g. OpenELEC, [https://forums.openvpn.net/topic13201.html#p31156 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.}}<br />
<br />
{{hc|/etc/openvpn/server/server.conf|<br />
...<br />
fragment 548<br />
}}<br />
<br />
{{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.}}<br />
<br />
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.<br />
{{hc|/etc/openvpn/client/client.conf|<br />
remote elmer.acmecorp.org 1194<br />
...<br />
mtu-test<br />
...<br />
}}<br />
<br />
=== IPv6 ===<br />
<br />
==== Connect to the server via IPv6 ====<br />
<br />
In order to enable Dual Stack for OpenVPN, you have to change {{ic|proto udp}} to {{ic|proto udp6}} in both server.conf and client.conf. Afterwards both IPv4 and IPv6 are enabled.<br />
<br />
==== Provide IPv6 inside the tunnel ====<br />
<br />
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 (DHCPv6-PD)|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:<br />
<br />
* 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).<br />
* 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.<br />
<br />
After you have received a prefix (a /64 is recommended), append the following to the server.conf:<br />
<br />
server-ipv6 2001:db8:0:123::/64<br />
<br />
This is the IPv6 equivalent to the default 10.8.0.0/24 network of OpenVPN and needs to be taken from the DHCPv6 client. Or use for example fd00:1234::/64.<br />
<br />
If you want to push a route to your home network (192.168.1.0/24 equivalent), also append:<br />
<br />
push "route-ipv6 2001:db8:0:abc::/64"<br />
<br />
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 [https://community.openvpn.net/openvpn/wiki/IPv6 OpenVPN Wiki] provides some other configuration options.<br />
<br />
== Starting OpenVPN ==<br />
<br />
=== Manual startup ===<br />
<br />
To troubleshoot a VPN connection, start the client's daemon manually with {{ic|openvpn /etc/openvpn/client/client.conf}} as root. The server can be started the same way using its own configuration file (e.g., {{ic|openvpn /etc/openvpn/server/server.conf}}).<br />
<br />
=== systemd service configuration ===<br />
<br />
To start the OpenVPN server automatically at system boot, [[enable]] {{ic|openvpn-server@''<configuration>''.service}} on the applicable machine. For a client, [[enable]] {{ic|openvpn-client@''<configuration>''.service}} instead. (Leave {{ic|.conf}} out of the {{ic|<configuration>}} string.)<br />
<br />
For example, if the client configuration file is {{ic|/etc/openvpn/client/''client''.conf}}, the service name is {{ic|openvpn-client@''client''.service}}. Or, if the server configuration file is {{ic|/etc/openvpn/server/''server''.conf}}, the service name is {{ic|openvpn-server@''server''.service}}.<br />
<br />
=== Letting NetworkManager start a connection ===<br />
<br />
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 {{ic|/etc/NetworkManager/dispatcher.d/}}. In the following example "Provider" is the name of the NetworkManager connection:<br />
<br />
{{hc|/etc/NetworkManager/dispatcher.d/10-openvpn|2=<br />
#!/bin/bash<br />
<br />
case "$2" in<br />
up)<br />
if [ "$CONNECTION_ID" == "Provider" ]; then<br />
systemctl start openvpn-client@''<configuration>''<br />
fi<br />
;;<br />
down)<br />
systemctl stop openvpn-client@''<configuration>''<br />
;;<br />
esac}}<br />
<br />
See [[NetworkManager#Network services with NetworkManager dispatcher]] for more details.<br />
<br />
=== Gnome configuration ===<br />
<br />
If you would like to connect a client to an OpenVPN server through Gnome's built-in network configuration do the following. First, install {{pkg|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_config_profile]], 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 {{ic|journalctl -b -u NetworkManager}}).<br />
<br />
== Routing all client traffic through the server ==<br />
<br />
{{Note|There are potential pitfalls when routing all traffic through a VPN server. Refer to [http://openvpn.net/index.php/open-source/documentation/howto.html#redirect the OpenVPN documentation on this topic] for more information.}}<br />
<br />
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., {{ic|/etc/openvpn/server/server.conf}}) [http://openvpn.net/index.php/open-source/documentation/howto.html#redirect]:<br />
<br />
push "redirect-gateway def1 bypass-dhcp"<br />
push "dhcp-option DNS 8.8.8.8"<br />
<br />
Change {{ic|8.8.8.8}} to your preferred DNS IP address if configured to run on the same box as the server or else leave it at 8.8.8.8 to use google's DNS.<br />
<br />
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.<br />
<br />
After setting up the configuration file, one must [[Internet_sharing#Enable_packet_forwarding|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]].<br />
<br />
To allow clients to be able to reach other (private) subnets behind the server, you may want to use the {{ic|push "route <address pool> <subnet>"}} option:<br />
<br />
push "route 172.10.142.0 255.255.255.0"<br />
push "route 172.20.142.0 255.255.255.0"<br />
<br />
=== Firewall configuration ===<br />
<br />
==== ufw ====<br />
<br />
In order to configure your ufw settings for VPN traffic first add the following to {{ic|/etc/default/ufw}}:<br />
<br />
{{hc|/etc/default/ufw|2=<br />
DEFAULT_FORWARD_POLICY="ACCEPT"<br />
}}<br />
<br />
Now change {{ic|/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 {{ic|/etc/openvpn/server/server.conf}}. The adapter ID in the example is generically called {{ic|eth0}} so edit it for your system accordingly.<br />
<br />
{{hc|/etc/ufw/before.rules|2=<br />
# NAT (Network Address Translation) table rules<br />
*nat<br />
:POSTROUTING ACCEPT [0:0]<br />
<br />
# Allow traffic from clients to eth0<br />
-A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE<br />
<br />
# do not delete the "COMMIT" line or the NAT table rules above will not be processed<br />
COMMIT<br />
}}<br />
<br />
Open OpenVPN port 1194:<br />
<br />
# ufw allow 1194<br />
<br />
Lastly, reload UFW:<br />
<br />
# ufw reload<br />
<br />
==== iptables ====<br />
<br />
In order to allow VPN traffic through your iptables firewall of your server, first create an iptables rule for NAT forwarding [http://openvpn.net/index.php/open-source/documentation/howto.html#redirect] on the server, assuming the interface you want to forward to is named {{ic|eth0}}:<br />
<br />
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE<br />
<br />
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 [https://community.openvpn.net/openvpn/wiki/255-qconnection-initiated-with-xxxxq-but-i-cannot-ping-the-server-through-the-vpn]:<br />
<br />
{{Warning|There are security implications for the following rules if you do not trust all clients which connect to the server. Refer to the [https://community.openvpn.net/openvpn/wiki/255-qconnection-initiated-with-xxxxq-but-i-cannot-ping-the-server-through-the-vpn OpenVPN documentation on this topic] for more details.}}<br />
<br />
iptables -A INPUT -i tun+ -j ACCEPT<br />
iptables -A FORWARD -i tun+ -j ACCEPT<br />
iptables -A INPUT -i tap+ -j ACCEPT<br />
iptables -A FORWARD -i tap+ -j ACCEPT<br />
<br />
Additionally be sure to accept connections from the OpenVPN port (default 1194) and through the physical interface.<br />
<br />
When you are satisfied make the changes permanent as shown in [[iptables#Configuration and usage]].<br />
<br />
If you have multiple {{ic|tun}} or {{ic|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. {{ic|tun22}} instead of {{ic|tun}}. This is advantageous if you have different firewall rules for different interfaces or OpenVPN configurations.<br />
<br />
=== Prevent leaks if VPN goes down ===<br />
<br />
The idea is simple: prevent all traffic through our default interface (enp3s0 for example) and only allow tun0.<br />
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.<br />
<br />
Be sure to set up a script to restart OpenVPN if it goes down if you do not want to manually restart it.<br />
<br />
==== ufw ====<br />
<br />
# Default policies<br />
ufw default deny incoming<br />
ufw default deny outgoing<br />
<br />
# Openvpn interface (adjust interface accordingly to your configuration)<br />
ufw allow in on tun0<br />
ufw allow out on tun0<br />
<br />
# Local Network (adjust ip accordingly to your configuration)<br />
ufw allow in on enp3s0 from 192.168.1.0/24<br />
ufw allow out on enp3s0 to 192.168.1.0/24<br />
<br />
# Openvpn (adjust port accordingly to your configuration)<br />
ufw allow out on enp3s0 to any port 1194<br />
ufw allow in on enp3s0 from any port 1194<br />
<br />
{{Warning| DNS '''will not''' work '''unless''' you run your own DNS server like [[BIND]]<br />
Otherwise, you will need to allow dns leak. '''Be sure to trust your DNS server!'''<br />
# DNS<br />
ufw allow in from any to any port 53<br />
ufw allow out from any to any port 53<br />
}}<br />
<br />
==== vpnfailsafe ====<br />
<br />
Alternatively, the [https://github.com/wknapik/vpnfailsafe vpnfailsafe] ({{AUR|vpnfailsafe-git}}) script can be used by the client to prevent DNS leaks and ensure that all traffic to the internet goes over the VPN. If the VPN tunnel goes down, internet access will be cut off, except for connections to the VPN server(s). The script contains the functionality of [[#Update resolv-conf script|update-resolv-conf]], so the two do not need to be combined.<br />
<br />
== L3 IPv4 routing==<br />
<br />
This section describes how to connect client/server LANs to each other using L3 IPv4 routing.<br />
<br />
=== Prerequisites for routing a LAN ===<br />
<br />
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.<br />
<br />
==== Routing tables ====<br />
<br />
{{Accuracy|Investigate if a routing protocol like RIP, QUAGGA, BIRD, etc can be used}}<br />
<br />
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.<br />
<br />
* Add a static route to the default gateway routing the VPN subnet to the LAN/VPN gateway's IP address.<br />
* Add a static route on each host on the LAN that needs to send IP packets back to the VPN.<br />
* Use [[iptables]]' NAT feature on the LAN/VPN gateway to masquerade the incoming VPN IP packets.<br />
<br />
=== Connect the server LAN to a client ===<br />
<br />
The server is on a LAN using the 10.66.0.0/24 subnet. To inform the client about the available subnet, add a push directive to the server configuration file:{{hc|/etc/openvpn/server/server.conf|push "route 10.66.0.0 255.255.255.0"}}<br />
<br />
{{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.<br />
}}<br />
<br />
=== Connect the client LAN to a server ===<br />
<br />
Prerequisites:<br />
<br />
* 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 192.168.4.0/24 for the clients LAN.<br />
* Each client's certificate has a unique Common Name, in this case bugs.<br />
* The server may not use the duplicate-cn directive in its config file.<br />
<br />
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.<br />
<br />
# mkdir -p /etc/openvpn/ccd<br />
<br />
Create a file in the client configuration directory called bugs, containing the {{ic|iroute 192.168.4.0 255.255.255.0}} directive. It tells the server what subnet should be routed to the client:<br />
<br />
{{hc|/etc/openvpn/ccd/bugs|iroute 192.168.4.0 255.255.255.0}}<br />
<br />
Add the client-config-dir and the {{ic|route 192.168.4.0 255.255.255.0}} directive to the server configuration file. It tells the server what subnet should be routed from the tun device to the server LAN:<br />
<br />
{{hc|/etc/openvpn/server/server.conf|<br />
client-config-dir ccd<br />
route 192.168.4.0 255.255.255.0<br />
}}<br />
<br />
{{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.<br />
}}<br />
<br />
=== Connect both the client and server LANs ===<br />
<br />
Combine the two previous sections:<br />
<br />
{{hc|/etc/openvpn/server/server.conf|<br />
push "route 10.66.0.0 255.255.255.0"<br />
.<br />
.<br />
client-config-dir ccd<br />
route 192.168.4.0 255.255.255.0<br />
}}<br />
<br />
{{hc|/etc/openvpn/ccd/bugs|iroute 192.168.4.0 255.255.255.0}}<br />
<br />
{{Note|Remember to make sure that all the LANs or the needed hosts can route to all the destinations.}}<br />
<br />
=== Connect clients and client LANs ===<br />
<br />
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: {{hc|/etc/openvpn/server/server.conf|client-to-client}}<br />
<br />
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):<br />
<br />
{{hc|/etc/openvpn/server/server.conf|<br />
client-to-client<br />
push "route 192.168.4.0 255.255.255.0"<br />
push "route 192.168.5.0 255.255.255.0"<br />
.<br />
.<br />
}}<br />
<br />
{{Note|As always, make sure that the routing is properly configured.}}<br />
<br />
== DNS ==<br />
<br />
The DNS servers used by the system are defined in {{ic|/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 {{pkg|openresolv}}, which makes it possible for more than one program to modify {{ic|resolv.conf}} without stepping on each-other's toes.<br />
<br />
Before continuing, test openresolv by restarting your network connection and ensuring that {{ic|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.<br />
<br />
For Linux, OpenVPN can send DNS host information, but expects an external process to act on it. This can be done with the {{ic|client.up}} and {{ic|client.down}} scripts packaged in {{ic|/usr/share/openvpn/contrib/pull-resolv-conf/}}. See their comments on how to install them to {{ic|/etc/openvpn/client/}}. The following is an excerpt of a resulting client configuration using the scripts in conjunction with ''resolvconf'' and options to [[#Run as unprivileged user]]:<br />
<br />
{{hc|/etc/openvpn/client/''clienttunnel''.conf|<br />
user nobody<br />
group nobody<br />
# Optional, choose a suitable path to chroot into for your system<br />
chroot /srv<br />
script-security 2<br />
up /etc/openvpn/client/client.up <br />
plugin /usr/lib/openvpn/plugins/openvpn-plugin-down-root.so "/etc/openvpn/client/client.down tun0"<br />
}}<br />
<br />
=== Update resolv-conf script ===<br />
<br />
The [https://github.com/masterkorp/openvpn-update-resolv-conf openvpn-update-resolv-conf] script is available as an alternative to packaged scripts. It needs to be saved for example at {{ic|/etc/openvpn/update-resolv-conf}} and made executable with [[chmod]]. There is also an AUR package: {{AUR|openvpn-update-resolv-conf}} which will take care of the script installation for you.<br />
<br />
Once the script is installed add lines like the following into your OpenVPN client configuration file:<br />
<br />
script-security 2<br />
up /etc/openvpn/update-resolv-conf<br />
down /etc/openvpn/update-resolv-conf<br />
<br />
{{Note|If manually placing the script on the filesystem, be sure to have {{pkg|openresolv}} installed.}}<br />
<br />
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.<br />
<br />
{{Note|When using {{ic|openresolv}} with the ''-p'' or ''-x'' options in a script (as both the included {{ic|client.up}} and {{ic|update-resolv-conf}} scripts currently do), a DNS resolver like {{Pkg|dnsmasq}} or {{Pkg|unbound}} is required for {{ic|openresolv}} to correctly update {{ic|/etc/resolv.conf}}. In contrast, when using the default DNS resolution from {{ic|libc}} the ''-p'' and ''-x'' options must be removed in order for {{ic|/etc/resolv.conf}} to be correctly updated by {{ic|openresolv}}.<br />
For example, if the script contains a command like {{ic|resolvconf -p -a }} and the default DNS resolver from {{ic|libc}} is being used, change the command in the script to be {{ic|resolvconf -a }}.}}<br />
<br />
=== Update systemd-resolved script ===<br />
<br />
Since systemd-229, [[systemd-networkd]]'s {{ic|systemd-resolved.service}} has exposed an API through DBus allowing management of DNS configuration on a per-link basis. Tools such as {{pkg|openresolv}} may not work reliably when {{ic|/etc/resolv.conf}} is managed by {{ic|systemd-resolved}}, and will not work at all if you are using {{ic|resolve}} instead of {{ic|dns}} in your {{ic|/etc/nsswitch.conf}} file. The [https://github.com/jonathanio/update-systemd-resolved update-systemd-resolved] script is another alternative and links OpenVPN with {{ic|systemd-resolved}} via DBus to update the DNS records.<br />
<br />
If you copy the script into {{ic|/etc/openvpn}} and mark as executable with [[chmod]], or install it via the AUR package ({{AUR|openvpn-update-systemd-resolved}}), you can add lines like the following into your OpenVPN client configuration file:<br />
<br />
script-security 2<br />
setenv PATH /usr/bin<br />
up /etc/openvpn/scripts/update-systemd-resolved<br />
down /etc/openvpn/scripts/update-systemd-resolved<br />
down-pre<br />
<br />
== L2 Ethernet bridging ==<br />
<br />
{{Expansion|Please add a well thought out section on L2 bridging.}}<br />
<br />
For now see: [[OpenVPN Bridge]]<br />
<br />
== Config generators ==<br />
<br />
{{Warning|Users are highly recommended to pass through the manual configuration described above to gain knowledge about options and usage before using any additional automation scripts.}}<br />
<br />
=== ovpngen ===<br />
<br />
The {{AUR|ovpngen}} package provides a simple shell script that creates OpenVPN compatible tunnel profiles in the unified file format suitable for the iOS version of OpenVPN Connect as well as for the Android app.<br />
<br />
Simply invoke the script with 5 tokens:<br />
<br />
# Server Fully Qualified Domain Name of the OpenVPN server (or IP address).<br />
# Full path to the CA cert.<br />
# Full path to the client cert.<br />
# Full path to the client private key.<br />
# Full path to the server TLS shared secret key.<br />
# Optionally a port number.<br />
# Optionally a protocol (udp or tcp).<br />
<br />
Example:<br />
<br />
# ovpngen example.org /etc/openvpn/server/ca.crt /etc/easy-rsa/pki/signed/client1.crt /etc/easy-rsa/pki/private/client1.key /etc/openvpn/server/ta.key > iphone.ovpn<br />
<br />
The resulting {{ic|iphone.ovpn}} can be edited if desired as the script does insert some commented lines.<br />
<br />
The client expects this file to be located in {{ic|/etc/openvpn/client/iphone.conf}}. Note the change in file extension from 'ovpn' to 'conf' in this case.<br />
<br />
{{Tip|If the server.conf contains a specified cipher and/or auth line, it is highly recommended that users manually edit the generated .ovpn file adding matching lines for cipher and auth. Failure to do so may results in connection errors!}}<br />
<br />
=== openvpn-unroot ===<br />
<br />
The steps necessary for OpenVPN to [[#Run as unprivileged user]], can be performed automatically using [https://github.com/wknapik/openvpn-unroot openvpn-unroot] ({{AUR|openvpn-unroot-git}}).<br />
<br />
It automates the actions required for the [https://community.openvpn.net/openvpn/wiki/UnprivilegedUser OpenVPN howto] by adapting it to systemd, and also working around the bug for persistent tun devices mentioned in the note.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Client daemon not reconnecting after suspend ===<br />
<br />
{{AUR|openvpn-reconnect}}, available on the AUR, solves this problem by sending a SIGHUP to openvpn after waking up from suspend.<br />
<br />
Alternatively, you can kill and restart OpenVPN after suspend by creating the folowing systemd service:<br />
<br />
{{hc|1=/etc/systemd/system/openvpn-reconnect.service|2=<br />
[Unit]<br />
Description=Restart OpenVPN after suspend<br />
<br />
[Service]<br />
ExecStart=/usr/bin/pkill --signal SIGHUP --exact openvpn<br />
<br />
[Install]<br />
WantedBy=sleep.target<br />
}}<br />
<br />
[[Enable]] this service for it to take effect.<br />
<br />
=== Connection drops out after some time of inactivity ===<br />
<br />
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 {{ic|keepalive}}directive to the server's configuration:<br />
<br />
{{hc|/etc/openvpn/server/server.conf|<br />
.<br />
.<br />
keepalive 10 120<br />
.<br />
.<br />
}}<br />
<br />
In this case the server will send ping-like messages to all of its clients every 10 seconds, thus keeping the tunnel up.<br />
If the server does not receive a response within 120 seconds from a specific client, it will assume this client is down.<br />
<br />
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.<br />
<br />
=== PID files not present ===<br />
<br />
The default systemd service file for openvpn-client does not have the --writepid flag enabled, despite creating /var/run/openvpn-client. If this breaks a config (such as an i3bar VPN indicator), simply change {{ic|openvpn-client@.service}} using a [[drop-in snippet]]:<br />
<br />
[Service]<br />
ExecStart=<br />
ExecStart=/usr/sbin/openvpn --suppress-timestamps --nobind --config %i.conf --writepid /var/run/openvpn-client/%i.pid<br />
<br />
=== Route configuration fails with systemd-networkd ===<br />
<br />
When using [[systemd-networkd]] to manage network connections and attempting to tunnel all outgoing traffic through the VPN, OpenVPN may fail to add routes. This is a result of systemd-networkd attempting to manage the tun interface before OpenVPN finishes configuring the routes. When this happens, the following message will appear in the OpenVPN log.<br />
<br />
openvpn[458]: RTNETLINK answers: Network is unreachable<br />
openvpn[458]: ERROR: Linux route add command failed: external program exited with error status: 2<br />
<br />
With systemd-233 (currently in [[testing]]), systemd-networkd can be configured to ignore the tun connections and allow OpenVPN to manage them. To do this, create the following file:<br />
<br />
{{hc|1=/etc/systemd/network/90-tun-ignore.network|2=<br />
[Match]<br />
Name=tun*<br />
<br />
[Link]<br />
Unmanaged=true<br />
}}<br />
<br />
[[Restart]] {{ic|systemd-networkd.service}} to apply the changes. To verify that the changes took effect, start the previously problematic OpenVPN connection and run {{ic|networkctl}}. The output should have a line similar to the following:<br />
<br />
7 tun0 none routable unmanaged<br />
<br />
== See also ==<br />
<br />
* [[Wikipedia:OpenVPN]]</div>Mutantoe