mirror of
https://github.com/thelittlerocket/pve.git
synced 2025-02-24 13:56:34 +08:00
Update build_nat_network.sh
This commit is contained in:
parent
c7de6aafab
commit
0b480490b6
1 changed files with 25 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
#!/bin/bash
|
||||
# from
|
||||
# https://github.com/spiritLHLS/pve
|
||||
# 2023.08.17
|
||||
# 2023.08.20
|
||||
|
||||
|
||||
########## 预设部分输出和部分中间变量
|
||||
|
@ -199,11 +199,34 @@ else
|
|||
fi
|
||||
${sysctl_path} -p
|
||||
|
||||
# 删除可能存在的原有的网卡配置
|
||||
cp /etc/network/interfaces /etc/network/interfaces_nat.bak
|
||||
chattr -i /etc/network/interfaces
|
||||
input_file="/etc/network/interfaces"
|
||||
output_file="/etc/network/interfaces.tmp"
|
||||
start_pattern="iface lo inet loopback"
|
||||
end_pattern="auto vmbr0"
|
||||
delete_lines=0
|
||||
while IFS= read -r line; do
|
||||
if [[ $line == *"$start_pattern"* ]]; then
|
||||
delete_lines=1
|
||||
fi
|
||||
if [ $delete_lines -eq 0 ]; then
|
||||
echo "$line" >> "$output_file"
|
||||
fi
|
||||
if [[ $line == *"$end_pattern"* ]]; then
|
||||
delete_lines=0
|
||||
fi
|
||||
done < "$input_file"
|
||||
mv "$output_file" "$input_file"
|
||||
chattr +i /etc/network/interfaces
|
||||
|
||||
# 重启配置
|
||||
service networking restart
|
||||
systemctl restart networking.service
|
||||
sleep 3
|
||||
ifreload -ad
|
||||
iptables-save | awk '{if($1=="COMMIT"){delete x}}$1=="-A"?!x[$0]++:1' | iptables-restore
|
||||
# 已加载网络,删除对应缓存文件
|
||||
if [ -f "/etc/network/interfaces.new" ];then
|
||||
chattr -i /etc/network/interfaces.new
|
||||
|
@ -217,4 +240,4 @@ _green "you can test open a virtual machine or container to see if the actual ne
|
|||
# _green "虽然已自动设置网关,但不确定是否已成功应用,请查看PVE中的 Datacenter-->pve-->System-->Network"
|
||||
# _green "如果 vmbr0 和 vmbr1 已正常显示且 Apply Configuration 这个按钮是灰色的,则不用执行 reboot 重启系统"
|
||||
# _green "上述情形如果有不同的,请点击 Apply Configuration 这个按钮,等待几分钟后重启系统,确保网关已成功应用"
|
||||
_green "你可以测试开一个虚拟机或者容器看看就知道是不是实际网络已应用成功了"
|
||||
_green "你可以测试开一个虚拟机或者容器看看就知道是不是实际网络已应用成功了"
|
||||
|
|
Loading…
Reference in a new issue