(Redirected from Openvpn)
For more information, see https://community.openvpn.net/.
The configuration snippets here will produce a working server and client config. But take certain precautions if you want to use this approach in a production environment. Important things to avoid are:
With the transition to systemd, OpenVPN no longer has a single monolithic init script, where every connection with a configuration file in /etc/openvpn/ is started automatically. Instead, individual connections can be started and stopped with systemctl.
For example, to start a connection, run systemctl start openvpn-client@foo.service, where the connection is defined in /etc/openvpn/client/foo.conf.
For more information, see Systemd#How_do_I_start.2Fstop_or_enable.2Fdisable_services.3F.
dnf install openvpn easy-rsa/usr/share/easy-rsa/3 somewhere (like /etc/openvpn/ directory with mkdir /etc/openvpn/easy-rsa; cp -rai /usr/share/easy-rsa/3/* /etc/openvpn/easy-rsa/).cd /etc/openvpn/easy-rsavars appropriately../easyrsa clean-all./easyrsa build-ca./easyrsa build-server-full $( hostname | cut -d. -f1 )./easyrsa gen-dhmkdir /etc/openvpn/keyscp -ai keys/$( hostname | cut -d. -f1 ).{crt,key} keys/ca.crt keys/dh*.pem /etc/openvpn/keys/cp -ai /usr/share/doc/openvpn*/sample/sample-config-files/roadwarrior-server.conf /etc/openvpn/serverudp.conf/etc/openvpn/server.conf appropriately to set your configuration and key paths, which are found in /etc/openvpn/keys/.restorecon -Rv /etc/openvpnsystemctl enable openvpn-server@serverudp.servicesystemctl start openvpn-server@serverudp.servicetun+, out from the LAN to tun+, and in from the outside on UDP port 1194.The following should work (assuming an outside interface is eth1 and an inside interface is eth0):
iptables -A INPUT -i eth1 -p udp --dport 1194 -j ACCEPT iptables -A INPUT -i tun+ -j ACCEPT iptables -A FORWARD -i tun+ -j ACCEPT iptables -A FORWARD -i eth0 -o tun+ -j ACCEPT iptables -A FORWARD -i eth1 -o tun+ -m state --state ESTABLISHED,RELATED -j ACCEPT
These commands should work for firewalld:
# The default 'openvpn' service references udp port 1194 firewall-cmd --add-service=openvpn # Add the network interface to the default zone (e.g. "FedoraServer" for Fedora Server) firewall-cmd --add-interface=tun0 --permanent # Allow intra-zone forwarding for the default zone firewall-cmd --add-forward --permanent # Allow masquerading (Network address translation - NAT) for the default zone firewall-cmd --add-masquerade --permanent # Reload FirewallD to check the bootup behaviour firewall-cmd --reload # Show the complete current config firewall-cmd --list-all
Or for genfw (my firewall-generation script, not currently available in Fedora), this in /etc/sysconfig/genfw/rules:
append INPUT -i eth1 -p udp --dport 1194 -j ACCEPT append INPUT -i tun+ -j ACCEPT append FORWARD -i tun+ -j ACCEPT append FORWARD -i eth0 -o tun+ -j ACCEPT append FORWARD -i eth1 -o tun+ -j established
Or for system-config-firewall, you can add these custom rules:
-A INPUT -i eth1 -p udp --dport 1194 -j ACCEPT -A INPUT -i tun+ -j ACCEPT -A FORWARD -i tun+ -j ACCEPT -A FORWARD -i eth0 -o tun+ -j ACCEPT -A FORWARD -i eth1 -o tun+ -m state --state ESTABLISHED,RELATED -j ACCEPT
Create a file iptables-rules in /etc/sysconfig and add the above contents, then in system-config-firewall, choose the "Custom Rules" choice, click "Add", choose IPV4 for the protocol type, and filter for the firewall table. Then select /etc/sysconfig/iptables-rules for the File: choice. Then Apply the changes.
You need to generate new keys (or use existing other client/username keys) for the new client/username
On the server:
cd /etc/openvpn/easy-rsa./easyrsa build-client-full usernameOn the client:
/etc/openvpn/client/.cp -ai /usr/share/doc/openvpn*/sample-config-files/roadwarrior-client.conf /etc/openvpn/client/clientudp.conf/etc/openvpn/client/clientudp.conf appropriately to set your configuration (just like server configuration, port, compression,..) and key paths.systemctl enable openvpn-client@clientudp.servicesystemctl start openvpn-client@clientudp.servicecheck /var/log/messages if things didn't work as expected
Alternatively, on the client, after copying the keys onto the client machine, you can use NetworkManager to add a vpn connection. Make sure you have the NetworkManager-openvpn package installed. Then just add a new VPN connection.
Should also test automatic starting at boot up, with password protected key files and maybe even --auth-user-pass. OpenVPN supports systemd's password passing if build with --enable-systemd via ./configure
On the server:
cd /etc/openvpn/easy-rsa./easyrsa build-client-full usernameOn the client:
C:\Program Files\OpenVPN\config\ on the client.C:\Program Files\OpenVPN\config\ as whatever.ovpn and edit appropriately.Ideally the client should do some verification on the server key with tls-remote in the whatever.ovpn configuration file.
When using OpenVPN with Pacemaker and systemd a command like pcs resource create openvpn-foo systemd:openvpn-client@foo op monitor interval=60s --force is needed to create a new resource for OpenVPN, where the connection is defined in /etc/openvpn/client/foo.conf. Passing --force is required, otherwise the error message "Error: Unable to create resource 'systemd:openvpn-client@foo', it is not installed on this system (use --force to override)" is thrown even the OpenVPN configuration file exists.