mac配置route

记录一下这美好的时刻!
(解决需要走本地所有流量的问题)

直接上脚本,需要的请直接拿走

#!/bin/sh

# ppp0: flags=8051 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

name=ppp0
gateway=10.123.456.1

testname=`ifconfig |grep ppp0 | grep -v grep|awk -F ":" '{print $1}'`
if [ "$testname" = "$name" ]
then
      echo "get  name $testname"
      testgateway=`ifconfig |grep inet | grep "$gateway" |grep -v grep|awk '{print $4}'`
      
      if [ "$testgateway" = "$gateway" ]
			then
			      echo "get  gateway $testgateway"
			      # 参考资料   
			      # 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  gateway like '$gateway'"
			fi
else
      echo "not find  name like '$name'"
fi

找找看脚本,是不是有问题? _

你可能感兴趣的:(mac,route)