即使答案可能非常简单,我也找不到解决此问题的任何方法。
我正试图让鱿鱼通过3g加密狗重定向流量,因此我需要列出IP,并在每次更改时在squid.conf中对其进行更改。
我在“ /etc/ppp/ip-up.local”上使用此代码,因此每次新IP连接(或重新连接)到计算机时都会启动它。
#!/bin/bash
if [[ "$PPP_IFACE" == "ppp0" ]] ; then
TABLE=uplink2
/bin/sed -i "s&\(tcp_outgoing_address\).*\(very1\)&\1 $PPP_LOCAL \2&" /etc/squid/squid.conf
fi
##generate ip subnet for route
baseip=`echo "$PPP_LOCAL" | cut -d"." -f1-3`
/usr/sbin/ip route add "$baseip".0/24 dev "$PPP_IFACE" src "$PPP_LOCAL" table "$TABLE"
/usr/sbin/ip route add default via "$PPP_REMOTE" table "$TABLE"
/usr/sbin/ip rule add from "$PPP_LOCAL" table "$TABLE"
/usr/sbin/squid/ -k reconfigure
/usr/bin/systemctl squid restart
exit 0
问题是baseip=echo "$PPP_LOCAL" | cut -d"." -f1-3
无法使用$ PPP_LOCAL
我尝试添加echo $PPP_LOCAL >> file.txt
,但它只是添加了一个空行。
sed代替我访问变量并用新地址正确修改squid.conf文件对我来说很尴尬
我该如何解决?
我还有一个“子问题”,我是一个完全的新手,刚刚开始学习,我不确定是否应该添加ip-down代码来删除表格规则
感谢大家的帮助