From 6d75ff25bf30565f0aca76975a0063200a448f7e Mon Sep 17 00:00:00 2001 From: Culsu Date: Sun, 29 Nov 2020 20:44:34 +0100 Subject: [PATCH 1/6] Altered the NIC IP alias to match the example --- README.md | 2 +- jaildk | 0 2 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 jaildk diff --git a/README.md b/README.md index 293695d..6f69b88 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Refer to [jail(8)](https://www.freebsd.org/cgi/man.cgi?query=jail&sektion=8) for Next add the following lines to your `/etc/rc.conf`: ``` -ifconfig_em0_alias0="inet 144.76.67.168/32" +ifconfig_em0_alias0="inet 172.16.1.1/32" jail_enable="YES" ``` diff --git a/jaildk b/jaildk old mode 100644 new mode 100755 From 61ae2100c3bf36ee21f9c97f5ebec2f3a615865e Mon Sep 17 00:00:00 2001 From: Culsu Date: Sun, 29 Nov 2020 22:18:34 +0100 Subject: [PATCH 2/6] Added support to automagically set the hostname in the jails rc.conf based on the hostname in /etc/jail.conf --- jaildk | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/jaildk b/jaildk index b4cf273..910f547 100755 --- a/jaildk +++ b/jaildk @@ -751,6 +751,7 @@ jaildk_clone() { echo else . $j/etc/$src/jail.conf + jail=$new bold "To mount the build chroot of the new jail, execute:" echo "jaildk build $new start $base $newversion" fi @@ -763,6 +764,9 @@ Create a new jail from template." jaildk_create() { jail=$1 + # $jail gets overwritten in jaildk_clone or some subcall to .template :-( ... + newjail=$jail + src=.template if test -z "$jail"; then @@ -774,8 +778,13 @@ jaildk_create() { newversion=`date +%Y%m%d` mkdir -p $j/etc/$jail - + jaildk_clone -s $src -d $jail -o $srcversion -n $newversion + # some perl magic to extract the hostname (if any) from /etc/jail.conf - and write it into the jails rc.conf + jailhostname=$(cat /etc/jail.conf | tr -d '\t\r\n ' | perl -ne '$_ =~ /.*'"$newjail"'(\{(?:\{.*\}|[^{])*\})|\w+/; print $1;' | grep -oE 'hostname=[^;]+' | cut -d= -f2) + sed -iE 's/^hostname.*$/hostname="'"$jailhostname"'"/' $j/etc/$newjail/local-etc-$newversion/rc.conf + + } remove() { From f59920e1197ec1df17f8c6132027b938988c6e8c Mon Sep 17 00:00:00 2001 From: Culsu Date: Sun, 29 Nov 2020 22:20:46 +0100 Subject: [PATCH 3/6] added a safety check --- jaildk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jaildk b/jaildk index 910f547..ac98e0e 100755 --- a/jaildk +++ b/jaildk @@ -782,7 +782,7 @@ jaildk_create() { jaildk_clone -s $src -d $jail -o $srcversion -n $newversion # some perl magic to extract the hostname (if any) from /etc/jail.conf - and write it into the jails rc.conf jailhostname=$(cat /etc/jail.conf | tr -d '\t\r\n ' | perl -ne '$_ =~ /.*'"$newjail"'(\{(?:\{.*\}|[^{])*\})|\w+/; print $1;' | grep -oE 'hostname=[^;]+' | cut -d= -f2) - sed -iE 's/^hostname.*$/hostname="'"$jailhostname"'"/' $j/etc/$newjail/local-etc-$newversion/rc.conf + [ -n "$jailhostname" ] && sed -iE 's/^hostname.*$/hostname="'"$jailhostname"'"/' $j/etc/$newjail/local-etc-$newversion/rc.conf } From 21800fe55ef55e6318cdcf405731d4ec737e13b3 Mon Sep 17 00:00:00 2001 From: Culsu Date: Sun, 29 Nov 2020 22:30:56 +0100 Subject: [PATCH 4/6] Added hint how to restart the network interface (after adding alias) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f69b88..df8994b 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ jail_enable="YES" ``` You may need to replace the interface name `em0` with the one in use on your system. - +To apply the alias to the interface you can use the netif rc script: `/etc/rc.d/netif restart`. ### Create the jail ``` From 82999c9c7a1ce57debe893b25ca752d3bbc949fb Mon Sep 17 00:00:00 2001 From: Culsu Date: Sun, 29 Nov 2020 22:32:24 +0100 Subject: [PATCH 5/6] Added hint how to restart the network interface (after adding alias) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index df8994b..8f2641a 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ jail_enable="YES" ``` You may need to replace the interface name `em0` with the one in use on your system. -To apply the alias to the interface you can use the netif rc script: `/etc/rc.d/netif restart`. +You might need to restart the interface to apply the alias: `/etc/rc.d/netif restart`. ### Create the jail ``` From fd005a540405da7b9b4997d8f5053f5d94321b27 Mon Sep 17 00:00:00 2001 From: Culsu Date: Sun, 29 Nov 2020 22:34:41 +0100 Subject: [PATCH 6/6] jlogin -> login --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f2641a..10e9989 100644 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ fcgiwrap is running as pid 37682. ### Login into the running jail for administration ``` -# jaildk jlogin myjail +# jaildk login myjail ``` You can use this to login into a database or execute commands inside the jail.