Last active
January 25, 2021 17:45
-
-
Save paulc/e70802602e2ad9131a4db032b5a5f5b2 to your computer and use it in GitHub Desktop.
Test VNET IPv6 jail configuration
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 | |
# Host network configuration | |
GW=$(route -6 get default | awk '/gateway/ { split($2,a,"%"); print a[1] }') | |
EXT_IFACE=$(route -6 get default | awk '/interface/ { print $2 }') | |
EXT_INET6=$(ifconfig $EXT_IFACE inet6 | awk '/inet6 2/ { print $2; exit }') | |
JAIL=${JAIL-ipv6test} | |
# Create bridge | |
if [ "${BRIDGE}" == "" ] | |
then | |
BRIDGE=$(ifconfig bridge create) | |
BRIDGE_CLEANUP=1 | |
ifconfig ${BRIDGE} up addm ${EXT_IFACE} | |
fi | |
# Create epair | |
EPAIR_HOST=$(ifconfig epair create) | |
EPAIR_JAIL=${EPAIR_HOST%a}b | |
JAIL_IPV6=${JAIL_IPV6-${EXT_INET6%:*}:9999} | |
# Cleanup | |
cleanup() { | |
ifconfig ${EPAIR_JAIL} -vnet ${JAIL} | |
jail -rv ipv6test | |
ifconfig ${EPAIR_HOST} destroy | |
if [ "$BRIDGE_CLEANUP" == 1 ] | |
then | |
ifconfig $BRIDGE destroy | |
fi | |
} | |
trap cleanup INT TERM EXIT | |
# Configure EPAIR | |
ifconfig ${BRIDGE} addm ${EPAIR_HOST} | |
ifconfig ${EPAIR_HOST} inet6 up -ifdisabled | |
# Setup jail | |
jail -cv name=${JAIL} vnet vnet.interface=${EPAIR_JAIL} persist | |
jexec ${JAIL} ifconfig ${EPAIR_JAIL} inet6 up ${JAIL_IPV6} | |
jexec ${JAIL} route -6 add default ${GW}%${EPAIR_JAIL} | |
echo "Jail: ipv6test - ${JAIL_IPV6}" | |
sleep 1 | |
# Check we can connect externally | |
jexec ${JAIL} ping6 -c 1 2a00:1450:400b:c01::65 | |
read -p "Return to quit:" _ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment