So machen Sie Routing-Änderungen dauerhaft

So machen Sie Routing-Änderungen dauerhaft

Ich habe die folgenden Routing-Regeln anzuwenden, sobald tun0 (ein OpenVPN-Tunnel) hochfährt. Diese Regeln helfen dabei, einige Clients in meinem Netzwerk aus dem VPN heraus und direkt ins Internet zu leiten. Wie kann ich diese Regeln am besten anwenden?

Update: Ubuntu 18.04 wird ausgeführt.

ip route add default via 192.168.8.1 table novpn
ip route add 192.168.1.0/24 dev enp4s0 table novpn
ip rule add from 192.168.1.220 table novpn
iptables -t nat -A POSTROUTING -m iprange --src-range 192.168.1.210-192.168.1.220 -o enp5s0 -j MASQUERADE

Antwort1

Sie können Befehle aus der OpenVPN-Konfiguration ausführen wie:

script-security 2
up /path/to/routing/script
down /path/to/routing/downscript

von man openvpn:

   --up cmd
          Run command cmd after successful TUN/TAP device open (pre --user
          UID change).

          cmd  consists  of  a path to script (or executable program), op‐
          tionally followed by arguments. The path and  arguments  may  be
          single-  or  double-quoted and/or escaped using a backslash, and
          should be separated by one or more spaces.

          The up command is useful for  specifying  route  commands  which
          route IP traffic destined for private subnets which exist at the
          other end of the VPN connection into the tunnel.

          For --dev tun execute as:

          cmd  tun_dev  tun_mtu  link_mtu  ifconfig_local_ip  ifconfig_re‐
          mote_ip [ init | restart ]

Antwort2

Sie können dies versuchen (fügen Sie es hinzu /etc/rc.local)

ip route add default via 192.168.8.1 table novpn
ip route add 192.168.1.0/24 dev enp4s0 table novpn
ip rule add from 192.168.1.220 table novpn
iptables -t nat -A POSTROUTING -m iprange --src-range 192.168.1.210-192.168.1.220 -o enp5s0 -j MASQUERADE

verwandte Informationen