I spent a lot of time messing with all of this, that's why I deceided to share my notes.
My aim was to collect sFlow samples and to agregate them (sfacct), store them in a TSDB (influxDB) and graph network traffic (grafana).
- To create encrypted image jails, use the -c switch and either pass bde or eli and follow the instructions on screen: ezjail-admin create -c eli -i 16G example.com 10.0.0.3
Also note, that crypto jails would block the boot process (unless the passphrase is provided via a file or some fetch magic via stdin). So they are being marked as attachblocking and not started during boot time. You need to start them using ezjail-admin startcrypto.
WARNING : This is probably a bad idea to use OpenVPN in a Jail (you will lose *a lot* of time to configure it) but it work's.
I really recommand to read the sources a the bottom of this articles, they were great help.
First things, prepare the host :
ifconfig tun create
echo 'cloned_interfaces="tun0"' >> /etc/rc.conf
Create you Jail (eg named openvpn) with ezjail (cf my previous posts) and change some settings in /usr/local/etc/ezjail/openvpn (you MUST use ifconfig, *_ip_multi0 is NOT supported) :
This is what you should put in /etc/devfs.rules in order to allow openVPN to bind on tun interface :
# Rules for jail <VPN>
[devfsrules_jail_openvpn=5]
add include $devfsrules_hide_all
add include $devfsrules_unhide_basic
add include $devfsrules_unhide_login
add path tun0 unhide
If you have a Warning like this in /var/log/messages :
WARNING: devfs_init_rulesets: could not read rules from /etc/devfs.rules
You sould try to copy the default file, and then clean it and copy only your few lines again (yes, it worked for me...)
Here is the config I made for the OpenVPN server in the jail /usr/local/etc/openvpn/openvpn.conf (the 2 last lines are really important):
port 1194
proto udp
dev tun
ca /etc/ssl/CA/cacert.pem
cert /etc/ssl/CA/certs/srv.crt
key /etc/ssl/CA/certs/srv.key
crl-verify /etc/ssl/CA/crls/crl.pem
dh /etc/ssl/CA/certs/dh2048.pem
server 192.168.40.0 255.255.255.0
ifconfig-pool-persist ipp.txt
keepalive 10 120
cipher BF-CBC
comp-lzo
user nobody
group nobody
persist-key
persist-tun
status openvpn-status.log
verb 3
mute 20
push "redirect-gateway def1"
push "dhcp-option DNS 208.67.222.222" # needed in jail
ifconfig-noexec
route-noexec
Enable OpenVPN at boot in the jail (no, you dont need to enable, neither set, the gateway in the jail) :
echo 'openvpn_enabled="YES"' >> /etc/rc.conf
From the host, you can now restart the jail, check that the tun interface of YOUR host (NOT THE JAIL) has the IP, verify OpenVPN is listening : ezjail-admin restart openvpn
ifconfig tun0
sockstat -4
BTW, did you remember to redirrct UDP port 1194 to the jail, like I explained in my previons ticket? If yes, did you thought to enable NAT for VPN IP? change your /etc/rc.conf and reload conf (with pfctl -vf /etc/pf.conf) : rdr on em0 proto udp to port 1194 -> 10.11.12.1 port 1194
nat on em0 from lo1:network -> (em0)
nat on em0 from 192.168.40.0/24 -> (em0)
If you have some troubles getting an IP on the tun interface, you may (but should not need) try to :
To add another default gateway to a dedicated interface, in this example I want 2 interfaces and one default GW for each IP (my 2nd interface has IP 10.10.10.10)
ip route add default via 10.10.10.1 table 100
ip rule add from 10.10.10.10 table 100
ip rule list
ip route list table local
ip route list table 100