记录一下这美好的时刻!
(解决vpn需要走本地所有流量的问题)
直接上脚本,需要的请直接拿走
bash
#!/bin/sh
# ppp0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1280
# inet 10.123.456.191 --> 10.123.456.1 netmask 0xffffff00
#ifconfig |grep ppp0 | grep -v grep|awk -F ":" '{print $1}'
#ppp0
#ifconfig |grep inet | grep 10.123.456.1 |grep -v grep|awk '{print $4}'
#10.123.456.1
vpnname=ppp0
vpngateway=10.123.456.1
testname=`ifconfig |grep ppp0 | grep -v grep|awk -F ":" '{print $1}'`
if [ "$testname" = "$vpnname" ]
then
echo "get vpn name $testname"
testvpngateway=`ifconfig |grep inet | grep "$vpngateway" |grep -v grep|awk '{print $4}'`
if [ "$testvpngateway" = "$vpngateway" ]
then
echo "get vpn gateway $testvpngateway"
# 参考资料
# http://edulinks.cn/2020/05/19/20200519-macos-route/
# https://blog.csdn.net/weixin_43846408/article/details/124505211
# http://www.taodudu.cc/news/show-5407606.html?action=onClick
echo ""
echo " --- exec cmd: netstat -rn|grep ppp0 ---"
netstat -rn|grep ppp0
echo ""
echo " --- exec cmd: delete route 12.34.56.78 ---"
sudo route -nv delete 12.34.56.78
echo ""
echo " --- exec cmd: add route 12.34.56.78 ---"
sudo route -nv add 12.34.56.78 10.123.456.1
echo ""
echo " --- exec cmd: netstat -rn|grep ppp0 ---"
netstat -rn|grep ppp0
else
echo "not find vpn gateway like '$vpngateway'"
fi
else
echo "not find vpn name like '$vpnname'"
fi
找找看脚本,是不是有问题? ^_^