2023-02-23 21:42:24 +08:00
|
|
|
|
#!/bin/bash
|
2023-02-23 21:58:44 +08:00
|
|
|
|
# 该脚本将创建一个名为vmbr0的虚拟网桥,并将其记录到配置文件中。它会自动获取本地IPV4地址、子网掩码和网关,并将其添加到vmbr0配置中。
|
2023-02-23 21:42:24 +08:00
|
|
|
|
|
|
|
|
|
# 设置虚拟网桥名称
|
|
|
|
|
BRIDGE_NAME="vmbr0"
|
|
|
|
|
|
2023-02-23 22:26:30 +08:00
|
|
|
|
# 获取本地 IPv4地址 子网掩码 网关地址
|
2023-02-23 21:42:24 +08:00
|
|
|
|
IP_ADDR=$(ip route get 8.8.8.8 | head -1 | awk '{print $7}')
|
2023-02-23 22:27:55 +08:00
|
|
|
|
SUBNET_MASK="255.255.255.0"
|
2023-02-23 21:42:24 +08:00
|
|
|
|
GATEWAY=$(ip route | awk '/default/ {print $3}')
|
|
|
|
|
|
2023-02-23 22:03:19 +08:00
|
|
|
|
# 创建虚拟网桥
|
|
|
|
|
cat << EOF > /etc/network/interfaces.d/$BRIDGE_NAME.conf
|
|
|
|
|
# This file is generated by create_vmbr0.sh script
|
|
|
|
|
auto $BRIDGE_NAME
|
|
|
|
|
iface $BRIDGE_NAME inet static
|
|
|
|
|
address $IP_ADDR
|
|
|
|
|
netmask $SUBNET_MASK
|
|
|
|
|
gateway $GATEWAY
|
2023-02-23 22:25:13 +08:00
|
|
|
|
bridge_ports ens18
|
2023-02-23 22:03:19 +08:00
|
|
|
|
bridge_vlan_aware 1
|
|
|
|
|
vlan_ids 100
|
|
|
|
|
EOF
|
2023-02-23 21:58:44 +08:00
|
|
|
|
|
2023-02-23 22:03:19 +08:00
|
|
|
|
# 重启网络服务以应用更改
|
|
|
|
|
systemctl restart networking.service
|