Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

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?

share|improve this question
    
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 Mar 8 '13 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 Mar 8 '13 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 Mar 9 '13 at 11:54

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer
    
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 Mar 9 '13 at 13:17
    
Can you ping both subnets from the rPi? Set the rPi as the default gateway on the subnet behind it? –  mulaz Mar 9 '13 at 14:42
    
Many thanks - I had failed to change the gateway from the original setting. –  sroebuck Mar 11 '13 at 12:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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