Quelques notes sur l’installation d’openvpn sous smartos.

Tout d’abord installer easy-rsa.

git clone https://github.com/OpenVPN/easy-rsa


http://docs.slackware.com/playground:openvpn_-_how_to_set_up_a_slackware_server_and_a_slackware_client

cp vars.example vars
vi vars
bash ./easyrsa init-pki
bash ./easyrsa build-ca
bash ./easyrsa init-pki
bash ./easyrsa gen-req server
bash ./easyrsa build-client-full thomas
cp -ar pki /opt/local/etc/openvpn/                           

Un petit script pour générer le fichier de configuration pour un client.

#!/bin/bash

echo "Generation configuration pour : ${1} "

cat << EOF >> ${1}.opvpn
client
remote vpn.montfort.fr 1194
remote-cert-tls server
dev tun
proto udp
resolv-retry infinite
nobind
persist-key
persist-tun
comp-lzo
verb 3
<ca>
EOF

cat pki/ca.crt >> ${1}.opvpn
echo "</ca>
<cert>" >> ${1}.opvpn
cat pki/issued/${1}.crt >> ${1}.opvpn
echo "</cert>
<key>" >> ${1}.opvpn
cat pki/private/${1}.key >> ${1}.opvpn
echo "</key>">> ${1}.opvpn

Changer le mot de passe d’une clef :

bash ./easyrsa set-rsa-pass thomas

Ensuite il faut relancer la génération des configurations.

Les règles de filtrage à mettre en place.

Fichier ipf.conf

## Trusted Internal
pass in quick on lo0 all
pass out quick on lo0 all
pass in quick on tun0 all                                   
pass out quick on tun0 all                                   
pass in quick on net0 all
pass out quick on net0 all

Fichier ipnat.conf

map net0 10.8.0.0/24 -> 0/32 proxy port ftp ftp/tcp
map net0 10.8.0.0/24 -> 0/32 portmap tcp/udp auto
map net0 10.8.0.0/24 -> 0/32

On applique tout ça.

routeadm -u -e ipv4-forwarding
svcadm enable ipfilter
/usr/sbin/ipnat -C -v -f /etc/ipf/ipnat.conf 
ipnat -l
openvpn --verb 6 --config /opt/local/etc/openvpn/server.conf

On peut automatiser le lancement de openvpn et ne pas avoir à saisir le mot de passe de la clef. Il faut créer un fichier /root/password.txt qui contiendra le mot de passe de la clef privée du serveur. Faire un chmod 600 sur ce fichier. Ajouter –askpass /root/password.txt dans /opt/local/lib/svc/method/openvpn

svcadm clear openvpn
svcs -xv openvpn

Dans le cas où on a plusieurs interfaces

  • Ajouter les interfaces dans la zone
{
    "add_nics": [
        {
            "interface": "net1",
            "index": 1,
            "nic_tag": "vpn",
            "mac": "02:00:00:fb:bd:9a",
            "ip": "178.33.XXX.XXX",
            "netmask": "255.255.0.0",
            "gateway": "188.165.XXX.XXX"
        }
    ]
}
  • Configurer les routes dans la zone. Une route par defaut qui sort par chaque interface.
route add 188.165.XXX.0/24 87.98.XXX.XXX -interface -ifp net0
route add default 188.165.XXX.XXX -ifp net0
netstat -rn
route add 188.165.XXX.0/24 178.33.XXX.XXX -interface -ifp net1
route add default 188.165.XXX.XXX -ifp net1
netstat -rn

Modifier /opt/local/lib/svc/manifest/openvpn.xml pour avoir plusieurs instances.

svccfg -s openvpn list
svccfg -s openvpn add fr443
svccfg -s openvpn:fr443 delprop application
svccfg -s openvpn:fr443 addpg application application
svccfg -s openvpn:fr443 setprop application/config = astring: /opt/local/etc/openvpn/server-fr443.conf
svcadm enable openvpn:fr443
svcs -xv openvpn:fr443

Policy routing

pass in quick on tun1 to net0:188.165.XXX.XXX from 10.8.0.0/24 to any keep state
pass in quick on tun3 to net0:188.165.XXX.XXX from 10.9.0.0/24 to any keep state

Se lit : ce qui arrive sur tun1 et provenant de 10.8.0.0/24 est redirigé sur net0 avec la passerelle 188.165.235.254

Quelques liens utiles