Zerotier como bridge con interface de red a máquina y otra interface a Internet

Fecha publicación
#
9
Dificultad
Avanzado
3 more properties
Publicado
tags
i40sys, industry 4.0, industry40.systems, zerotier, vpn, industrial, remote access, acceso remoto, plc, siemens, omron, vpn, vxlan

Escenario de ejemplo:
Suponemos que la empresa tiene una red con acceso a Internet y que nos asigna IP por DHCP. Colocaremos nuestro IoT GW con su interface WAN conectada a esta red y la interface LAN del IoT GW la conectaremos a la red donde tenemos el PLC que conecta al a máquina, típicamente al Switch IP de la máquina.

Configuración IP del IoT GW:
YAML
WAN: eth0
	IP: unmanaged (sin configuración IP)
MANTENIMENT: ztc25el5hr
	IP: unmanaged (sin configuración IP)
BRIDGE(BR0): br-br0 (MANTENIMENT + WAN)
	IP: 10.46.1.27

Tabla de Contenidos

/etc/netplan/50-cloud-init.yaml

YAML
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
  version: 2
  ethernets:
    eth0:
      addresses: []
      dhcp4: false
      optional: true
    eth1:
      addresses: []
      dhcp4: true
      optional: true
  bridges:
    br0:
      addresses: [ 10.46.1.27/24 ]
      dhcp4: false
      interfaces:
        - eth0

/opt/network/bridge.sh

Bash
#!/bin/bash
PATH="/bin:/sbin:/usr/bin:/usr/sbin"
export PATH

LOCAL_IF="eth0"
VPN_IF="ztc25el5hr"
BR_IP="10.46.1.27/24"
BR_NET="10.46.1.0/24"

date

# esperem fins que la interficie existeixi
while [ ! -e "/sys/class/net/$VPN_IF" ];
do
  sleep 2;
done

# bridge
#brctl addbr br0
#brctl addif br0 $LOCAL_IF
brctl addif br0 $VPN_IF
brctl setfd br0 0
#brctl setmaxage br0 0

# ip
#ifconfig $LOCAL_IF 0.0.0.0
#ifconfig $VPN_IF 0.0.0.0
#ifconfig br0 $BR_IP
#ifconfig $LOCAL_IF up
#ifconfig $VPN_IF up
#ifconfig br0 up

# route
#ip route add $BR_NET dev br0

# iptables
iptables -I FORWARD -i $VPN_IF -j ACCEPT
iptables -I FORWARD -o $VPN_IF -j ACCEPT
iptables -I FORWARD -i br0 -j ACCEPT
iptables -I FORWARD -o br0 -j ACCEPT
iptables -I FORWARD -i $LOCAL_IF -j ACCEPT
iptables -I FORWARD -o $LOCAL_IF -j ACCEPT

crontab -l

YAML
@reboot /opt/network/bridge.sh > /var/log/bridge.log 2>&1

/var/lib/zerotier-one/network.d/NETWORKID.local.conf

YAML
allowManaged=0
allowGlobal=0
allowDefault=0
allowDNS=0