Supported VPN are:
- Client to server (roadwarrior)
- Network to network (net2net)
openvpn-tunnel-create: fired when a new tunnel is created, takes the tunnel name as argumentopenvpn-tunnel-delete: fired when a new tunnel is deleted, takes the tunnel name as argumentopenvpn-tunnel-modify: fired when a new tunnel is modified, takes the tunnel name as argumentnethserver-openvpn-save: fired when roadwarrior account or server is changedopenvpn-tunnel-upload: used to transform a given file into a ready-to-use tunnel client
Accounts are used to identify clients connecting to the server itself. There are two types of accounts:
- user account: system user with VPN access using user name and password
- vpn-only account: simple account with VPN access only
Each account can be used in a roadwarrior connection (host to net).
If a net to net tunnel is needed, VPNRemoteNetwork and VPNRemoteNetmask
properties must be set to inform the server about remote routes.
When a new account is created, a certificate with same name is generated inside /var/lib/nethserver/certs directory.
Properties:
VPNRemoteNetwork: remote networkVPNRemoteNetmask: remote netmaskOpenVpnIp: reserved IP for the client
Database: vpn
<name>=vpn VPNRemoteNetwork= VPNRemoteNetmask= OpenVpnIp=
All certificates are signed using NethServer default RSA key (/etc/pki/tls/private/NSRV.key).
CA configuration is stored inside /var/lib/nethserver/ directory, all certificates are stored inside /var/lib/nethserver/certs. The nethserver-openvpn-conf action creates:
serial,certindex.attrand/certindex: database of valid and revoked certificatescrlnumberand/etc/openvpn/certs/crl.pem: certificate revocation listdh1024.pem: key for TLS negotation
Certificates in PEM format can be created using the command:
/usr/libexec/nethserver/pki-vpn-gencert <commonName>
The commonName parameter is an unique name stored inside the certificate.
The command will generate key, crt and csr file.
Each generated certificate is referred with a numeric id and saved inside certindex database. OpenSSL will also create a certificate named using the generated id (eg. 02.pem).
Certificate revocation is done via the command:
/usr/libexec/nethserver/pki-vpn-revoke [-d] <commonName>
The commonName parameter is an unique name stored inside the certificate.
If '-d' option is enabled, also delete crt, csr, pem and key files
All certificates will expire after X days, where X is the value of CertificateDuration property inside pki key.
Renew is done via the command:
/usr/libexec/nethserver/pki-vpn-renew <commonName>
The commonName parameter is an unique name stored inside the certificate.
Client configuration is generated using /usr/libexec/nethserver/openvpn-local-client command.
The file will contain the CA certificate inside the <ca>.
Example:
/usr/libexec/nethserver/openvpn-local-client myuser
The OpenVPN server listens on a management socket: /var/spool/openvpn/host-to-net.
It's possible to retrieve server status and execute commands using the socket.
Available scripts:
/usr/libexec/nethserver/openvpn-status: retrieve status of connected clients and return result in JSON format/usr/libexec/nethserver/openvpn-kill: kill a connected client, exits 0 on success, 1 otherwise
Example with netcat:
>INFO:OpenVPN Management Interface Version 1 -- type 'help' for more info status OpenVPN CLIENT LIST Updated,Thu Jan 23 09:22:24 2014 Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since ROUTING TABLE Virtual Address,Common Name,Real Address,Last Ref GLOBAL STATS Max bcast/mcast queue length,0 END
See more on management options: http://openvpn.net/index.php/open-source/documentation/miscellaneous/79-management-interface.html
Properties:
status: enable or disable the OpenVPN server, can beenabledordisabled, default isdisabledAuthMode: authentication mode, can bepassword,certificateorpassword-certificateUDPPort: server listen port, default is1194Mode: network mode, can beroutedorbridged. Default isrouted.ClientToClient: can beenabledordisabled, default isdisabled. When enabled, traffic between VPN clients is allowedCompression: can beenabled,disabledor a valid compression alghoritm (see man openvpn). If set to enabled, adaptive LZO compression is usedRemote: comma-separated list of IPs or host names, it's used as multiple remote option inside client configuration generation scriptPushDns: if set, push the specified DNS as DHCP optionPushDomain: if set, push the specified domain as DHCP optionPushExtraRoutes: ifdisabled, only routes for green interface are pushed, if enabled also all static routes will be pushed. Default isenabledPushNbdd: if set, push the specified NBDD as DHCP optionPushWins: if set, push the specified WINS as DHCP optionCustomRoutes: a comma separated listed of CIDR to be pushed as extra routes to VPN clientsTopology: set roadwarrior server topology, for valid values seeman openvpnNotifyStatus: can beenabledordisabled, default isdisabled. Ifenabled, send a mail notification toNotifyAddressesupon roadwarrior user connect or disconnectNotifyAddresses: comma-separated list of mail addresses, destinations forNotifyStatusproperty
If mode is bridged:
BridgeEndIP: first client IP pool, must be inside the LAN range and outside DHCP rangeBridgeStartIP: last client IP pool, must be inside the LAN range and outside DHCP rangeBridgeName: name of the bridge, default isbr0TapInterface: name of bridged tap interface, default istap0
If mode is routed:
Network: network of VPN clients, eg. 192.168.6.0Netmask: netmask of VPN clients, eg. 255.255.255.0RouteToVPN: can beenabledordisabled, default isdisabled. When enabled, all traffic from client will be routed via VPN tunnel
Example:
openvpn@host-to-net=service AuthMode=password BridgeEndIP=192.168.1.122 BridgeName=br0 BridgeStartIP=192.168.1.121 ClientToClient=disabled Mode=routed Netmask=255.255.255.0 Network=192.168.6.0 NotifyAddresses=root@localhost NotifyStatus=enabled PushDns= PushDomain= PushExtraRoutes=enabled PushNbdd= PushWins= Remote= RouteToVPN=disabled TapInterfaces=tap0 Topology=subnet UDPPort=1194 access=green,red status=enabled
Available topologies are subnet and p2p
If topology is p2p:
- only
pskauthentication mode is available - options
LocalPeerIPandRemotePeerIPmust be set for both server and client - options
RemoteNetworksmust be set if the client should be able to reach networks behind the tunnel server
If topology is subnet:
- only
password,certificateorpassword-certificateauthentication mode are available - options
Networkmust be set for the server
OpenVPN clients are used to connect to a tunnel server obtaining a net2net VPN.
Common properties:
AuthMode: default value iscertificate. Possible values:certificate: use x509 certificate. Certificates, including CA and private key, are saved in/var/lib/nethserver/certs/clientsdirectory in a PEM file namedkey.pempassword: use user name and passwordpassword-certificate: use user name, password and a valid x509 certificatepsk: use a pre-shared key
Cipher: a valid OpenVPN cipher amongopenvpn --show-ciphersCompression: can beenabled,disabledor a valid compression alghoritm (see man openvpn). If set to enabled, adaptive LZO compression is usedLocalPeerIPandRemotePeerIP: IP for the Point to Point hostsPassword: password used for authentication, ifAuthModeispasswordorpassword-certificateProtocol: can beudportcp, default isudpRemoteHost: a list of remote server hostnames or ip addressesRemoteNetworks: list of networks in CIDR format, for each network will be created a route. This networks will also be used by the firewall library to calculate the zone of VPN hosts used inside the firewall rules.RemotePort: remote host portUser: username used for authentication, ifAuthModeispasswordorpassword-certificateWanPriorities: an ordered list of red interfaces which will be used to connect to the server, can be used to prefer a faster WAN over a slower oneTopology: can besubnet(default) orp2pstatus: enable or disable the OpenVPN server, can beenabledordisabled, default isenabled
Files:
- pre-shared key:
/var/lib/nethserver/certs/clients/<name>.key - certificates:
/var/lib/nethserver/certs/<name>.{pem,key}
Database: vpn
c1=tunnel AuthMode=psk Cipher= Compression=disabled Crt= Mode=routed Protocol=udp Psk= RemoteHost=1.2.3.4,8.8.6.7 RemotePort=1122 Topology=subnet WanPriorities=eth2,eth1 status=enabled clntnh2d=tunnel AuthMode=certificate Cipher= Compression=enabled Mode=routed Protocol=udp RemoteHost=1.2.3.4,8.8.6.7 RemotePort=1244 Topology=subnet status=enabled
Servers are instance of OpenVPN listening for incoming connections. Each server runs on its own port and can handle many clients.
When a server is created the following files will be generated:
- a certificate and a private key:
/var/lib/nethserver/openvpn-tunnels/<name>.crtand/var/lib/nethserver/openvpn-tunnels/keys/<name>.key - a pre-shared key
/var/lib/nethserver/openvpn-tunnels/<name>.key
Certificate generation uses a custom version of easy-rsa, see /usr/share/nethserver-openvpn directory content.
Properties:
Cipher: a valid OpenVPN cipher amongopenvpn --show-ciphersCompression: can beenabled,disabledor a valid compression alghoritm (see man openvpn). If set to enabled, adaptive LZO compression is usedLocalNetworks: list of networks in CIDR format, each network will be pushed as route to the clientLocalPeerIPandRemotePeerIP: IP for the Point to Point hostsNetwork: network address of the VPN tunnelPort: listen portProtocol: can beudportcp, default isudpPublicAddresses: list of public IPs or host names used by clients to connect to the serverRemoteNetworks: list of networks in CIDR format, for each network will be created a local routeTopology: can besubnet(default) orp2pstatus: enable or disable the OpenVPN server, can beenabledordisabled, default isdisabled
Database: vpn
server1=openvpn-tunnel-server Cipher= Compression=enabled LocalNetworks=192.168.1.0/24 RemotelNetworks=192.168.6.0/24 Network=10.10.11.0/24 Port=1282 Protocol=udp PublicAddresses=1.2.3.4,test.local.neth.eu Topology=subnet status=enabled psk1=openvpn-tunnel-server Cipher= Compression=enabled LocalNetworks=10.132.0.0/16 LocalPeer=10.68.218.1 Port=1248 Protocol=udp PublicAddresses=1.2.3.4,myfw.host.org RemotePeer=10.68.218.2 Topology=p2p status=disabled
The main templates for the configuration are:
/etc/e-smith/templates/etc/openvpn/host-to-net.conf: allows the customization of roadwarrior server/etc/e-smith/templates/openvpn-tunnel-server/: allows the customization of tunnel server, it's expanded in/etc/openvpn/<tunnel_server_name>.conf/etc/e-smith/templates/openvpn-tunnel-client/: allows the customization of tunnel client, it's expanded in/etc/openvpn/<tunnel_client_name>.conf
All OpenVPN services are handled using systemd instances of the openvpn service.
Every instance has the following form: openvpn@<instance_name> where
instance_name is name of the key inside the vpn e-smith db.
The roadwarrior server has a fixed name: host-to-net.
Instances can be inspected using systemctl command:
systemctl status openvpn@host-to-net systemctl status openvpn@server1
The roadwarrior logs can be found here:
/var/log/openvpn/host-to-net-status.log/var/log/openvpn/openvpn.log
The log of each OpenVPN instance can be seen using journalctl command.
Example:
journalctl -u openvpn@client1 journalctl -u openvpn@host-to-net