LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux network architecture - local network vs. LAN network rule (https://www.linuxquestions.org/questions/linux-newbie-8/linux-network-architecture-local-network-vs-lan-network-rule-4175593819/)

LnxNewUser 11-18-2016 03:57 PM

Linux network architecture - local network vs. LAN network rule
 
Hello,

I have a question linked to the local delivery of packets for Linux Kernel. My question is linked to network features.

I've two ethernet interfaces (eth0 and eth1), I want to send a packet from eth0 to eth1 and force it to be routed on the LAN network by a router or another computer. (as shown below)
On the computer 2, I've launched wireshark and a simple C program which listen on a UDP port and redirect the UDP message to another Ip address (simple ip redirection)

Code:

    +++++++++++
    +  =====  +              Msg  +++++++++++
    +  Eth0 -------------------->----        +
    +  =====  +                    + |      +
    +        +                    + |      +
    +  =====  +                    + |      +
    +  Eth1 --------------------<----        +
    +  =====  +    LAN Network    +++++++++++
    +++++++++++                    Computer 2
    Computer 1

According to my understanding, when the linux kernel sees that the packet sended by eth0 is destinated to eth1. The packet is routed through the local network and not on the LAN network.

Is it possible to force the Linux Kernel to send it on the "outside" network? If yes, how can I do it?

After reading Linux network architecture articles on google, I've thought to modify the ip_rcv / ip_route_input functions in order to force it to go on the LAN Network.

Thanks for your help.

cliffordw 11-19-2016 01:34 AM

Hi, and welcome!

Yes, you're correct: the kernel normally routes such packets internally, without sending them out on the wire.

I believe you can change this with some setting changes and appropriate routing, though.

First, let's look at routing. You have to force the traffic out of the system. Let's assume eth0 has IP address 192.168.1.1, and eth1 has IP 192.168.1.2. Fix the routing with:

Code:

route add -host 192.168.1.2 dev eth0
route add -host 192.168.1.1 dev eth1

You also need to tell the kernel to allow this traffic, and not drop it as "martian source" traffic, with:

Code:

sysctl -w net.ipv4.conf.eth0.accept_local=1
sysctl -w net.ipv4.conf.eth1.accept_local=1
sysctl -w net.ipv4.conf.all.rp_filter=2

I think that should do the trick, although I don't have a system where I can test that right now.

References:

- https://www.kernel.org/doc/Documenta.../ip-sysctl.txt
- https://stackoverflow.com/questions/...al-doesnt-work

Good luck!

LnxNewUser 11-19-2016 03:49 AM

Thanks a lot for your reply and the references.
I'll check it and let you know if it's work or not.


All times are GMT -5. The time now is 09:03 AM.