Skip to content

Instantly share code, notes, and snippets.

@Shonke
Created October 4, 2019 00:37
Show Gist options
  • Save Shonke/097e7d0b03067cf4ed6f31aa8dc7fe67 to your computer and use it in GitHub Desktop.
Save Shonke/097e7d0b03067cf4ed6f31aa8dc7fe67 to your computer and use it in GitHub Desktop.
Layer 2 Bridging with zerotier
#!/bin/bash
# doc: https://zerotier.atlassian.net/servicedesk/customer/portal/1/article/7471125
LOGGING_FILE='/var/log/zt-bridge.log'
LAN_INT='eth3'
BR_INT='br0'
ZT_INT='ztwdjesw7o'
BRIDGE_IP='172.28.10.5/16'
#GATEWAY_IP='192.168.3.5'
SLEEP_TIMER='15s'
#Delay Timer to give the system a chance to finish booting
sleep $SLEEP_TIMER
echo 'find zt tap devices'
zt=$(ip -d tuntap show|grep -B 1 'zerotier-one')
ZT_INT=$(echo $zt|egrep -oh '^(\w+)')
echo 'zt tap device is: '$ZT_INT >> $LOGGING_FILE
#Disable Interfaces, Remove IP addresses
echo 'Disabling Interface' >> $LOGGING_FILE
/sbin/ip link set $LAN_INT down >> $LOGGING_FILE
/sbin/ip link set $ZT_INT down >> $LOGGING_FILE
/sbin/ip addr flush dev $LAN_INT >> $LOGGING_FILE
/sbin/ip addr flush dev $ZT_INT >> $LOGGING_FILE
echo 'Setting up Bridging...' >> $LOGGING_FILE
/sbin/brctl addbr $BR_INT >> $LOGGING_FILE
/sbin/brctl addif $BR_INT $ZT_INT $LAN_INT >> $LOGGING_FILE
/sbin/ip link set $LAN_INT promisc on up >> $LOGGING_FILE
/sbin/ip link set $ZT_INT promisc on up >> $LOGGING_FILE
/sbin/ip link set $BR_INT up >> $LOGGING_FILE
/sbin/ip addr add $BRIDGE_IP dev $BR_INT >> $LOGGING_FILE
#/sbin/route add default gateway $GATEWAY_IP
echo 'Finished!' >> $LOGGING_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment