Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-06-2016, 07:15 AM   #1
LQ Newbie
Registered: Jan 2016
Posts: 2

Rep: Reputation: Disabled
Question 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: gateway:
Eth1: gateway:

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

any body please help?

many thanks in advance

Old 01-06-2016, 09:36 AM   #2
Ser Olmy
Senior Member
Registered: Jan 2012
Distribution: Slackware
Posts: 2,543

Rep: Reputation: Disabled
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?
Old 01-06-2016, 04:46 PM   #3
Doug G
Registered: Jul 2013
Posts: 749

Rep: Reputation: Disabled
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:
Old 01-06-2016, 05:07 PM   #4
LQ Newbie
Registered: Jan 2016
Posts: 2

Original Poster
Rep: Reputation: Disabled
Dear All,

noted with thanks..



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 default gateway for 2 NICs each 5883 Linux - Networking 9 01-17-2012 07:23 AM
[SOLVED] Squid with 2 NICs... set gateway vonedaddy Linux - Server 7 11-11-2010 01:48 AM
Linux Gateway with 3 NICs pin_bk Linux - Networking 16 03-27-2005 09:57 AM
can't get nics working, on gateway evilchild Slackware 3 03-28-2004 07:18 PM
How do I connect dual nics in firewall to the gateway? scoobadiver Linux - Newbie 3 01-12-2004 05:03 PM > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration