Skip to content

Instantly share code, notes, and snippets.

@xuchunyang
Created August 1, 2014 06:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuchunyang/d9b2863dbdff4e4fdfd0 to your computer and use it in GitHub Desktop.
Save xuchunyang/d9b2863dbdff4e4fdfd0 to your computer and use it in GitHub Desktop.
修复 Mac 连上 Bras 之后不能访问外网和校内网的问题
#!/usr/bin/env bash
# Program: 添加东南大学路由表 | http://git.io/AOIiRg
# Note: 使用前需要修改 GATEWAY
# Usage: 添加路由表: sudo add-seu-route.sh
# 删除路由表: sudo add-seu-route.sh del
GATEWAY=192.168.7.1 # 修改成你的连接 bras 前的默认网关
#---------------------------------------------------------------
SEU_NETWORKS=(
58.192.96.0/19 \
121.229.0.0/16 \
121.248.48.0/20 \
211.65.32.0/19 \
211.65.232.0/22 \
172.16.0.0/12 \
202.119.0.0/19 \
202.119.144.0/20 \
)
add_route ()
{
# Make sure connection to gateway is alive
if ! /sbin/ping -W 5 -c 1 $GATEWAY > /dev/null; then
echo "Cannot connect to ${GATEWAY}, check your gateway!"
exit 1
else
# Add SEU route
for i in ${SEU_NETWORKS[@]}; do
/sbin/route add $i $GATEWAY
done
fi
}
del_route ()
{
# Recover orginial default gateway after disconnect from bras
/sbin/route add default $GATEWAY
# Delete SEU route
for i in ${SEU_NETWORKS[@]}; do
/sbin/route delete $i $GATEWAY
done
}
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "You need to run $() with sudo or as root"
exit 1
fi
if [ "$1" == "" ]; then
add_route
elif [ "$1" == "del" ]; then
del_route
else
echo "Usage: [sudo] add-seu-route.sh [del]"
exit 1
fi
#-------------------------------------------------------------------------------
# add-seu-route.sh - public domain - Chunayng Xu <xuchunyang56@gmail.com> 2014

Usage

1. 修改配置:

  • add-seu-route.sh -- 修改 GATEWAY
  • ip-up -- 检查 BRAS_SEU_REMOTE_SERVERppp0 ,可能需要修改
  • ip-down -- 检查 BRAS_SEU_REMOTE_SERVER,可能需要修改

2. 添加可执行权限:

sudo chmod +x add-seu-route.sh ip-up ip-down

3. 移动到相应的目录:

sudo mv ip-up ip-down /etc/ppp
sudo mv add-seu-route.sh /sbin

最终相关配置文件的目录结构:

➜  ~  ls -l /etc/ppp
total 24
-rwxr-xr-x  1 root  wheel  179 Aug  1 13:42 ip-down
-rwxr-xr-x  1 root  wheel  457 Aug  1 13:26 ip-up
-rw-rw-rw-  1 root  wheel   28 Aug  1 12:33 options
➜  ~  ls -l /sbin/add-seu-route.sh
-rwxr-xr-x  1 root  admin  1574 Aug  1 13:42 /sbin/add-seu-route.sh
#!/bin/bash
# Check /var/log/ppp.log or just type "grep remote /var/log/ppp.log" from terminal
BRAS_SEU_REMOTE_SERVER="10.254.32.3"
if [ $IPREMOTE = $BRAS_SEU_REMOTE_SERVER ]; then
# Delete SEU route table
/sbin/add-seu-route.sh del &> /tmp/ppp.log
fi
#!/bin/bash
# Check /var/log/ppp.log or just type "grep remote /var/log/ppp.log" from terminal
BRAS_SEU_REMOTE_SERVER="10.254.32.3"
if [ $IPREMOTE = $BRAS_SEU_REMOTE_SERVER ]; then
# Replace default route (pppd is supposed to do this for us, but it does not work for now)
/sbin/route delete default &> /tmp/ppp.log
/sbin/route add default -interface ppp0 &> /tmp/ppp.log
# Add SEU route table
/sbin/add-seu-route.sh &> /tmp/ppp.log
fi
plugin L2TP.ppp
l2tpnoipsec
@xuchunyang
Copy link
Author

Go to 修复 Mac 连上 bras 后仍无法上网的问题 for more information about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment