Project

General

Profile

Support #921

Change The IP Address of a Jail Based on a New Network on FreeBSD

Added by Daniel Curtis about 6 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Jails / Containers
Target version:
Start date:
01/21/2018
Due date:
% Done:

100%

Estimated time:
0.50 h
Spent time:

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
      
  • 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
      

Resources

#1

Updated by Daniel Curtis about 6 years ago

  • Description updated (diff)
  • Status changed from New to Resolved
  • % Done changed from 0 to 100
#2

Updated by Daniel Curtis about 6 years ago

  • Subject changed from Change The IP Address of a Jail Based on a New Network to Change The IP Address of a Jail Based on a New Network on FreeBSD
#3

Updated by Daniel Curtis about 6 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF