写了个脚本绕过校园网二层隔离,自动化这个教程里面提到的加路由的方法。

依赖 ipcalc 计算子网地址。apt install ipcalc

#!/bin/bash

IPA=$(ip address list dev eth0 | awk ' /inet/ {print $2}' | head -1)
GATE=$(ip route list dev eth0 | awk ' /^default/ {print $3}')

IP=$(echo $IPA | awk -F'/' '{print $1}')
MASK=$(echo $IPA | awk -F'/' '{print $2}')
NETWORK=$(ipcalc $IPA -n -b | grep Network | awk '{print $2}')

echo =========================
echo Your IP: $IP
echo Netmask: $MASK
echo Gateway: $GATE

echo adding route: ip r a $NETWORK via $GATE
sudo ip r a $NETWORK via $GATE
sudo ip r a $GATE dev eth0
echo ok