• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

How to add multiple gateway in /etc/sysconfig/network in Linux ?

kmthien

Senior member
Hi guys,

I got an existing GATEWAY = 192.1.1.1 in my /etc/sysconfig/network. How can I add one more gateway, which is 192.1.1.100 ? Thanks !
 
What are you trying to accomplish here ? Is .100 another NAT device ? This type of setup could really cause a lot of problems. What type of load balancing are you trying to accomplish?
 
192.1.1.1 is the gateway which link back to my main office and 192.1.1.100 is the gateway to link to partner company !
 
192.1.1.1 is the gateway which link back to my main office and 192.1.1.100
They look like they're both on the same subnet (assuming /24), in which case I'll also assume they go out the same interface on your PC. In which case, everything should be taken care of for you upstream.

bart
 
Slighlty oversimplifying, you can't have two "gateways" (default routes). What you need is for a default route to point to one of them, and more-specfic subnet route(s) to point to the other one.

The simple way is to just put 'em in your /etc/rc.local:

route add -net 1.2.3.0 netmask 255.255.255.0 gw 192.1.1.100

will send traffic destined to 1.2.3.0/24 to 192.1.1.100 instead, while everything else goes out the default route to 192.1.1.1.
 
Hi,

U means 1.2.3.0 is my linux server ? After modifying my rc.local, do I need to restart the server or which server to restart ? Thanks

kmthien
 
Do you have 2 routers on your LAN?

one with the port address of 192.1.1.1 and another router with the port labeled 192.1.1.100? and both ports are Attached to your LAN and both routers go to entirely different places???.... (Generally it's the Router port that is the "gateway".)Thats pretty weird...

but read "man route", see if that helps any, but I am not sure what your talking about... So if you can please discribe your LAN in better terms...

It would be alot easier if just had one router that had at least 3 ports, one connected to your LAN one connected to the Office LAN and one to your partner's company.. so that you don't have to configure every computer on your LAN with routing stuff...
 
umm.. I you can do it. It kinda differs for each Distro, which one are you using?

The generic manual way is to do it by hand:


route add -net *.*.*.* netmask 255.*.*.* 192.1.1.100
^ ^
l l ^ and the gateway..
l l
the network you are going too.. l
l
it's netmask

if you don't know the network number and the netmask number for the gateway ask the network people for it... and then you repeat the command for the other gateway

otherwise you can specify this perminately in the /etc/sysconfig/static-routing file in RedHat.. others are a bit different...

in redhat its a bit like this

#interface type destination gw ip-address
eth0 net *.*.*.* gw 192.1.1.100
eth0 net *.*.*.* gw 192.1....

as far as the actual ip address are I don't know your network, so You'll have to ask them.. umm.. and check out your distro's documentation for the specific details on the correct syntax and stuff. If you are lucky you'll have a configuration program like linuxconf that can help you out...
 
cool if you only got one router to worry about then all you should have to do is set the router's port that is connected to your lan as the defualt gw and the router should be able to take care of it all, The proccess should be invisible to any computers on you lan.
 
Hi,

I have entered the following command:

route add -net 61.2.3.190 netmask 255.255.255.0 gw 192.1.1.100

but failed. It returned some instructions on how to use route command.

61.2.3.190 is the ftp server ipadd of my partner company and 192.1.1.100 is the gateway server. My server ipadd is 192.1.1.50, where it links to the router via a switch. 192.1.1.100 is connected to the router directly.

You means my server 192.1.1.50 can't have 2 default gateway ?

Thanks !

 
It can, but it would load balance then. You need this supported in kernel thought:
ip route flush all
ip route add 192.168.0.0/16 dev eth0 proto kernel scope link src $IP
ip route add default nexthop via $G1 dev $DEV1 nexthop via $G2 dev $DEV2
where G1/G2 are gateways and DEV1/DEV2 are devices, in your case DEV1=DEV2 (IP your ip)
OR
you might try using them to access different IPs, dunno what you want to accomplish with to gateways...
 
Back
Top