SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.