LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-26-2010, 03:08 PM   #1
jetson21
LQ Newbie
 
Registered: Feb 2010
Posts: 10

Rep: Reputation: 0
Gateway/Router failover


Hi all,

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

Last edited by jetson21; 03-26-2010 at 03:09 PM.
 
Old 03-26-2010, 03:48 PM   #2
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
No, no, no. Linux likes it. Linux doesn't like to be a blow-up doll.
Take a look with article: http://lartc.org/howto/lartc.rpdb.mu...ks.html#AEN298

You can also search this forum for expression "Load balancing".

Last edited by nimnull22; 03-26-2010 at 04:14 PM.
 
Old 03-29-2010, 09:11 AM   #3
jetson21
LQ Newbie
 
Registered: Feb 2010
Posts: 10

Original Poster
Rep: Reputation: 0
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?
 
Old 03-29-2010, 09:24 AM   #4
al_bye
LQ Newbie
 
Registered: Mar 2010
Distribution: Ubuntu 9.10, Ubuntu Netbook-Remix
Posts: 26

Rep: Reputation: 17
The below thread is taken from a UBUNTU site. Creating a virtual NIC is the way forward sorry I don't know your distro.

http://adventuresinswitching.blogspo...on-ubuntu.html
 
Old 03-29-2010, 10:33 AM   #5
jetson21
LQ Newbie
 
Registered: Feb 2010
Posts: 10

Original Poster
Rep: Reputation: 0
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?

Last edited by jetson21; 03-29-2010 at 10:44 AM.
 
Old 03-29-2010, 11:37 AM   #6
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
You want to say that in your LAN there is two GW.

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

I hope it will work

Last edited by nimnull22; 03-29-2010 at 11:59 AM.
 
Old 03-29-2010, 01:06 PM   #7
jetson21
LQ Newbie
 
Registered: Feb 2010
Posts: 10

Original Poster
Rep: Reputation: 0
so this will basically replace the default gateways?

Last edited by jetson21; 03-29-2010 at 01:07 PM.
 
Old 03-29-2010, 01:41 PM   #8
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Yes, you need to replace ONE default gateway with two.
And rule for kernel how to choose them.

Try, you can alway restore previous configuration - reboot.
 
Old 03-29-2010, 02:41 PM   #9
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
You know what I think about your idea.

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)
 
Old 03-30-2010, 09:04 AM   #10
jetson21
LQ Newbie
 
Registered: Feb 2010
Posts: 10

Original Poster
Rep: Reputation: 0
I dunno it seems linux does detect first level router failover.

http://mailman.ds9a.nl/pipermail/lar...q4/021821.html

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...

Last edited by jetson21; 03-30-2010 at 10:01 AM.
 
Old 03-30-2010, 03:13 PM   #11
fancylad
Member
 
Registered: Mar 2008
Distribution: slackware
Posts: 175

Rep: Reputation: 19
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.

Last edited by fancylad; 03-30-2010 at 03:15 PM.
 
Old 03-30-2010, 06:15 PM   #12
jetson21
LQ Newbie
 
Registered: Feb 2010
Posts: 10

Original Poster
Rep: Reputation: 0
how does it know the first gateway is down and it should switch?

Last edited by jetson21; 03-30-2010 at 06:16 PM.
 
Old 03-31-2010, 05:32 AM   #13
CmdoColin
Member
 
Registered: Jul 2009
Posts: 31

Rep: Reputation: 17
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.

Config wise this should do the job:

route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.1.121 metric 1
route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.1.122 metric 10

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:

route add -net 200.0.0.0 netmask 255.0.0.0 gw 192.168.1.121 metric 1
route add -net 62.0.0.0 netmask 255.0.0.0 gw 192.168.1.122 metric 1

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.
 
Old 04-01-2010, 12:15 AM   #14
fancylad
Member
 
Registered: Mar 2008
Distribution: slackware
Posts: 175

Rep: Reputation: 19
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.
 
Old 04-01-2010, 10:37 AM   #15
jetson21
LQ Newbie
 
Registered: Feb 2010
Posts: 10

Original Poster
Rep: Reputation: 0
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.

Last edited by jetson21; 04-01-2010 at 10:39 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
non-default route to static host through gateway for ppp failover testing jrscandora Linux - Networking 3 04-21-2009 03:20 AM
Adding new Linux firewall/router on network with pre-existing gateway/router grittyminder Linux - Networking 4 08-13-2008 03:17 AM
Gentoo Linux And Failover Router,-routes seem to break after cycle. zer0python Linux - Networking 0 06-17-2008 10:02 AM
linux as router/gateway/firewall to dsl-router sjoerdvvu Linux - Networking 2 02-24-2006 11:56 PM
router-gateway-AP? bigearsbilly Linux - Wireless Networking 1 01-28-2005 08:47 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:43 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration