LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 11-22-2020, 08:25 AM   #1
JamesGT
Member
 
Registered: Oct 2009
Location: St. Louis, MO, USA
Distribution: Slackware64 Live
Posts: 300

Rep: Reputation: 51
Two Networks, Two NICs, Two Gateways...howto?


I have a server that has 2 network cards connected to two different networks.

I've configured rc.inet1.conf to have eth0 on a private network, and eth1 to be on a public network.

There is only one line "Default Gateway IP Address". Each network card has it's own gateway however.

How do I configure each card for each network?

I tried just adding lines to each card eth0 and eth1 as :

GATEWAY[0]="X.X.X.X" and GATEWAY[1]="1.1.1.1" but that doesn't seem to work.

If I change the default gateway line to the gateway IP for the public network, the public network works, but private does not.

If I change the default gateway line to the gateway IP for the private network, the public network does not work, but the private does.

How do you set up separate gateways for each network?

James
 
Old 11-22-2020, 08:36 AM   #2
tadgy
Member
 
Registered: May 2018
Location: UK
Distribution: Slackware (servers), Void (desktop/laptop)
Posts: 306

Rep: Reputation: 417Reputation: 417Reputation: 417Reputation: 417Reputation: 417
You can only have one default gateway on your system, even if it is connected to multiple networks.

When your networking is set up, aside from a default gateway (assuming you have one configured), each network gets a route added for it. It's those routes which configure how your host sends packets destined for each network - packets for your private network on one interfaces, and public on another.

The default gateway is used when your host needs to send packets to a network it doesn't know about.. eg, the internet.

If you have two routes out to the internet, you can only have one of them as your default. You'll need to use routes to determine which gateway is used for accessing different networks.

HTH.
 
1 members found this post helpful.
Old 11-22-2020, 09:38 AM   #3
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,347

Rep: Reputation: Disabled
Quote:
Originally Posted by JamesGT View Post
How do you set up separate gateways for each network?
That's called routing.

A Default Gateway, also known as "a gateway of last resort", is just the most general route possible, covering every IP network in existence. Adding two such routes pointing to different gateways will result in round-robin load balancing at the packet level, which is not what you want.

However, specific routes always take precedence over more general routes. What you need to do for this to work, is to add a more specific route to your private network via the other gateway (router). You do this using the ip route add command (or route add on older systems).

For instance, if the network 192.168.10.0/24 can be reached via gateway 192.168.1.2, the command would look like this: ip route add 192.168.10.0/24 via 192.168.1.2

Such static routes (as they are called) become part of the kernel routing table and take effect immediately, but as with other IP parameters they are lost at reboot. Slackware doesn't have an init script for storing static routes, but you could always add the relevant command(s) to /etc/rc.d/rc.local.
 
Old 11-22-2020, 09:39 AM   #4
Chuck56
Member
 
Registered: Dec 2006
Location: Colorado, USA
Distribution: Slackware
Posts: 930

Rep: Reputation: 479Reputation: 479Reputation: 479Reputation: 479Reputation: 479
add a private route on eth1, the nic connected to the public network.

if the private network is 10.10.10.0 with a /24 subnet (mask 255.255.255.0) then

to add the route:
Code:
ip route add 10.10.10.0/24 dev eth1
to remove the route:
Code:
ip route del 10.10.10.0/24 dev eth1
Have fun!
 
Old 11-22-2020, 03:34 PM   #5
slacktroll
Member
 
Registered: May 2011
Distribution: Slackware64/current
Posts: 175

Rep: Reputation: 45
I've played around with this earlier some years ago, it's possible to use multiple default gateways with different metrics.
I can't really remember how it's done but it's possible. Your program has to bind to the source ip address when doing certain things.. :-)

It might be right to look into source routing, which probably will get you there.
 
Old 11-23-2020, 02:36 AM   #6
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,347

Rep: Reputation: Disabled
Quote:
Originally Posted by slacktroll View Post
I've played around with this earlier some years ago, it's possible to use multiple default gateways with different metrics.
Nope, the gateway with the lowest metric will always be used.
Quote:
Originally Posted by slacktroll View Post
I can't really remember how it's done but it's possible. Your program has to bind to the source ip address when doing certain things.. :-)
You might be thinking of policy routing, but that's not what the OP needs/wants.
Quote:
Originally Posted by slacktroll View Post
It might be right to look into source routing, which probably will get you there.
That's another thing entirely, and also not what the OP is looking for.
 
Old 11-24-2020, 09:40 AM   #7
slacktroll
Member
 
Registered: May 2011
Distribution: Slackware64/current
Posts: 175

Rep: Reputation: 45
Yeah you're right about the metrics.
Was digging and found this...

Perhaps something else..

Code:
interface=eth1
mtu=1500
ipadress=10.0.0.8
netmask=255.255.255.0
ifconfig_broadcast=10.0.0.255
netname=10.0.0.0
othergateway=10.0.0.1
nametable=othergatway

echo "1 $nametable" >> /etc/iproute2/rt_tables
/sbin/ip link set dev $interface up mtu $mtu
/sbin/ip addr add dev $interface $ipadress/$netmask broadcast $ifconfig_broadcast
/sbin/ip route add $netname/$netmask dev $interface src $ipadress table $nametable
/sbin/ip route add default via $othergateway dev $interface table $nametable
/sbin/ip rule add from $ipadress/32 table $nametable
/sbin/ip rule add to $ipadress/32 table $nametable

Last edited by slacktroll; 11-24-2020 at 10:10 AM.
 
  


Reply



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
[SOLVED] Two gateways, lack of connectivity to some of local networks. horizn Linux - Networking 0 02-28-2018 02:47 PM
two seperate networks - two gateways no routing [Centos 4.7] jon_the_eye Linux - Networking 5 07-07-2010 04:32 AM
Two NICS one web server and Two Gateways walk into a bar... dr_rockstar66 Linux - Networking 2 02-23-2005 04:23 PM
2 NICs 2 networks 2 gateways birkinshawc Linux - Networking 1 05-29-2004 03:05 PM
Howto set up 2 different gateways for 2 different nics kemplej Slackware 1 05-18-2004 11:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 08:33 AM.

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