使用脚本设置时桥接工作出现问题

使用脚本设置时桥接工作出现问题

我正在尝试建立一座桥,本质上是将我的机器变成一个交换机。

INTERFACES='br0'我在与接口设置相同的计算机上运行 dhcp 服务器。

/etc/network/interfaces看起来像这样:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet manual
auto eth1
iface eth1 inet manual
auto wlan0
iface wlan0 inet manual

auto br0
iface br0 inet static
    bridge_ports eth0 eth1 wlan0
    address 10.1.36.10
    netmask 255.255.255.0
    network 10.1.36.0
    broadcast 10.1.36.255

当我手动配置时,一切正常。

然后我编写了一个 bash 脚本来进行设置,因为我需要以相同的方式配置许多机器:

echo "Setting up Static IP..."
if [ $(ifconfig -a | sed 's/[ \t].*//;/^\(lo\|\)$/d' | wc -l) -gt 1 ]
then
   BRIDGE_PORTS=""
   for i in $(ifconfig -a | sed 's/[ \t].*//;/^\(lo\|\)$/d'); do
       sudo echo "auto $i" | sudo tee -a  /etc/network/interfaces
       sudo echo "iface $i inet manual" | sudo tee -a  /etc/network/interfaces
       BRIDGE_PORTS="$BRIDGE_PORTS $i "
   done
   sudo echo "auto br0" | sudo tee -a  /etc/network/interfaces
   sudo echo "iface br0 inet static" | sudo tee -a  /etc/network/interfaces
   sudo echo "bridge_ports $BRIDGE_PORTS" | sudo tee -a  /etc/network/interfaces
   sudo echo "address $STATIC_IP" | sudo tee -a  /etc/network/interfaces
   sudo echo "netmask 255.255.255.0" | sudo tee -a  /etc/network/interfaces
   sudo echo "network $NETWORK_IP" | sudo tee -a  /etc/network/interfaces
   sudo echo "broadcast $BROADCAST_IP" | sudo tee -a  /etc/network/interfaces
   DHCP_INTERFACE="br0"
else
   sudo echo "auto eth0" | sudo tee -a  /etc/network/interfaces
   sudo echo "iface eth0 inet static" | sudo tee -a  /etc/network/interfaces
   sudo echo "address $STATIC_IP" | sudo tee -a  /etc/network/interfaces
   sudo echo "netmask 255.255.255.0" | sudo tee -a  /etc/network/interfaces
   sudo echo "network $NETWORK_IP" | sudo tee -a  /etc/network/interfaces
   sudo echo "broadcast $BROADCAST_IP" | sudo tee -a  /etc/network/interfaces
   DHCP_INTERFACE="eth0"
fi

我不知道为什么,但当我使用脚本设置桥接器时,它不包括 eth0 或 eth1 接口。

当我跑步时ip addr我得到这个:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
   valid_lft forever preferred_lft forever
inet6 ::1/128 scope host 
   valid_lft forever preferred_lft forever
2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default      qlen 1000
link/ether 78:d0:04:20:b9:6c brd ff:ff:ff:ff:ff:ff
3: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
link/ether 78:d0:04:20:b9:6d brd ff:ff:ff:ff:ff:ff
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
link/ether c4:d9:87:8e:72:f9 brd ff:ff:ff:ff:ff:ff
inet6 fe80::c6d9:87ff:fe8e:72f9/64 scope link 
   valid_lft forever preferred_lft forever
5: mon.wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UNKNOWN group default qlen 1000
link/ieee802.11/radiotap c4:d9:87:8e:72:f9 brd ff:ff:ff:ff:ff:ff
6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
link/ether c4:d9:87:8e:72:f9 brd ff:ff:ff:ff:ff:ff
inet 10.1.36.10/24 brd 10.1.36.255 scope global br0
   valid_lft forever preferred_lft forever
inet6 fe80::c6d9:87ff:fe8e:72f9/64 scope link 
   valid_lft forever preferred_lft forever

eth0和eth1没有br0作为它们的master!这是为什么?

相关内容