Skip to content

Instantly share code, notes, and snippets.

@ruimgoncalves
Created October 5, 2020 20:20
Show Gist options
  • Save ruimgoncalves/13b63c3b133c505e293146f8f9f3bdf0 to your computer and use it in GitHub Desktop.
Save ruimgoncalves/13b63c3b133c505e293146f8f9f3bdf0 to your computer and use it in GitHub Desktop.
#!/bin/bash
# SoftEther On-Demand Initialization Script
# First, ensure you create a "Local Bridge with New Tap Device" and name it soft or change TAP_DEVICE accordingly
# This script will allow connection to the vpn server from connected vpn clients
# It will create on-demand a bridge between eth0 <-> br0 <-> tap_soft
# with the same ip as the undelying physical adapter
CURRENT_IP=$(ip route get 1 | grep -Po '(?<=src )(\S+)')
CURRENT_GW=$(ip -4 route ls | grep default | grep -Po '(?<=via )(\S+)')
TAP_DEVICE='tap_soft'
echo "Adding bridge adapter to $TAP_DEVICE with existing IP $CURRENT_IP GW $CURRENT_GW"
# set up bridge
ip link add br0 type bridge
ip link set eth0 master br0
# unset eth0 ip info
ip addr flush dev eth0
ip link set dev br0 up
# Setup static ip
ip a add $CURRENT_IP/24 dev br0
ip route add default via $CURRENT_GW
./vpnserver/vpnserver start
while [ -z "`ifconfig | grep $TAP_DEVICE`" ]
do
echo "Wait for tap adapter $TAP_DEVICE "
sleep 2
done
echo "Found VPN adapter, attaching to bridge."
ip link set dev $TAP_DEVICE master br0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment