Open igalic opened 4 years ago
I'm using prestart/poststart hooks with combination of anchors to add and remove this per jail basis.
Would you mind sharing how, exactly?
So first of all some related pf.conf configuration. I'm using a separate lo1 interface to handle all the traffic.
table <jails> persist counters
nat-anchor "jail-nat/*"
rdr-anchor "jail-rdr/*"
pass quick log on lo0 from <jails> to $jail_out # allow connection from jail to external IP
pass quick on lo1 from <jails> to 172.16.0.1. # DNS for jails
Might be that some lines are missing but I hope you get the idea of how to dynamically handle this.
Poststart hook
#!/usr/bin/env sh
set -e
_name=$IOC_ID _jid=$IOC_JID
_ip=$(echo "$IOC_IP4_ADDR" | grep -o '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}') _if=$(echo "$IOC_IP4_ADDR" | cut -d"|" -f1) _eif="igb0"
printf " + Allow outbound access " pfctl -t jails -T add $_ip 2>/dev/null printf "pass on $_if from $_ip to $_ip\n" | pfctl -a "jail/$_name" -f - echo "nat on $_eif inet proto tcp from $_ip to ! $_ip port "{ http, https }" -> (igb0:0)" | pfctl -a "jail-nat/$_name" -f -
**Prestop hook**
- remove IP from jails table
- remove rules for the anchor
- remove nat from the anchor
set -e
_name=$IOC_ID _jid=$IOC_JID
_ip=$(echo "$IOC_IP4_ADDR" | grep -o '[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}') _if=$(echo "$IOC_IP4_ADDR" | cut -d"|" -f1)
pfctl -t jails -T delete $_ip 2>/dev/null pfctl -a "jail/$_name" -F rules 2>/dev/null pfctl -a "jail-nat/$_name" -F nat 2>/dev/null
I declare my jails with
ip4_addr=vnet0|dhcp
, where thednsmasq
on the host provides IP addresses. Mypf.conf
uses names rather than IPs, and looks like this:so i'd need to reload it every time a jail (re)starts,
pf
needs to be reloaded.What's the best way to do this?