debian 9: 修复 ifupdown 不支持静态 ipv6 onlink 网关

This commit is contained in:
bin456789 2025-02-06 18:47:21 +08:00
parent 24b6e7f922
commit 7b777df830
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B
3 changed files with 26 additions and 0 deletions

View File

@ -134,6 +134,8 @@ fix_network_manager() {
done done
} }
# debian 9 IPV6 onlink 路由需要 post-up
# auto lo # auto lo
# iface lo inet loopback # iface lo inet loopback
@ -147,6 +149,8 @@ fix_network_manager() {
# iface eth0 inet6 static # iface eth0 inet6 static
# address 2602:1:0:80::100/64 # address 2602:1:0:80::100/64
# gateway 2602:1:0:80::1 # gateway 2602:1:0:80::1
# post-up ip route add 2602:1:0:80::1 dev eth0
# post-up ip route add default via 2602:1:0:80::1 dev eth0
# dns-nameserver 2606:4700:4700::1111 # dns-nameserver 2606:4700:4700::1111
# dns-nameserver 2001:4860:4860::8888 # dns-nameserver 2001:4860:4860::8888
@ -171,6 +175,11 @@ fix_ifupdown() {
if [ -n "$ethx" ]; then if [ -n "$ethx" ]; then
line=$(echo "$line" | awk "{\$2=\"$ethx\"; print \$0}") line=$(echo "$line" | awk "{\$2=\"$ethx\"; print \$0}")
fi fi
elif [[ "$line" = *" dev e"* ]]; then
if [ -n "$ethx" ]; then
# awk 会去除前面的空格
line=$(echo "$line" | sed -E "s/[^ ]*$/$ethx/")
fi
fi fi
if ! $del_this_line; then if ! $del_this_line; then
echo "$line" >>"$tmp_file" echo "$line" >>"$tmp_file"

View File

@ -3113,8 +3113,10 @@ EOF
# hack 3 # hack 3
# 修改 trans.sh # 修改 trans.sh
# 1. 直接调用 create_ifupdown_config # 1. 直接调用 create_ifupdown_config
# shellcheck disable=SC2154
insert_into_file $initrd_dir/trans.sh after '^: main' <<EOF insert_into_file $initrd_dir/trans.sh after '^: main' <<EOF
distro=$nextos_distro distro=$nextos_distro
releasever=$nextos_releasever
create_ifupdown_config /etc/network/interfaces create_ifupdown_config /etc/network/interfaces
exit exit
EOF EOF

View File

@ -955,6 +955,21 @@ iface $ethx inet6 static
address $ipv6_addr address $ipv6_addr
gateway $ipv6_gateway gateway $ipv6_gateway
EOF EOF
# debian 9
# ipv4 支持静态 onlink 网关
# ipv6 不支持静态 onlink 网关,需使用 post-up 添加,未测试动态
# ipv6 也不支持直接 ip route add default via xxx onlink
if [ "$distro" = debian ] && [ "$releasever" -le 9 ]; then
# debian 添加 gateway 失败时不会执行 post-up
# 因此 gateway post-up 只能二选一
# 注释最后一行,也就是 gateway
sed -Ei '$s/^( *)/\1# /' "$conf_file"
cat <<EOF >>$conf_file
post-up ip route add $ipv6_gateway dev $ethx
post-up ip route add default via $ipv6_gateway dev $ethx
EOF
fi
fi fi
# dns # dns