История изменений
Исправление achilles_85, (текущая версия) :
Почитал раздел из мана, но есть вопросы. Скрипт выглядит так
#!/bin/bash
# LTE
IF1=wwan0
IF1_IP=`ip addr | grep $IF1 | awk -F"/" '/inet/{ print gensub (/.* /,"","g",$1)}'`
IF1_GW_IP=`ip route | awk '/default.*'$IF1'/ { print $3 }'`
IF1_NET=`ip route | grep kernel | awk '/'$IF1_IP'/ { print $1 }'`
# Local net
IF3=eth0
IF3_IP=`ip addr | grep $IF3 | awk -F"/" '/inet/{ print gensub (/.* /,"","g",$1)}'`
IF3_GW_IP=`ip route | awk '/'$IF3'/ { print $9 }'`
IF3_NET=`ip route | awk '/'$IF3'/ { print $1 }'`
case "$1" in
"ifup")
ip route add $IF1_NET dev $IF1 src $IF1_IP table LTE
ip route add default via $IF1_GW_IP table LTE
ip route add $IF1_NET dev $IF1 src $IF1_IP
ip route add default via $IF1_GW_IP
ip route add $IF3_NET dev $IF3 table LTE
ip route add $IF3_NET dev $IF3 table WG
ip route add $IF1_NET dev $IF1 table WG
ip route add 127.0.0.0/8 dev lo table LTE
ip route add 127.0.0.0/8 dev lo table WG
ip rule add from $IF1_IP table LTE
ip rule add from all fwmark 400 table WG
;;
"ifdown")
ip route delete $IF1_NET dev $IF1 src $IF1_IP table LTE
ip route delete default via $IF1_GW_IP table LTE
ip route delete $IF1_NET dev $IF1 src $IF1_IP
ip route delete default via $IF1_GW_IP
ip route delete $IF3_NET dev $IF3 table LTE
ip route delete $IF3_NET dev $IF3 table WG
ip route delete $IF1_NET dev $IF1 table WG
ip route delete 127.0.0.0/8 dev lo table LTE
ip route delete 127.0.0.0/8 dev lo table WG
ip rule delete from $IF1_IP table LTE
ip rule delete from all fwmark 400 table WG
;;
*)
echo "Failed"
exit 1
;;
esac
Исходная версия achilles_85, :
Почитал раздел из мана, но есть вопросы. Скрипт выглядит так
#!/bin/bash
# LTE
IF1=wwan0
IF1_IP=`ip addr | grep $IF1 | awk -F"/" '/inet/{ print gensub (/.* /,"","g",$1)}'`
IF1_GW_IP=`ip route | awk '/default.*'$IF1'/ { print $3 }'`
IF1_NET=`ip route | grep kernel | awk '/'$IF1_IP'/ { print $1 }'`
# Local net
IF3=eth0
IF3_IP=`ip addr | grep $IF3 | awk -F"/" '/inet/{ print gensub (/.* /,"","g",$1)}'`
IF3_GW_IP=`ip route | awk '/'$IF3'/ { print $9 }'`
IF3_NET=`ip route | awk '/'$IF3'/ { print $1 }'`
case "$1" in
"ifup")
ip route add $IF1_NET dev $IF1 src $IF1_IP table LTE
ip route add default via $IF1_GW_IP table LTE
ip route add $IF1_NET dev $IF1 src $IF1_IP
ip route add default via $IF1_GW_IP
ip route add $IF3_NET dev $IF3 table LTE
ip route add $IF3_NET dev $IF3 table WG
ip route add $IF1_NET dev $IF1 table WG
ip route add 127.0.0.0/8 dev lo table LTE
ip route add 127.0.0.0/8 dev lo table WG
ip rule add from $IF1_IP table LTE
ip rule add from all fwmark 400 table WG
;;
"ifdown")
ip route delete $IF1_NET dev $IF1 src $IF1_IP table LTE
ip route delete default via $IF1_GW_IP table LTE
ip route delete $IF1_NET dev $IF1 src $IF1_IP
ip route delete default via $IF1_GW_IP
ip route delete $IF3_NET dev $IF3 table LTE
ip route delete $IF3_NET dev $IF3 table WG
ip route delete $IF1_NET dev $IF1 table WG
ip route delete 127.0.0.0/8 dev lo table LTE
ip route delete 127.0.0.0/8 dev lo table WG
ip rule delete from $IF1_IP table LTE
ip rule delete from all fwmark 400 table WG
;;
*)
echo "Failed"
exit 1
;;
esac