Skip to content

Instantly share code, notes, and snippets.

@Darkflib
Created June 26, 2018 18:08
Show Gist options
  • Select an option

  • Save Darkflib/b3e72b2af8e726d07f4b327328d7323f to your computer and use it in GitHub Desktop.

Select an option

Save Darkflib/b3e72b2af8e726d07f4b327328d7323f to your computer and use it in GitHub Desktop.
tinc setup
#!/bin/bash
NETNAME=nbgNet
apt-get -y install tinc
mkdir -p /etc/tinc/$NETNAME/hosts
mkdir -p /mnt/backup/tinc/$NETNAME/
EXTIPADDR=$(ifconfig enp2s0 | grep "inet " | awk -F'[: ]+' '{ print $3 }')
NUMBER=$(hostname -s | sed 's/[^0-9]*//g')
INTIPADDR="10.233.10.$NUMBER"
INTIPRANGE="10.233.10.0/24"
HOSTNAME=$(hostname -s)
echo $EXTIPADDR
echo $NUMBER
echo $INTIPADDR
echo $HOSTNAME
cat << EOF > /etc/tinc/$NETNAME/tinc.conf
Name = $HOSTNAME
Device = /dev/net/tun
AddressFamily = ipv4
ConnectTo = nbg04
ConnectTo = nbg03
EOF
cat << EOF > /etc/tinc/$NETNAME/hosts/$HOSTNAME
Address = $EXTIPADDR
Subnet = $INTIPADDR
EOF
cat << EOF > /etc/tinc/$NETNAME/tinc-up
#!/bin/sh
ip link set \$INTERFACE up
ip addr add $INTIPADDR dev \$INTERFACE
ip route add $INTIPRANGE dev \$INTERFACE
EOF
cat << EOF > /etc/tinc/$NETNAME/tinc-down
#!/bin/sh
ip route del $INTIPRANGE dev \$INTERFACE
ip addr del $INTIPADDR dev \$INTERFACE
ip link set \$INTERFACE down
EOF
chmod +x /etc/tinc/$NETNAME/tinc-down /etc/tinc/$NETNAME/tinc-up
tincd -n $NETNAME -K4096
cp /etc/tinc/$NETNAME/hosts/* /mnt/backup/tinc/$NETNAME/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment