July 26, 2017

How to Rename a Jail Using ezjail on FreeBSD

FreeBSD Logo

This tutorial covers the steps to rename a jail using ezjail on FreeBSD. Instead of deleting and creating a new jail, you can rename an existing jail. This can safe you some time. If you do not use ezjail you can probably adjust the steps that it will work with your jail administration framework.

Root access is required to edit the following files and to execute commands. Log in as root (su) or simply prepend sudo to all commands that require root privileges.

Remove the old jail without deleting the files

Stop the old jail:

ezjail stop old.domain.com

Remove the jail from ezjail’s configuration:

ezjail-admin delete old.domain.com

Now the jail is no longer running but the files are still present on disk.
Check this with the ls command:

ls /usr/jails/old.domain.com/

Note: Make sure to update your DNS as well.

Create the new jail

First we rename the directory of the old jail. This is not needed but the convention dictates that the jail directory name should reflect the hostname for that jail. At the end we will create the new jail. Navigate to the jails directory:

cd /usr/jails/

Rename the old jail directory:

mv old.domain.com new.domain.com

Create the new jail:

ezjail-admin create -x new.domain.com 10.0.0.1

Start the new jail

Start the new jail with:

ezjail start new.domain.com

SSH to the renamed jail and check the hostname:

ssh -A new
hostname
new.domain.com

Speak Your Mind