Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuisPalacios/59ed7e4df2e232689c555cf88bfdb733 to your computer and use it in GitHub Desktop.
Save LuisPalacios/59ed7e4df2e232689c555cf88bfdb733 to your computer and use it in GitHub Desktop.
Sur: Script que se ejecuta al levantar el tunel OpenVPN
#!/bin/bash
# Script que se ejecuta al levantar el tunel OpenVPN
#
# /etc/openvpn/client/sur_cliente_access_de_norte_UP.sh
#
# Documentado en:
# https://www.luispa.com/linux/2014/10/19/bridge-ethernet.html
#
# Interfaces, rutas + IP y MACs asociaré a las interfaces tap y bridge
. /etc/openvpn/client/sur_cliente_access_de_norte_CONFIG.sh
# Activo MASQUERADE para los clientes de LAN
iptables -t nat -I POSTROUTING -o ${ifNorteTunel} -j MASQUERADE # Hacia Internet sale con mi IP
## Tabla de routing para la LAN
##
## Equipos que salen a internet vía el router de Movistar en NORTE
##
# Creo una tabla de routing dedicada
grep -i "^107 Norte" /etc/iproute2/rt_tables > /dev/null 2>&1
if [ "$?" = 1 ]; then
sudo echo "107 Norte" >> /etc/iproute2/rt_tables
fi
ip route add ${ipNorteLanRango} dev ${ifNorteLan} table Norte 2>/dev/null
ip route add default via ${ipNorteTunelRouter} table Norte 2>/dev/null
# Creo una regla que indica qué equipos deben usar dicha tabla de routing
ip rule add from ${ipNorteLanRango} table Norte 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment