Skip to content

Instantly share code, notes, and snippets.

@sudowork
Last active April 26, 2016 01:32
Show Gist options
  • Save sudowork/0147dd9382fd0465471a to your computer and use it in GitHub Desktop.
Save sudowork/0147dd9382fd0465471a to your computer and use it in GitHub Desktop.

Revisions

  1. sudowork revised this gist Feb 2, 2016. 1 changed file with 33 additions and 34 deletions.
    67 changes: 33 additions & 34 deletions vpn_fix.sh
    Original file line number Diff line number Diff line change
    @@ -1,49 +1,48 @@
    #!/usr/bin/env bash
    # You must have sudo ability on your machine
    machine=$1
    if [ -z $machine ]; then
    echo "usage $0 {machine_name}"
    exit
    fi
    docker-machine ls | grep ${machine}
    if [ $? == 1 ]; then

    machine=${1:-"default"}

    if [[ ! $(docker-machine ls | grep ${machine}) ]]; then
    echo "${machine} is not a docker-machine"
    exit 1
    fi
    dm_ip=`docker-machine ip ${machine} | awk -F. '{print $1"."$2"."$3}'`
    fwrule=`sudo ipfw -a list | grep "deny ip from any to any"`
    fwrule_id=`echo $fwrule | awk '{ print $1 }'`
    if [ "$fwrule" != "" ]; then

    # check ipfw firewall rules
    # TODO support pf (new as of Yosemite)
    type "ipfw" > /dev/null 2>&1
    if [ $? -ne 0 ]; then
    fwrule=`sudo 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} ... "
    sudo ipfw delete ${fwrule_id}
    if [ $? == 0 ]; then
    echo "$(tput setaf 2)[OK]$(tput sgr0)"
    echo "$(tput setaf 2)[OK]$(tput sgr0)"
    else
    echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
    exit 1
    echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
    exit 1
    fi
    else
    echo "No rules found. You are good to go"
    else
    echo "No rules found. You are good to go"
    fi
    fi

    # overwrite bad routes
    dm_ip=`docker-machine ip ${machine} | awk -F. '{print $1"."$2"."$3".0/24"}'`
    docker_interface=$(VBoxManage showvminfo ${machine} | grep -o -E 'vboxnet\d\d?')
    if [ -z "${docker_interface}" ]; then
    echo "No docker VM found!"
    exit 1
    echo "No docker VM found!"
    exit 1
    else
    echo "Found docker interface at $(tput setaf 1)${docker_interface}$(tput sgr0). Changing routes ..."
    current_route=$(sudo netstat -rn | grep ${dm_ip})
    if [ -z "${current_route}" ]; then
    # no route, let's add it!
    sudo route -nv add -net ${dm_ip} -interface ${docker_interface}
    else
    sudo route -nv change -net ${dm_ip} -interface ${docker_interface}
    fi

    if [ $? == 0 ]; then
    echo "$(tput setaf 2)[OK]$(tput sgr0)"
    else
    echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
    exit 1
    fi
    fi
    echo "Found docker interface at $(tput setaf 1)${docker_interface}$(tput sgr0). Changing routes ..."
    sudo route delete ${dm_ip} && sudo route add -net ${dm_ip} -interface ${docker_interface}

    if [ $? == 0 ]; then
    echo "$(tput setaf 2)[OK]$(tput sgr0)"
    else
    echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
    exit 1
    fi
    fi
  2. ori-rad-admin revised this gist Apr 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vpn_fix.sh
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ if [ $? == 1 ]; then
    echo "${machine} is not a docker-machine"
    exit 1
    fi
    dm_ip=`docker-machine ip ctti | awk -F. '{print $1"."$2"."$3}'`
    dm_ip=`docker-machine ip ${machine} | awk -F. '{print $1"."$2"."$3}'`
    fwrule=`sudo ipfw -a list | grep "deny ip from any to any"`
    fwrule_id=`echo $fwrule | awk '{ print $1 }'`
    if [ "$fwrule" != "" ]; then
  3. ori-rad-admin revised this gist Mar 12, 2015. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions vpn_fix.sh
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,6 @@ if [ $? == 1 ]; then
    exit 1
    fi
    dm_ip=`docker-machine ip ctti | awk -F. '{print $1"."$2"."$3}'`
    docker-machine stop ${machine}
    fwrule=`sudo ipfw -a list | grep "deny ip from any to any"`
    fwrule_id=`echo $fwrule | awk '{ print $1 }'`
    if [ "$fwrule" != "" ]; then
    @@ -48,4 +47,3 @@ else
    exit 1
    fi
    fi
    docker-machine start ${machine}
  4. ori-rad-admin revised this gist Mar 6, 2015. 1 changed file with 22 additions and 13 deletions.
    35 changes: 22 additions & 13 deletions vpn_fix.sh
    Original file line number Diff line number Diff line change
    @@ -1,42 +1,51 @@
    #!/usr/bin/env bash

    [ $(id -u) = 0 ] || { echo "You must be root (or use 'sudo')" ; exit 1; }

    fwrule=`ipfw -a list | grep "deny ip from any to any"`
    # You must have sudo ability on your machine
    machine=$1
    if [ -z $machine ]; then
    echo "usage $0 {machine_name}"
    exit
    fi
    docker-machine ls | grep ${machine}
    if [ $? == 1 ]; then
    echo "${machine} is not a docker-machine"
    exit 1
    fi
    dm_ip=`docker-machine ip ctti | awk -F. '{print $1"."$2"."$3}'`
    docker-machine stop ${machine}
    fwrule=`sudo 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}
    sudo ipfw delete ${fwrule_id}
    if [ $? == 0 ]; then
    echo "$(tput setaf 2)[OK]$(tput sgr0)"
    else
    echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
    echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
    exit 1
    fi
    else
    echo "No rules found. You are good to go"
    fi

    docker_interface=$(sudo -u $(logname) VBoxManage showvminfo boot2docker-vm | grep -o -E 'vboxnet\d\d?')
    docker_interface=$(VBoxManage showvminfo ${machine} | grep -o -E 'vboxnet\d\d?')
    if [ -z "${docker_interface}" ]; then
    echo "No docker VM found!"
    exit 1
    else
    echo "Found docker interface at $(tput setaf 1)${docker_interface}$(tput sgr0). Changing routes ..."

    current_route=$(netstat -rn | grep 192.168.59)
    current_route=$(sudo netstat -rn | grep ${dm_ip})
    if [ -z "${current_route}" ]; then
    # no route, let's add it!
    route -nv add -net 192.168.59 -interface ${docker_interface}
    sudo route -nv add -net ${dm_ip} -interface ${docker_interface}
    else
    route -nv change -net 192.168.59 -interface ${docker_interface}
    sudo route -nv change -net ${dm_ip} -interface ${docker_interface}
    fi

    if [ $? == 0 ]; then
    echo "$(tput setaf 2)[OK]$(tput sgr0)"
    else
    echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
    exit 1
    fi
    fi
    docker-machine start ${machine}
  5. Christian Blades created this gist Jan 21, 2015.
    42 changes: 42 additions & 0 deletions vpn_fix.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    #!/usr/bin/env bash

    [ $(id -u) = 0 ] || { echo "You must be root (or use 'sudo')" ; exit 1; }

    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}
    if [ $? == 0 ]; then
    echo "$(tput setaf 2)[OK]$(tput sgr0)"
    else
    echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
    exit 1
    fi
    else
    echo "No rules found. You are good to go"
    fi

    docker_interface=$(sudo -u $(logname) VBoxManage showvminfo boot2docker-vm | grep -o -E 'vboxnet\d\d?')
    if [ -z "${docker_interface}" ]; then
    echo "No docker VM found!"
    exit 1
    else
    echo "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}
    else
    route -nv change -net 192.168.59 -interface ${docker_interface}
    fi

    if [ $? == 0 ]; then
    echo "$(tput setaf 2)[OK]$(tput sgr0)"
    else
    echo "$(tput setaf 1)[FAIL]$(tput sgr0)"
    exit 1
    fi
    fi