This is my situation:

Router A: IP Mask - Connected to the internet.

Server: - Interface eth0: inet addr: Mask: (connected to router B) - Interface ra0: inet addr: Mask: (connected to router A)

Router B: IP Mask - Connected to Server's eth0

Computer: connected to Router B via WiFi connection.

I configured a static route on Router B that use as default gateway and i can ping that ip from computer.

The problem is: how i can connect to the internet ? In other words, traffic coming from Server eth0 should use ra0 as gateway.

Any suggestion ?

Thank you

  • is there some reason you need to route through the server? why not connect the routers directly and let them handle routing between the subnets? – quack quixote Dec 24 '09 at 20:41

I believe you need to enable routing on the server (I'm assuming Linux) for it to be route packets not destined for itself. See the information in this article for how to do it.


Echoing the comment from ~quack, why not connect the routers directly and let them handle the routing? Especially if they are NAT routers, then packets have a better chance of flowing, because not only does Computer01 need to know how to reach the Internet, RouterA needs to know how to reach Computer01.

It may be as simple as turning your server into a NAT router, either with Windows's Interface Sharing or with various Linux configurations. And while I'm not opposed to using a server as a router, doing so does put additional load on the server.

  • I couldn't connect the 2 routers because of the distance and because 1 of them are preconfigured router, with not so much customization capabilities. – Dario Dec 29 '09 at 9:41

I found a solution using iptables (just 2 lines):

iptables --table nat --append POSTROUTING --out-interface ra0 -j MASQUERADE
iptables --append FORWARD --in-interface eth0 -j ACCEPT

Thank you all!

  • Does the --append FORWARD line enable packet forwarding on the box? – pcapademic Dec 29 '09 at 21:49

You can bridge the two interfaces on the server.

  1. Install the bridge utilities package.

apt-get install bridge-utils

  1. Create the bridge.

brctl addbr br0

  1. Remove any IP addresses from the Ethernet interfaces.

ifconfig eth0 down

ifconfig eth1 down

  1. Enable STP support if required.

brctl stp bra on

  1. Attach the Ethernet interfaces to the bridge.

brctl addif br0 eth0

brctl addif br0 eth1

  1. Bring the bridge and the Ethernet interfaces up.

ifconfig eth0 up

ifconfig eth1 up

ifconfig br0 up

See link for more details.

  • Please quote the essential parts of the answer from the reference link, as the answer can become invalid if the linked page changes or the target site is unreachable/permanently offline. – DavidPostill Sep 26 '14 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy