Update network.sh

This commit is contained in:
spiritLHLS 2023-02-23 21:58:44 +08:00 committed by GitHub
parent beaf942335
commit fb8610e526
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# 该脚本将创建一个名为vmbr0的虚拟网桥并将其记录到PVE配置中。它会自动获取本地IPV4地址、子网掩码和网关并将其添加到vmbr0配置中。 # 该脚本将创建一个名为vmbr0的虚拟网桥并将其记录到配置文件中。它会自动获取本地IPV4地址、子网掩码和网关并将其添加到vmbr0配置中。
# 设置虚拟网桥名称 # 设置虚拟网桥名称
BRIDGE_NAME="vmbr0" BRIDGE_NAME="vmbr0"
@ -20,15 +20,16 @@ NET_ADDR=${NET_ADDR::-1}
# 获取网关地址 # 获取网关地址
GATEWAY=$(ip route | awk '/default/ {print $3}') GATEWAY=$(ip route | awk '/default/ {print $3}')
# 创建虚拟网桥并将其记录到PVE配置中 # 创建虚拟网桥的配置文件
pvesh set /nodes/localhost/network/$BRIDGE_NAME \ echo "# This file is generated by create_vmbr0.sh script" > /tmp/$BRIDGE_NAME.conf
-content-type "application/json" \ echo "auto $BRIDGE_NAME" >> /tmp/$BRIDGE_NAME.conf
-put \ echo "iface $BRIDGE_NAME inet static" >> /tmp/$BRIDGE_NAME.conf
-data \ echo " address $IP_ADDR" >> /tmp/$BRIDGE_NAME.conf
'{ echo " netmask $SUBNET_MASK" >> /tmp/$BRIDGE_NAME.conf
"bridge_ports": "none", echo " gateway $GATEWAY" >> /tmp/$BRIDGE_NAME.conf
"bridge_vlan_aware": "1", echo " bridge_ports none" >> /tmp/$BRIDGE_NAME.conf
"vlan_ids": "100", echo " bridge_vlan_aware 1" >> /tmp/$BRIDGE_NAME.conf
"addresses": "'"$IP_ADDR/$SUBNET_MASK"'", echo " vlan_ids 100" >> /tmp/$BRIDGE_NAME.conf
"gateway": "'"$GATEWAY"'"
}' # 将配置文件移动到网络接口配置目录
mv /tmp/$BRIDGE_NAME.conf /etc/network/interfaces.d/$BRIDGE_NAME.conf