Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We are trying to put together a box with dual LAN cards (let's say Outer and Inner), where the Inner LAN card is supposed to act as a default gateway on the network it is connected to.

This box is running Ubuntu. The basic purpose for this box is to take messages generated on the inner network, do some work with them and forward them out the Outer LAN card to a server. The inner network is completely isolated with simply a regular switch connecting the Inner LAN Card with two other boxes.

These other boxes either throw out multi-cast messages (which the Inner LAN Card is listening to), or send out unicast messages meant for the server which is not on this inner network. So, we need the Inner LAN Card to act as a default gateway, where these unicast messages will then be sent, and the code on the dual-LAN Card box can then intercept and forward these messages to the server.

Question: 1. How do we setup the LAN Card to be default gateway (does it need some configuration on Ubuntu)? 2. Once we have this setup, is it a simple matter of listening to the interface to intercept the incoming messages?

Any help (pointers in the right direction) is appreciated.

Thanks.

share|improve this question

1 Answer 1

You don't need to any special configuration on the NIC to make it the default gateway. You just need to configure the machines in the inner LAN to use this NIC IP as their default gateway.

To route the packets between the two subnets, you need to enable IPv4 forwarding using:

# echo 1 > /proc/sys/net/ipv4/ip_forward     (as root)

To make it permanent, edit the file /etc/sysctl.conf and uncomment the line:

net.ipv4.ip_forward=1

For packet interception, you can write a program in C/C++. You can use libpcap to get the traffic that reaches your inner NIC and do whatever processing you need to do. I can't provide more details because I don't know the type of processing you want to do.

share|improve this answer
    
This is perfect. Here are some more comments. I am guessing that I don't have to do the IPv4 forwarding since I don't want the packets to be forwarded as is (or maybe I do, not sure yet). For processing, we are writing the code in Python. This code is already working with the Multi-cast messages. Quick question: if i don't do anything special to make it a default gateway, won't the Inner network card simply drop the packets sent to it (but not meant for it). –  Vaibhav Dec 28 '10 at 7:52
1  
This is the rule. If the host is not configured as a router (enabled IP forwarding), the NIC will drop the packets it receives if they are not destined to it. –  Khaled Dec 28 '10 at 8:09
1  
If you will forward the packets yourself using your application, you don't need to enable IP forwarding. You just create two sockets: one is receiving from inner NIC, and the other sending via outer NIC. –  Khaled Dec 28 '10 at 8:48
1  
Yes, the system will not see those packets. You will catch them yourself in your application. –  Khaled Dec 28 '10 at 10:22
1  
Vaibhav, if you want to process it yourself in userspace, then you can do as Khaled suggested, the two sockets. You can use a RAW socket, see packet(7), socket(2), which will get the packets at layer 2 itself. –  radical Dec 28 '10 at 10:30

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.