martes, 29 de julio de 2014

Bridge con Raspberry Pi



Llevaba tiempo dándole vueltas a configurar la Raspberry Pi en modo bridge para extender la red "casera" y poder usar un tercer punto de acceso sin necesidad de adquirir un nuevo switch.

El pasado mes de mayo @biokeko me regaló una tarjeta 10/100/1000 USB 3.0 y con esta, más el "Pi" y un poco de tiempo robado al fin de semana he conseguido configurar la Raspberry como "puente".

¿Qué es un "bridge"?

Un bridge ethernet es el análogo a un switch ethernet físico. Trabaja a nivel de capa 2 en el modelo OSI y podríamos definirlo como un switch por software que se utiliza para conectar múltiples interfaces ethernet (físicas o virtuales).

¿Cómo instalo el software necesario?

He usado y uso exclusivamente Raspbian. Desde consola y como root:

  • apt-get update
  • apt-get -y install bridge-utils
¿Qué ficheros necesito modificar?

En mi caso particular, tengo 2 interfaces de red : eth0 es la nativa de RaspberryPi y eth1 es la interfaz USB.

Basta con modificar /etc/network/interfaces :

auto lo

iface lo inet loopback

iface eth0 inet manual

iface eth1 inet manual

#Configuración bridge
auto br0
iface br0 inet static
        bridge_ports eth0 eth1
        address 192.168.20.251
        broadcast 192.168.20.255
        netmask 255.255.255.0
        gateway 192.168.20.1



Si reinicias(no es necesario) tu dispositivo tendrás el "puente" activo.

Algunos comandos interesantes:

Mostrar estado del bridge
root@raspberrypi:/home/pi# brctl show
bridge name    bridge id                       STP enabled    interfaces
br0                   8000.0023554c4039    no                     eth0

                                                                                   eth1


Mostrar las "macs" que "ha aprendido" nuestro "bridge"
root@raspberrypi:/home/pi# brctl showmacs br0
port no    mac addr        is local?    ageing timer
  1    00:1a:a0:a3:89:4b    no           6.86
  1    00:1e:c2:16:4c:cf    no           0.01
  2    00:23:55:4c:40:39    yes           0.00
  2    78:d6:f0:26:a8:35    no          37.36
  1    ac:3c:0b:1e:59:86    no           6.25
  1    b8:27:eb:b0:52:bb    yes           0.00
  1    bc:14:01:bb:ae:85    no          15.03
  2    e8:94:f6:93:93:ef    no          15.06




...y el clásico "brctl help"os ayudará con temas como STP o añadir manualmente interfaces al "puente".

Para este ejemplo, el comando ifconfig devuelve

root@raspberrypi:/home/pi# ifconfig
br0     Link encap:Ethernet  HWaddr 00:23:55:4c:40:39 
          inet addr:192.168.20.251  Bcast:192.168.20.255  Mask:255.255.255.0
          inet6 addr: fe80::223:55ff:fe4c:4039/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:16922 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4210 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:14341787 (13.6 MiB)  TX bytes:361541 (353.0 KiB)

eth0      Link encap:Ethernet  HWaddr b8:27:eb:b0:52:bb 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:25168 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11978 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:19662264 (18.7 MiB)  TX bytes:2478027 (2.3 MiB)

eth1      Link encap:Ethernet  HWaddr 00:23:55:4c:40:39 
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7773 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12210 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1917220 (1.8 MiB)  TX bytes:5398632 (5.1 MiB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:17 errors:0 dropped:0 overruns:0 frame:0
          TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:3626 (3.5 KiB)  TX bytes:3626 (3.5 KiB)

BONUS

No hay comentarios: