#!/usr/bin/env bash # # - create GRE tunnel between two servers # - pass all traffic from specified network to GRE tunel # ####### LINUX ####### PATH="/bin:/usr/sbin:/usr/bin:/sbin:/usr/local/bin:/usr/local/sbin" TUNNEL_IF=gre10 VPN_NETWORK=10.254.0.0/16 # entry node LOCAL_ADDR_EXT=162.210.201.13 LOCAL_ADDR_INT=10.254.10.1 # exit node REMOTE_ADDR_EXT=88.32.99.91 REMOTE_ADDR_INT=10.254.20.1 ##################### # create gre interface ip tunnel add "$TUNNEL_IF" mode gre local "$LOCAL_ADDR_EXT" remote "$REMOTE_ADDR_EXT" ttl 255 # start interface ip link set "$TUNNEL_IF" up # setup internal address on interface ip addr add "$LOCAL_ADDR_INT" dev "$TUNNEL_IF" # add route to exit node route add -net "${REMOTE_ADDR_INT%.*}.0" netmask 255.255.255.0 gw "$LOCAL_ADDR_INT" # create rule for vpn network ip rule add from $VPN_NETWORK table 10 # add default rule for vpn table ip route add default via "$LOCAL_ADDR_INT" table 10