Linux Packet Forwarding

Posted on 2008-11-06
Last Modified: 2010-04-21
Can linux forward packets back through the same interface they came?  If so, how can this be accomplished with routes?  Thanks.
Question by:MainStaySolutions
    LVL 2

    Accepted Solution

    May be helpfull to get at least part of topology, but generally said, it is possible to route thru the same interface. If we do have two networks directly connected:
    route add -net xx.xx.xx.0 netmask y.y.y.0 dev eth0
    route add -net aa.aa.aa.0 netmask b.b.b.0 dev eth0

    If there's gateway to one of the networks on the way, use
    route add -net xx.xx.xx.0 netmask y.y.y.0 gw zz.zz.zz.zz

    Don't forget to switch on packet forwarding
    echo "1" > /proc/sys/net/ipv4/ip_forward
    LVL 43

    Assisted Solution

    Yes it can, use normal routing rules.
    But mind, that if the connection gets SNATed or DNATed on the router as well - both actions are required SNAT and DNAT.
    LVL 43

    Expert Comment

    Oh, one more thing, linux by default does not route such packets, but sends redirect to the sending device (so it knows there shorter path). To disable this
    for f in /proc/sys/net/ipv4/conf/*/send_redirects; do echo 0 > $f; done

    Author Closing Comment

    Thank you for the quick response.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Hello EE, Today we will learn how to send all your network traffic through Tor which is useful to get around censorship and being tracked all together to a certain degree. This article assumes you will be using Linux, have a minimal knowledge of …
    BIND is the most widely used Name Server. A Name Server is the one that translates a site name to it's IP address. There is a new bug in BIND (, affecting all versions of BIND 9 from BIND 9.1.0 (inclusive) thro…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now