github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/scripts/tun/lan.sh (about)

     1  #!/bin/sh
     2  
     3  set -x
     4  
     5  TABLE=${TABLE:-30002}
     6  LAN_IPS=${LAN_IPS:-"192.168.2.145"}
     7  TUN_NAME=${TUN_NAME:-tun0}
     8  
     9  
    10  sudo ip route flush table ${TABLE}
    11  
    12  sudo ip route replace default dev ${TUN_NAME} table ${TABLE}
    13  
    14  for lan in ${LAN_IPS}; do
    15      sudo ip rule add from ${lan} lookup ${TABLE} priority 30000
    16  done
    17  
    18  sudo iptables -C FORWARD -o ${TUN_NAME} -j ACCEPT
    19  if [ $? -ne 0 ]; then
    20      sudo iptables -I FORWARD -o ${TUN_NAME} -j ACCEPT
    21  fi
    22  sudo iptables -C FORWARD -i ${TUN_NAME} -j ACCEPT
    23  if [ $? -ne 0 ]; then
    24      sudo iptables -I FORWARD -i ${TUN_NAME} -j ACCEPT
    25  fi