Skip to content

Instantly share code, notes, and snippets.

@christian-blades-cb
Last active January 23, 2024 15:09
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save christian-blades-cb/16e8ae55697ae65b5318 to your computer and use it in GitHub Desktop.
Save christian-blades-cb/16e8ae55697ae65b5318 to your computer and use it in GitHub Desktop.
Fix issues with using boot2docker with Cisco's AnyConnect
#!/usr/bin/env bash
# If you're using docker-machine, call this script with your
# environment name
# Ex: ./vpn_fix dev
DEFAULTVM="boot2docker-vm"
[ $(id -u) = 0 ] || { echo "You must be root (or use 'sudo')" ; exit 1; }
report_success ()
{
if [ $? == 0 ]; then
echo "$(tput setaf 2)[OK]$(tput sgr0)"
else
echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
exit 1
fi
}
firewall_down ()
{
fwrule=`ipfw -a list | grep "deny ip from any to any"`
fwrule_id=`echo $fwrule | awk '{ print $1 }'`
if [ "$fwrule" != "" ]; then
echo "Found blocking firewall rule: $(tput setaf 1)${fwrule}$(tput sgr0)"
printf "Deleting rule ${fwrule_id} ... "
ipfw delete ${fwrule_id}
report_success
else
echo "No firewall rules found. Good!"
fi
}
restore_route ()
{
vm_name=${1}
docker_interface=$(sudo -u $(logname) VBoxManage showvminfo "${vm_name}" --machinereadable | awk -F "=" '/hostonlyadapter/ { gsub("\"", "", $2); print $2 }' | head -n1)
if [ -z "${docker_interface}" ]; then
echo "No docker VM found! Maybe ${vm_name} isn't running?"
else
printf "Found docker interface at $(tput setaf 1)${docker_interface}$(tput sgr0). Changing routes ... "
current_route=$(netstat -rn | grep 192.168.59)
if [ -z "${current_route}" ]; then
# no route, let's add it!
route -nv add -net 192.168.59 -interface ${docker_interface} > /dev/null
else
route -nv change -net 192.168.59 -interface ${docker_interface} > /dev/null
fi
report_success
fi
}
firewall_down
restore_route ${1-$DEFAULT_VM}
@jtyberg
Copy link

jtyberg commented Jan 30, 2015

Worked for me, thanks. Only issue is that Cisco AnyConnect (version 3.1.04074) does not allow modifying routes. I had to disconnect first, run script, then re-connect.

Copy link

ghost commented Mar 6, 2015

I forked this and made it work with docker-machine
https://gist.github.com/ori-rad-admin/cb3505349de89efe4075

@tegansnyder
Copy link

👍 thanks!

@christian-blades-cb
Copy link
Author

I've heard that this solution doesn't work with Yosemite. I haven't upgraded, so I haven't had a chance to find a new way.

@sudowork
Copy link

sudowork commented Feb 2, 2016

@christian-blades-cb, I've got a version of this script working with Yosemite (forked from @ori-rad-admin's script that uses docker-machine).

The main changes are basically:

dm_ip=`docker-machine ip ${machine} | awk -F. '{print $1"."$2"."$3".0/24"}'` 
sudo route delete ${dm_ip} && sudo route add -net ${dm_ip} -interface ${docker_interface}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment