嗯, 本猫的脚本有多烂大大们都知道的, 所以本文旨在抛砖引玉, 简单介绍利用 pppd hook 和 dhcpcd hook 做到记忆网关, 以及 bash_completion 补全的实现.
保存用的脚本:
/usr/local/bin/froute-save
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#!/bin/bash interface=${interface:-$1} gateway=${new_routers:-$5} if [ "$reason" = 'BOUND' ] && ! ([ -z "$interface" ] || [ -z "$gateway" ]) then mkdir -p /tmp/froute/ chmod 755 /tmp/froute echo $gateway > /tmp/froute/$interface chmod 644 /tmp/froute/$interface elif ([ "$reason" = 'STOP' ] || [ "$reason" = 'RELEASE' ]) && ! [ -z "$interface " ] then rm -f /tmp/froute/$interface fi |
嗯..然后首先是pppd的hook, 代码如下:
/etc/ppp/ip-up.d/02-route.sh
1 |
reason=BOUND froute-save $1 0 0 0 $5 |
/etc/ppp/ip-down.d/02-route.sh
1 |
reason=RELEASE froute-save $1 |
然后是dhcpcd的hook.
/etc/dhcpcd.enter-hook
1 |
froute-save |
如果有用 netcfg 设置静态地址连接, 可以参考如下配置:
1 2 |
POST_UP="env reason=BOUND froute-save $INTERFACE 0 0 0 $GATEWAY || true" PRE_DOWN="env reason=RELEASE froute-save $INTERFACE || true" |
嗯, 现在记忆网关的部分就完成了 >< Continue reading 简易的默认网关保存+Bash补全解决方案 For Arch Linux