Last active
January 23, 2024 15:09
-
-
Save christian-blades-cb/16e8ae55697ae65b5318 to your computer and use it in GitHub Desktop.
Fix issues with using boot2docker with Cisco's AnyConnect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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} |
I forked this and made it work with docker-machine
https://gist.github.com/ori-rad-admin/cb3505349de89efe4075
👍 thanks!
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.
@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
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.