Created
November 1, 2023 17:56
-
-
Save patmaddox/faae27f34e32500c334edf4a1ee7a42d to your computer and use it in GitHub Desktop.
freebsd jail config with host configuring things in guest (iface name, resolv.conf, etc)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
path = "/jails/${name}"; | |
vnet; | |
$iface = "$name"; | |
vnet.interface = "${iface}b"; | |
host.hostname = "$name"; | |
exec.clean; | |
exec.start = "sh /etc/rc"; | |
exec.stop = "sh /etc/rc.shutdown jail"; | |
exec.release = "ifconfig ${iface}a destroy"; | |
enforce_statfs = 1; | |
devfs_ruleset = 6; | |
allow.mount; | |
allow.mount.devfs; | |
mount.devfs; | |
porttest { | |
exec.prepare += "~patmaddox/bin/jlprep $name $ip $iface"; | |
$ip = "192.168.2.5/24"; | |
} | |
tf_snowflake { | |
exec.prepare += "~patmaddox/bin/jlprep $name $ip $iface"; | |
$ip = "192.168.2.14/24"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
if [ ! "$1" -o ! "$2" -o ! "$3" ]; then | |
echo "Usage: jlprep <name> <ip> <iface>" | |
exit 1 | |
fi | |
name=$1 | |
ip=$2 | |
iface=$3 | |
jail="/jails/${name}" | |
## HOST - add interfaces | |
aname=`ifconfig epair create up` | |
bname=`echo "$aname" | sed -e 's/a$/b/'` | |
ifconfig jails addm $aname | |
ifconfig $aname name ${iface}a | |
ifconfig $bname name ${iface}b | |
## JAIL - configure rc.conf et al | |
ipprefix=`echo $ip | grep -o '^[[:digit:]]*.[[:digit:]]*.[[:digit:]]*'` | |
sysrc="sysrc -f ${jail}/etc/rc.conf" | |
$sysrc ifconfig_${iface}b_name="elink" | |
$sysrc ifconfig_elink="${ip}" | |
$sysrc defaultrouter="${ipprefix}.1" | |
$sysrc devfs_load_rulesets="YES" | |
mkdir -p ${jail}/usr/local/etc/pkg/repos | |
echo 'FreeBSD: { enabled: no }' > ${jail}/usr/local/etc/pkg/repos/FreeBSD.conf | |
echo 'poudriere: { url: "http://192.168.2.1", enabled: yes }' > ${jail}/usr/local/etc/pkg/repos/poudriere.conf | |
cat > ${jail}/etc/resolv.conf << EOF | |
nameserver 8.8.8.8 | |
nameserver 8.8.4.4 | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment