create: Add -g|--gateway

This commit is contained in:
tschettervictor
2025-05-20 09:00:48 -06:00
committed by GitHub
parent 9950403445
commit 141bc10c28

View File

@@ -44,6 +44,7 @@ usage() {
-C | --clone Create a clone jail. -C | --clone Create a clone jail.
-D | --dual Create jail with both IPv4 and IPv6 networking ('inherit' and 'ip_hostname' only). -D | --dual Create jail with both IPv4 and IPv6 networking ('inherit' and 'ip_hostname' only).
-E | --empty Create an empty container, intended for custom jail builds (thin/thick/linux or unsupported). -E | --empty Create an empty container, intended for custom jail builds (thin/thick/linux or unsupported).
-g | --gateway IP Specify a default router/gateway for the jail.
-L | --linux Create a Linux jail (experimental). -L | --linux Create a Linux jail (experimental).
-M | --static-mac Generate a static MAC address for jail (VNET only). -M | --static-mac Generate a static MAC address for jail (VNET only).
--no-validate Do not validate the release when creating the jail. --no-validate Do not validate the release when creating the jail.
@@ -53,7 +54,7 @@ usage() {
-V | --vnet Enable VNET, and attach to an existing, physical interface. -V | --vnet Enable VNET, and attach to an existing, physical interface.
-v | --vlan VLANID Creates the jail with specified VLAN ID (VNET only). -v | --vlan VLANID Creates the jail with specified VLAN ID (VNET only).
-x | --debug Enable debug mode. -x | --debug Enable debug mode.
-Z | --zfs-opts [zfs,options] Comma separated list of ZFS options to create the jail with. This overrides the defaults. -Z | --zfs-opts zfs,options Comma separated list of ZFS options to create the jail with. This overrides the defaults.
EOF EOF
exit 1 exit 1
@@ -620,7 +621,9 @@ create_jail() {
_ifconfig_inet=SYNCDHCP _ifconfig_inet=SYNCDHCP
else else
# Else apply the default gateway # Else apply the default gateway
if [ -n "${bastille_network_gateway}" ]; then if [ -n "${OPT_GATEWAY}" ]; then
_gateway="${OPT_GATEWAY}"
elif [ -n "${bastille_network_gateway}" ]; then
_gateway="${bastille_network_gateway}" _gateway="${bastille_network_gateway}"
else else
_gateway="$(netstat -4rn | awk '/default/ {print $2}')" _gateway="$(netstat -4rn | awk '/default/ {print $2}')"
@@ -718,6 +721,7 @@ STATIC_MAC=""
DUAL_STACK="" DUAL_STACK=""
VALIDATE_RELEASE="1" VALIDATE_RELEASE="1"
PRIORITY="99" PRIORITY="99"
OPT_GATEWAY=""
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "${1}" in case "${1}" in
-h|--help|help) -h|--help|help)
@@ -740,6 +744,16 @@ while [ $# -gt 0 ]; do
EMPTY_JAIL="1" EMPTY_JAIL="1"
shift shift
;; ;;
-g|--gateway)
OPT_GATEWAY="${2}"
# Validate gateway
if [ -n "${OPT_GATEWAY}" ]; then
if ! validate_ip "${OPT_GATEWAY}" >/dev/null 2>/dev/null; then
error_exit "[ERROR]: Not a valid gateway: ${OPT_GATEWAY}"
fi
fi
shift 2
;;
-L|--linux) -L|--linux)
LINUX_JAIL="1" LINUX_JAIL="1"
shift shift