LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   2 NICs with different gateway (https://www.linuxquestions.org/questions/linux-newbie-8/2-nics-with-different-gateway-4175563202/)

teddy.phg 01-06-2016 07:15 AM

2 NICs with different gateway
 
Dear All,

I am running centOS 5.6 with 2 NICs,

I need to set gateway for each NIC..

Eth0: 10.100.100.1 gateway: 10.100.100.101
Eth1: 10.100.100.2 gateway: 10.100.100.102

so packages come from Eth0 will be routed to 10.100.100.101
so does packages come from Eth1 will be routed to 10.100.100.2

any body please help?

many thanks in advance

Teddy

Ser Olmy 01-06-2016 09:36 AM

That's not how routing works. NICs don't have gateways; routing tables do, and you usually have exactly one of those.

I don't blame you for thinking gateways are somehow tied to NICs, though, because that's how many configuration tools present the parameters. But if you specify two "default gateways" (note how it doesn't really make sense to talk about having more than one "default" of anything), you end up with either:
  • a system that uses one gateway and simply ignores the other, which is no help at all, or
  • a system that tries to round-robin load balance across the gateways, which usually won't work.
For outbound traffic on a multihomed system (one with more than one NIC) from a process that isn't bound to a specific IP address, the gateway is selected first, based on the information in the routing table. Then a source address is chosen, based on which NIC the packet has to go through in order to reach that gateway.

It is possible to bind a process to a specific IP, but that won't actually affect the choice of gateway. To do that, you need to implement what is known as "policy routing", where you have more than one routing table using different gateways, and traffic is routed using the various tables based on some specific criteria, like the source address.

Does that sound like what you want to accomplish?

Doug G 01-06-2016 04:46 PM

You can set up custom routing tables using iproute2 and give each nic a different default gateway. I've done so on CentOS 6, but only with the two nics on two different subnets.

I followed a process similar to the one described here: https://www.thomas-krenn.com/en/wiki..._on_One_System

teddy.phg 01-06-2016 05:07 PM

Dear All,

noted with thanks..

Regards
Tedd


All times are GMT -5. The time now is 11:50 PM.