Jump to contentJump to page navigation: previous page [access key p]/next page [access key n]
Applies to SUSE Linux Enterprise Server 11 SP4

16 Configuring VPN Server

Nowadays, the Internet connection is cheap and available almost everywhere. It is important that the connection is as secure as possible. Virtual Private Network (VPN) is a secure network within a second, insecure network such as the Internet or WLAN. It can be implemented in different ways and serves several purposes. In this chapter, we focus on VPNs to link branch offices via secure wide area networks (WANs).

16.1 Conceptual Overview

This section defines some term regarding to VPN and introduces a brief overview of some scenarios.

16.1.1 Terminology

Endpoint

The two ends of a tunnel, the source or destination client

Tap Device

A tap device simulates an Ethernet device (layer 2 packets in the OSI model such as IP packets). A tap device is used for creating a network bridge. It works with Ethernet frames.

Tun Device

A tun device simulates a point-to-point network (layer 3 packets in the OSI model such as Ethernet frames). A tun device is used with routing and works with IP frames.

Tunnel

Linking two locations through a primarily public network. From a more technical viewpoint, it is a connection between the client's device and the server's device. Usually a tunnel is encrypted, but it does need to be by definition.

16.1.2 VPN Scenarios

Whenever you setup a VPN connection your IP packets are transferred over your secured tunnel. A tunnel can use a so-called tun or tap device. They are virtual network kernel drivers which implement the transmission of ethernet frames or ip frames/packets.

Any userspace program OpenVPN can attach itself to a tun or tap device to receive packets sent by your OS. The program is also able to write packets to the device.

There are many solutions to set up and build a VPN connection. This section focuses on the OpenVPN package. Compared to other VPN software, OpenVPN can be operated in two modes:

Routed VPN

Routing is an easy solution to set up. It is more efficient and scales better than bridged VPN. Furthermore, it allows the user to tune MTU (Maximum Transfer Unit) to raise efficiency. However, in a heterogeneous environment NetBIOS broadcasts do not work if you do not have a Samba server on the gateway. If you need IPv6, each tun drivers on both ends must support this protocol explicitly. This scenario is depicted in Figure 16.1, “Routed VPN”.

Routed VPN
Figure 16.1: Routed VPN
Bridged VPN

Bridging is a more complex solution. It is recommended when you need to browse Windows file shares across the VPN without setting up a Samba or WINS server. Bridged VPN is also needed if you want to use non-IP protocols (such as IPX) or applications relying on network broadcasts. However, it is less efficient than routed VPN. Another disadvantage is that it does not scale well. This scenarios is depicted in the following figures.

Bridged VPN - Scenario 1
Figure 16.2: Bridged VPN - Scenario 1
Bridged VPN - Scenario 2
Figure 16.3: Bridged VPN - Scenario 2
Bridged VPN - Scenario 3
Figure 16.4: Bridged VPN - Scenario 3

The major difference between bridging and routing is that a routed VPN cannot IP-broadcast while a bridged VPN can.

16.2 Creating the Simplest VPN Example

The following example creates a point-to-point VPN tunnel. It demonstrates how to create a VPN tunnel between one client and a server. It is assumed that your VPN server will use private IP addresses like 192.168.1.120 and your client the IP address 192.168.2.110. You can modify these private IP addresses to your needs but make sure you select addresses which do not conflict with other IP addresses.

Warning
Warning: Use It Only For Testing

This scenario is only useful for testing and is considered as an example to get familiar with VPN. Do not use this as a real world scenario to connect as it can compromise your security and the safety of your IT infrastructure!

16.2.1 Configuring the VPN Server

To configure a VPN server, proceed as follows:

Procedure 16.1: VPN Server Configuration
  1. Install the package openvpn on the machine that will later become your VPN server.

  2. Open a shell, become root and create the VPN secret key:

    openvpn --genkey --secret /etc/openvpn/secret.key
  3. Copy the secret key to your client:

    scp /etc/openvpn/secret.key root@192.168.2.110:/etc/openvpn/
  4. Create the file /etc/openvpn/server.conf with the following content:

    dev tun
    ifconfig 192.168.1.120 192.168.2.110
    secret secret.key
  5. If you use a firewall, start YaST and open UDP port 1194 (Security and Users › Firewall › Allowed Services.

  6. Start the OpenVPN service as root:

    rcopenvpn start

16.2.2 Configuring the VPN Client

To configure the VPN client, do the following:

Procedure 16.2: VPN Client Configuration
  1. Install the package openvpn on your client VPN machine.

  2. Create /etc/openvpn/client.conf with the following content:

    remote IP_OF_SERVER
    dev tun
    ifconfig 192.168.2.110 192.168.1.120
    secret secret.key

    Replace the placeholder IP_OF_SERVER in the first line with either the domain name, or the public IP address of your server.

  3. If you use a firewall, start YaST and open UDP port 1194 as described in Step 5 of Procedure 16.1, “VPN Server Configuration”.

  4. Start the OpenVPN service as root:

    rcopenvpn start

16.2.3 Testing the VPN Example

After the OpenVPN is successfully started, test if the tun device is available with the following command:

ifconfig tun0

To verify the VPN connection, use ping on both client and server to see if you can reach each other. Ping server from client:

ping -I tun0 192.168.1.120

Ping client from server:

ping -I tun0 192.168.2.110

16.3 Setting Up Your VPN Server Using Certificate Authority

The example shown in Section 16.2 is useful for testing, but not for daily work. This section explains how to build a VPN server that allows more than one connection at the same time. This is done with a public key infrastructure (PKI). A PKI consists of a pair of public and private keys for the server and each client and a master certificate authority (CA), which is used to sign every server and client certificate.

The general overview of this process involves the following steps explained in these sections:

16.3.1 Creating Certificates

Before a VPN connection gets established, the client must authenticate the server certificate. Conversely, the server must also authenticate the client certificate. This is called mutual authentication. To create such certificates, use the YaST CA module in Chapter 17, Managing X.509 Certification for more details.

To create a VPN root, server, and client CA, proceed as follows:

Procedure 16.3: Creating a VPN Server Certificate
  1. Prepare a common VPN Certificate Authority (CA):

    1. Start the YaST CA module.

    2. Click Create Root CA.

    3. Enter your CA Name and Common Name, for example VPN-Server-CA.

    4. Fill out the other fields like e-mail addresses, organization, etc. and proceed with Next.

    5. Enter your password twice and proceed with Next.

    6. Review the summary. YaST displays the current settings for confirmation. Click Create. The root CA is created then appears in the overview.

  2. Create a VPN server certificate:

    1. Select your created root CA from Step 1 and click Enter CA.

    2. Click the Certificate tab and click Add › Add Server Certificate.

    3. Enter the Common Name, something like openvpn.example.com and proceed with Next.

    4. Enter your password twice and proceed with Next.

    5. Review the summary. YaST displays the current settings for confirmation. Click Create. The VPN server certificate is created and appears in the Certificate tab.

  3. Create VPN client certificates:

    1. Make sure you are on the Certificate tab and click Add › Add Client Certificate.

    2. Enter the Common Name, something like client1.example.com.

    3. Enter the e-mail addresses for your client, something like user1@client1.example.com, and click Add. Proceed with Next.

    4. Enter your password twice and proceed with Next.

    5. Review the summary. YaST displays the current settings for confirmation. Click Create. The VPN client certificate is created and appears in the Certificate tab.

    6. Repeat Step 3 if you need more clients.

After you have successfully finished Procedure 16.3, “Creating a VPN Server Certificate” you have a VPN root CA, a VPN server CA, and one or more VPN client CAs. To finish the task, proceed with the following procedure:

  1. Activate the Certificate tab if you haven't done so yet.

  2. Export the VPN server certificate in two formats: PEM and unencrypted key in PEM.

    1. Select your VPN server CA (openvpn.example.com in our example) and choose Export › Export to File.

    2. Mark Only the Certificate in PEM Format, enter your VPN server certificate password and save the file to /etc/openvpn/server_crt.pem.

    3. Repeat Step 2.a and Step 2.b, but choose from the save dialog window the option Only the Certificate in PEM Format to File.

  3. Export the VPN client certificates and choose an export format, PEM or PKCS12 (preferred). For each client:

    1. Select your VPN client certificate (client1.example.com in our example) and choose Export › Export to File.

    2. Mark Like PKCS12 and Include the CA Chain, enter your VPN client certificate key password and provide a PKCS12 password, and save the file to /etc/openvpn/ssl/client1.pk12.

  4. Copy the files to your client (in our example, client1.example.com).

  5. Export the VPN CA (in our example VPN-Server-CA):

    1. Switch to the Description tab and select Export to File.

    2. Select Advanced › Export to File.

    3. Mark Only the Certificate in PEM Format and save the file to /etc/openvpn/vpn_ca.pem.

If desired, the client PKCS12 file can be converted into the PEM format using this command:

openssl pkcs12 -in client1.p12 -out client1.pem

Enter your client password to create the client1.pem file. The PEM file contains the client certificate, client key, and the CA certificate. You can split this combined file using a text editor and create three separate files. The filenames can be used for the ca, cert, and key options in the OpenVPN configuration file (see Example 16.1, “VPN Server Configuration File”).

16.3.2 Configuring the Server

The configuration file is mostly a summary of /usr/share/doc/packages/openvpn/sample-config-files/server.conf without the comments and with some small changes concerning some paths.

Example 16.1: VPN Server Configuration File
# /etc/openvpn/server.conf
port 1194 1
proto udp 2
dev tun0 3

# Security 4
pkcs12 ssl/client1.p12
# Enable one of these options: 5
# tls-verify openvpn.example.com
# ns-cert-type server
dh   ssl/dh1024.pem

server 192.168.1.120 255.255.255.0 6
ifconfig-pool-persist /var/run/openvpn/ipp.txt 7

# Privileges 8
user nobody
group nobody

# Other configuration 9
keepalive 10 120
comp-lzo
persist-key
persist-tun
status      /var/log/openvpn-status.log
log-append  /var/log/openvpn.log
verb 4

1

The TCP/UDP port to which OpenVPN listens. You have to open up the port in the Firewall, see Chapter 15, Masquerading and Firewalls. The standard port for VPN is 1194, so in most cases you can leave that as it is.

2

The protocol, either UDP or TCP.

3

The tun or tap device, see Section 16.1.1, “Terminology” for the differences.

4

The following lines contain the relative or absolute path to the root server CA certificate (ca), the root CA key (cert), the private server key (key) and the Diffie-Hellman parameters (dh). These were generated in Section 16.3.1, “Creating Certificates”.

5

Verifies the X509 name of a pending TLS connection (option tls-verify) or uses a peer certificate designated as an explicit nsCertType; enable one of the two options.

6

Supplies a VPN subnet. The server can be reached by 192.168.1.120.

7

Records a mapping of clients and its virtual IP address in the given file. Useful when the server goes down and (after the restart) the clients get their previously assigned IP address.

8

For security reasons it is a good idea to run the OpenVPN daemon with reduced privileges. For this reason the group and user nobody is used.

9

Several other configurations, see comment in the original configuration from /usr/share/doc/packages/openvpn/sample-config-files.

After this configuration, you can see log messages from your OpenVPN server under /var/log/openvpn.log. When you have started it for the first time, it should finish it with:

... Initialization Sequence Completed

If you do not see this message, check the log carefully. Usually OpenVPN gives you some hints what is wrong in your configuration file.

16.3.3 Configuring the Clients

The configuration file is mostly a summary from /usr/share/doc/packages/openvpn/sample-config-files/client.conf without the comments and with some small changes concerning some paths.

Example 16.2: VPN Client Configuration File
# /etc/openvpn/client.conf
client 1
dev tun 2
proto udp 3
remote IP_OR_HOSTNAME 1194 4
resolv-retry infinite
nobind

# Privileges 5
user nobody
group nobody

# Try to preserve some state across restarts.
persist-key
persist-tun

# Security 6
ca   ssl/ca.crt
cert ssl/client.crt
key  ssl/client.key

comp-lzo 7

1

We must specify that this machine is a client.

2

The network device. Both clients and server must use the same device.

3

The protocol. Use the same settings as on the server.

4

Replace the placeholder IP_OR_HOSTNAME with the respective hostname or IP address of your VPN server. After the hostname the port of the server is given. You can have multiple lines of remote entries pointing to different VPN servers. This is useful for load balancing between different VPN servers.

5

For security reasons it is a good idea to run the OpenVPN daemon with reduced privileges. For this reason the group and user nobody is used.

6

Contains the client files. For security reasons, it is better to have a separate file pair for each client.

7

Turns compression on. Use it only when the server has this parameter switched on as well.

16.4 Changing Nameservers in VPN

If you need to change name servers before or during your VPN session, use netconfig.

Important
Important: Differences between SUSE Linux Enterprise Desktop and SUSE Linux Enterprise Server

The following procedure is for SUSE Linux Enterprise Servers only without NetworkManager (with ifup). SUSE Linux Enterprise Desktop installations use NetworkManager and must install the NetworkManager-openvpn plug-in.

Use the following procedure to change a name server:

Procedure 16.4: Changing Nameservers
  1. Copy the scripts and make them executable:

    cp /usr/share/doc/packages/openvpn/sample-scripts/client-netconfig.* \
      /etc/openvpn/
    chmod +x /etc/openvpn/client-netconfig.*
  2. Add the following lines to /etc/openvpn/client.conf:

    pull dhcp-options
    up   /etc/openvpn/client-netconfig.up
    down /etc/openvpn/client-netconfig.down

If you need to specify a ranking list of fallback services, use the NETCONFIG_DNS_RANKING variable in /etc/sysconfig/network/config. The default value is auto which resolves to:

+strongswan +openswan +racoon +openvpn -avahi

Preferred service names have the + prefix, fallback services the - prefix.

16.5 KDE- and GNOME Applets For Clients

The following sections describe the setup of OpenVPN connections with the GNOME and KDE desktop tools.

16.5.1 KDE

To setup an OpenVPN connection in KDE4 that can be easily turned on or off, proceed as follows:

  1. Make sure you have installed the NetworkManager-openvpn-kde4 package with all dependencies resolved.

  2. Right-click on a widget of your panel and select Panel Options › Add Widgets....

  3. Select Networks.

  4. Right-click on the icon and choose Manage Connections.

  5. Add a new VPN connection with Add › OpenVPN. A new window opens.

  6. Choose the Connection Type between X.509 Certificates or X.509 With Password depending on what you have setup with your OpenVPN server.

  7. Insert the necessary files into the respective text fields. From our example configuration these are:

    CA file

    /etc/openvpn/ssl/ca.crt

    Certificate

    /etc/openvpn/ssl/client1.crt

    Key

    /etc/openvpn/ssl/client1.key

    Username

    The user

    Password

    The password for the user

  8. If you have not used the KDE Wallet System, you are asked if you want to configure it. Follow the steps in the wizard. After you have finished this step, you are reverted back to the Network Settings dialog.

  9. Finish with Ok.

  10. Enable the connection with your Network manager applet.

16.5.2 GNOME

To setup a OpenVPN connection in GNOME that can be easily turned on or off, proceed as follows:

  1. Make sure you have installed the package NetworkManager-openvpn-gnome and have resolved all dependencies.

  2. Start the Network Connection Editor with AltF2 and insert nm-connection-editor into the text field. A new window appears.

  3. Select the VPN tab and click Add.

  4. Choose the VPN connection type, in this case OpenVPN.

  5. Choose the Authentication type. Select between Certificates (TLS) or Password with Certificates (TLS) depending on the setup of your OpenVPN server.

  6. Insert the necessary files into the respective text fields. According to the example configuration, these are:

    Username

    The user (only available when you have selected Password with Certificates (TLS))

    Password

    The password for the user (only available when you have selected Password with Certificates (TLS))

    User Certificate

    /etc/openvpn/ssl/client1.crt

    CA Certificate

    /etc/openvpn/ssl/ca.crt

    Private Key

    /etc/openvpn/ssl/client1.key

  7. Finish with Apply and Close.

  8. Enable the connection with your Network Manager applet.

16.6 For More Information

For more information about VPN, visit:

  • http://www.openvpn.net: Homepage of VPN

  • man openvpn

  • /usr/share/doc/packages/openvpn/sample-config-files/: Examples of configuration files for different scenarios

  • /usr/src/linux/Documentation/networking/tuntap.txt, install the kernel-source package

Print this page