5

I would like to set up a Raspberry PI as a router between two subnets on the same network using the standard built in ethernet interface.

The aim is to be able to use this to monitor network usage (with tshark) in a network where it isn't possible to physically bridge the external internet connection and the local area network and where ethernet switches are in use so it is not possible to simply monitor all network traffic at any one point. This setup will rely on the cooperation of all users who will have to reassign their machines to the new subnet so that their traffic is routed through the PI.

I recognise that the Raspberry PI with it's USB based ethernet will introduce latency issues and that this isn't not an ideal scenario, but this is small scale experimental and it seems to be the least disruptive way of making this work. However, I'm open to alternative suggestions.

So far:

  • I have successfully installed tshark which works fine.

  • I have successfully set up the device multi-homing by adding an additional iface definition for eth0:0 in /etc/network/interfaces defined with an address on the additional subnet.

  • I have successfully installed brctl (part of the bridge-utils package).

However:

It appears that brctl will only bridge between physical interfaces and doesn't want to know the additional virtual interface eth0:0.

Is there a way of configuring brctl to do this, or is there some alternative way of going about this?

3
  • 1
    I think you are confusing several thinks. First I point you to the OSI Model (en.wikipedia.org/wiki/OSI_model). In networks, bridges are used to connect networks at layer 2 and routing is done at layer 3. In fact, to only monitor network, you don't even need to put the RP in the middle, you just need to configure ethernet port in promiscuous mode. In promiscuous mode the ethernet card will capture all packets and not only the packets for it and you can use tshark ou tcpdump to 'see' whats going on in network. In fact, when you use tcpdump, it put the ethernet in promiscuous mode.
    – Pipe
    Commented Mar 8, 2013 at 19:47
  • Your are more than likely correct about the layer issue. However, in a network with switches the traffic to the Raspberry Pi is limited to those packets addressed to it regardless of promiscuous mode because the switch (rather than hub) isolates the traffic to optimise flow.
    – sroebuck
    Commented Mar 8, 2013 at 21:37
  • There are several solutions depending your network topology. If your switch don not allow port mirroring than Mulaz answer is a simple solution.
    – Pipe
    Commented Mar 9, 2013 at 11:54

1 Answer 1

4

You do not need bridges to do that.

After setting up the interfaces, you have two options:

  • You can set up forwarding directly ("routing"), just by enabling it:

type:

echo 1 > /proc/sys/net/ipv4/ip_forward

(you can do the same for ipv6 if you need it)

You need interfaces and a default gw configured.

You also need to add a route on your upstream routers, for the subnet behind the rPI:

route add -net your.subnet.behind.rPI netmask your.net.mask.there gw rpi.ip.add.ress

e.g:

route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.100

If your rPI has 192.168.1.100 and the network behind it is 192.168.2.0/24

  • If you cannot access the upstream routers, you can set up NAT:

Configure the interfaces, enable ip fowarding, and then enable nat on the upstream interface (eth0 in example):

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
3
  • I've tried the second option (I can't access the upstream routers). I have enabled IP forwarding okay and applied the iptables command (and some variants of it found elsewhere) but it doesn't appear to be passing messages between the subnets. Is there something I need to do to enable nat - other than the iptables command itself? Is there any reasonably straightforward way of debugging what's happening? Many thanks.
    – sroebuck
    Commented Mar 9, 2013 at 13:17
  • Can you ping both subnets from the rPi? Set the rPi as the default gateway on the subnet behind it?
    – mulaz
    Commented Mar 9, 2013 at 14:42
  • Many thanks - I had failed to change the gateway from the original setting.
    – sroebuck
    Commented Mar 11, 2013 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.