3

I have a Linux box with 8 network interfaces:

  • 3 interfaces are connected to 3 different ISPs, one interface is the default gw interface.

  • Use NAT for outgoing packages.

  • Internally, I use the dynamic routing protocol.

When I receive external traffic from a specific interface, I want the outgoing packet to follow and exit the correct interface.

How can I accomplish that?

Dave M
  • 4,494
  • 21
  • 30
  • 30
  • I would like any traffic entering from an external interface to go to the destination from the same interface regardless of what is indicated in the routing table. – Gli Illuminati Jan 07 '20 at 11:56

2 Answers2

1

You can use iptables to do so. The specific command will of course vary on exactly what you want to do, but this answers the broad question as you have it!

LTPCGO
  • 472
  • 1
  • 3
  • 15
1

You can accomplish that using iptables and iproute2. But in a case such as yours, with that amount of network interfaces and OSPF, I would rather invest some money in a network router or gateway appliance for the sake of manageability on the long run.

Here's an article that shows an example of how doing so, although it doesn't contemplate OSPF:

https://www.dicas-l.com.br/arquivo/roteamento_avancado_com_iproute2_e_iptables_no_slackware.php

(It is in Portuguese, but focus on the script)

Basically, you should mark packets when they enter your network in iptables, and route them using that mark using iproute2.

Best regards.

Stefano Martins
  • 1,131
  • 7
  • 10