Estou tentando configurar uma ponte, basicamente transformando minha máquina em um comutador.
Estou executando um servidor dhcp na mesma máquina com INTERFACES='br0'
como configuração de interface.
/etc/network/interfaces
é assim:
# 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
Quando configurei isso manualmente, tudo funcionou bem.
Escrevi então um script bash para configurar isso, já que preciso configurar várias máquinas da mesma maneira:
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
Eu não sei por que, mas a bridge não inclui as interfaces eth0 ou eth1 quando configuro com o script.
Quando executo ip addr
, obtenho isto:
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
A eth0 e eth1 não têm br0 como seu mestre! Por que isso?