From Fedora Project Wiki

m (Removed spurious code tag that was messing up formatting)
Line 16: Line 16:
# <code>./build-dh</code>
# <code>./build-dh</code>
# <code>mkdir /etc/openvpn/keys</code>
# <code>mkdir /etc/openvpn/keys</code>
# <code>cp -ai keys/$( hostname | cut -d. -f1 ).{crt,key} keys/ca.crt keys/dh1024.pem /etc/openvpn/keys/</code>
# <code>cp -ai keys/$( hostname | cut -d. -f1 ).{crt,key} keys/ca.crt keys/dh*.pem /etc/openvpn/keys/</code>
# <code>cp -ai /usr/share/doc/openvpn-*/sample-config-files/roadwarrior-server.conf /etc/openvpn/server.conf</code>
# <code>cp -ai /usr/share/doc/openvpn-*/sample-config-files/roadwarrior-server.conf /etc/openvpn/server.conf</code>
# Edit <code>/etc/openvpn/server.conf</code> appropriately to set your configuration and key paths.
# Edit <code>/etc/openvpn/server.conf</code> appropriately to set your configuration and key paths, which are found in /etc/openvpn/keys/.
# Fix selinux context of files:
# restorecon -Rv /etc/openvpn
# If you have feodra 14 or earlier:
# <code>chkconfig --level 2345 openvpn on</code>
# <code>chkconfig --level 2345 openvpn on</code>
# <code>service openvpn start</code>
# <code>service openvpn start</code>
# If you have fedora 15 or later (Note that 'server' corresponds with the configuration name in /etc/openvpn/ such as server.conf):
# <code>ln -s /lib/systemd/system/openvpn\@.service /etc/systemd/system/multi-user.target.wants/openvpn\@server.service</code>
# <code>systemctl enable openvpn@server.service</code>
# <code>systemctl start openvpn@server.service</code>
# Verify that firewall rules allow traffic in from <code>tun+</code>, out from the LAN to <code>tun+</code>, and in from the outside on UDP port 1194.   
# Verify that firewall rules allow traffic in from <code>tun+</code>, out from the LAN to <code>tun+</code>, and in from the outside on UDP port 1194.   


The following should work (assuming your outside interface is eth1 and your inside interface is eth0):
The following should work (assuming an outside interface is eth1 and an inside interface is eth0):
<pre>
<pre>
iptables -A INPUT -i eth1 -p udp --dport 1194 -j ACCEPT
iptables -A INPUT -i eth1 -p udp --dport 1194 -j ACCEPT

Revision as of 02:31, 6 February 2012

OpenVPN

For more information, see http://www.openvpn.net/.

Setting up an OpenVPN server

  1. yum install openvpn.$HOSTTYPE
  2. Copy /usr/share/openvpn/easy-rsa/2.0 somewhere (like root's home directory with cp -ai /usr/share/openvpn/easy-rsa/2.0 ~/easy-rsa).
  3. cd ~/easy-rsa
  4. Edit vars appropriately.
  5. . vars
  6. ./clean-all
  7. Before continuing, make sure the system time is correct. Preferably, set up NTP .
  8. ./build-ca
  9. ./build-inter $( hostname | cut -d. -f1 )
  10. ./build-dh
  11. mkdir /etc/openvpn/keys
  12. cp -ai keys/$( hostname | cut -d. -f1 ).{crt,key} keys/ca.crt keys/dh*.pem /etc/openvpn/keys/
  13. cp -ai /usr/share/doc/openvpn-*/sample-config-files/roadwarrior-server.conf /etc/openvpn/server.conf
  14. Edit /etc/openvpn/server.conf appropriately to set your configuration and key paths, which are found in /etc/openvpn/keys/.
  15. Fix selinux context of files:
  16. restorecon -Rv /etc/openvpn
  17. If you have feodra 14 or earlier:
  18. chkconfig --level 2345 openvpn on
  19. service openvpn start
  20. If you have fedora 15 or later (Note that 'server' corresponds with the configuration name in /etc/openvpn/ such as server.conf):
  21. ln -s /lib/systemd/system/openvpn\@.service /etc/systemd/system/multi-user.target.wants/openvpn\@server.service
  22. systemctl enable openvpn@server.service
  23. systemctl start openvpn@server.service
  24. Verify that firewall rules allow traffic in from tun+, 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

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.

Setting up a Linux OpenVPN client

You need to generate new keys (or use existing other client/username keys) for the new client/username

On the server:

  1. cd easy-rsa
  2. . vars
  3. ./build-key username

On the client:

  1. Copy username.key, username.crt and ca.crt from server to /etc/openvpn/keys/.
  2. cp -ai /usr/share/doc/openvpn-*/sample-config-files/roadwarrior-client.conf /etc/openvpn/client.conf
  3. Edit /etc/openvpn/client.conf appropriately to set your configuration (just like server configuration, port, compression,..) and key paths.
  4. chkconfig --level 2345 openvpn on
  5. service openvpn start

check /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.

Setting up a Windows OpenVPN client

On the server:

  1. cd easy-rsa
  2. . vars
  3. ./build-key username

On the client:

  1. Install the OpenVPN GUI or the stand-alone OpenVPN client.
  2. Copy username.crt, username.key, and ca.crt to C:\Program Files\OpenVPN\config\ on the client.
  3. Drop roadwarrior-client.conf into C:\Program Files\OpenVPN\config\ as whatever.ovpn and edit appropriately.
  4. Either use the GUI to start the connection, start the OpenVPN service manually, or set the OpenVPN service to start automatically.

Ideally the client should do some verification on the server key with tls-remote in the whatever.ovpn configuration file.