Support #921
Change The IP Address of a Jail Based on a New Network on FreeBSD
Status:
Closed
Priority:
Normal
Assignee:
Category:
Jails / Containers
Target version:
Description
I have a FreeBSD VM with some jails that use a bridged network interface that changes networks fairly often. Rather than manually changing all the IP addresses manually, I wrote a script that changes the IP address of the jail config based on the network the VM is attached to.
- Create a new shell script:
vi /usr/local/bin/chjailip.sh
- And add the following:
#!/bin/sh # Script to change ezjail config IP address # Get the current primary interface IP and change it to .99 nextcloudip=`ifconfig | grep 255.255.255.255 | grep -Eo '(\b[0-9]{1,3}\.){3}[0-9]{1,3}\b' | grep -v 255 | sed 's/\.[0-9]*$/\.99/'` # Replace the newjail ezjail configs IP address with the newly updated IP sed -i '' -e "s/newjail_ip=\"*.*\"/newjail_ip=\"$newjailip\"/" /usr/local/etc/ezjail/newjail
- And add the following:
- Make the script executable:
chmod +x /usr/local/bin/chjailip.sh
- Edit the crontab:
crontab -e
- And add the script to run every reboot:
@reboot /usr/local/bin/chjailip.sh
- And add the script to run every reboot: