Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
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.
I am trying to set up a linux pc at work to learn more about linux networking. It will be plugged into a switch that has 2 routers on it. I'd like to configure my ethernet device (eth0) to have both routers in case one fails Linux will switch to the other router like with my windows box. Can I do this in Suse linux? I tried the below set up and unplugged one router but it didnt seem to switch over to use the second router. I did read one post where it mentioned having multiple default gateways on an interface "is really bad and will drive linux mad". If thats true, I guess I am really lost on how to set something like this up.
A modified ip route show below:
>ip route show
192.168.1.121 dev eth0 scope link
192.168.1.122 dev eth0 scope link
192.168.1.0/24 dev eth0 proto kernerl scope link src 192.168.1.20
127.0.0.0/8 dev lo scope link
default 192.168.1.121 dev eth0 metric 1
default 192.168.1.122 dev eth0 metric 1
That article talks about having multiple NICs though, in my case I just have one NIC device hooked up to a segment with 2 routers where I'd like to try and have both configured to for failover. Does my ip route show look correct or should I delete all of it and enter it in the way that article describes with just one nic though?
So I should make ip route tables for both routers and then set up a default gateway for just the one and it will failover to the 2nd router(route table) when the default gateway goes down?
You can try to add two default route.
Add:
ip route add default scope global nexthop via <GW IP> dev eth0 weight 0 \
nexthop via <GW IP> dev eth0 weight 1
You will never get "failover" works. Why, because, linux needs a criteria to determine somehow that one of your GW went down. Otherwise it will send packets to the fail gw and never switch to second one.
If you really need to route traffic through one main and one reserve/spare, you need to script which will simply replace GW in one default route, if it goes down (ping doesn't return)
Is there a spot to find out about more information on configuring it? It looks like the way i have the network configured to start should be working... Grrr...
i've never tried this but can't you have two default gateways and just set the metric to the backup one to be higher? then if the first one goes down it should use the backup as the first one is no longer there. having only one nic shouldn't be a problem. both default gateways can be on the same network, just obviously different ips. if they are different networks then just make a virutal/alias interface (ifconfig eth0:0 <ip> netmask <netmask>). also this is probably pretty crude but you could run a cron job say every minute or so that pings www.google.com or one of your isp's routers and if it is not responsive changes the default route to the backup default route.
I'm running two ethernet NIC's on an Ubuntu server which has a failover set up. Effectively if one gateway goes down, then it will use the other. Would rather someone confirmed this; my understanding is that it will pass traffic if the mac address is avalible. That is if it can't contact the mac of the primary gateway it will use one of a higher metric. That isn't perfect - there are issues with it. Again, I'd get someone else to confirm this, as I could be getting confused with something else.
Do check my syntax - this is from memory, and be aware this won't last through reloads. Also this isn't "load balancing". Load balancing (network rather than server) I've done before to a degree by using those routes to share traffic. In theory you could do this by:
So all traffic destined for the 200 network would go out the .121 router and all 62 network traffic out of the second .122 router.
and fail over with it:
route add -net 62.0.0.0 netmask 255.0.0.0 gw 192.168.1.121 metric 10
route add -net 200.0.0.0 netmask 255.0.0.0 gw 192.168.1.122 metric 10
Again, I've never done anything like that in the real world. Theoretically should be good. Be interested in how that works out for you. Test it and let us know =) Good luck.
that's a good question jetson21, I'm not sure how it would know. I guess I was thinking about it incorrectly. If you had two seperate NICs then it would know because the one NIC was not up. Your situation is different obviously because you just have one NIC plugged into a switch. The only way I can think of, with out running some kind of routing protocol, is that the machine would have to test the link by doing something like a ping and if this failed, switch over to the other interface. This goes back to my suggestion of setting up a cron job to do this. The only problem with this is that crond checks every minute so you could potentially be without a connection for a minute. I'm not sure if this is acceptiable or not. At any rate your situation is rather unique and ideally the primary link should not go down too often I would imagine so this method may be acceptable.
So I did some more testing. So with both routers up and both configured as default gateways, all traffic flows smoothly. Once I power down Router 1 (first in list). Traffic stops and Linux continually arps trying to find Router 1. Checking ip neigh show, it shows the path as incomplete for Router 1. You'd think that with the state being incomplete Linux would switch to use the back up. I guess I am just somewhat suprised that the Linux stack doesn't seem to handle this kind of environment. Thats why I think maybe I just dont have it configured correctly or maybe I am missing an option or something. If I change the metric values myself after the cable is pulled, Linux changes the order of the default gateways and traffic resumes because it uses Router 2. I believe the windows TCP/IP stack does periodic pings of the gateways and then switches to the alternate.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.