Quote:
Originally Posted by kssuhesh
Hello,
Is it possible to set multiple gateway to one linux system, so that I can use one for communicate with multiple private networks (172.16.0.0/24, 172.16.1.0/24) and one for internet ?
|
Yes, it is possible. This is what route is for.
You can have not only multiple gateways, but also multiple devices.
Let us say, you want to access the private networks through gateway X.X.X.X, device ethA, and internet through gateway Y.Y.Y.Y, device ethB.
You may want to delete the default route rule first. By executing
You may find a line like
Code:
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 Z.Z.Z.Z 0.0.0.0 UG 0 0 0 ethC
You can delete it with
Code:
# route del -net 0.0.0.0 netmask 0.0.0.0 dev ethC
Then you just need to add the following routes
Code:
# route add -net 172.16.0.0 netmask 255.255.255.0 gw X.X.X.X dev ethA
# route add -net 172.16.1.0 netmask 255.255.255.0 gw X.X.X.X dev ethA
# route add -net 0.0.0.0 netmask 0.0.0.0 gw Y.Y.Y.Y dev ethB
Remember to replace X/Y/Z and A/B/C according to your real configuration.