Simple script to enable/disable an IP address based on ping?

I’m running OSPF with several routers using 2 different paths back to the main gateway router. It works fine for load balancing but I need half the routers to go one way and the other half to go the other way with failover. Adjusting the cost is giving me strange results and doens’t seem to work as it should. The only way this works is by disabling one of the IP addresses in each router to force them to go another way. I know I can do check gateway pings but I don’t want to manually right all my routes. There are alot and its ever changing.

So lets say my gateway has 2 IP’s, 1.1.1.1 on ether 1 and 2.2.2.2 on ether 2. If my other router has 1.1.1.5 and 2.2.2.5 I would like 1.1.1.5 normally disabled. Then it will ping 2.2.2.2 on its interface that is 2.2.2.5. If those pings go away then enabled ip address 1.1.1.5 which will automatically create the ospf routes and failover. Then if pings resume on 2.2.2.2 disabled 1.1.1.5 again.

Can someone help me with this? It seams simple but I am new to scripting.

add netwatch and specify up/down events
up:
/ip address disable [find address=“1.1.1.1/24”]
down:
/ip address enable [find address=“1.1.1.1/24”]


The best way is still to adjust OSPF costs. It gave you strange results most likely because something was not set up properly.

Thanks I’ll try this.

The problem with OSPF is that I have 6 routers going back to one router. That one router acts as 2 gateways to the internet. So I can adjust cost on that router and send all 6 routers one way or another and it works fine but I need 3 of them going one way and 3 of them going the other way and for the life of me I can’t seem to make that happen since they all go back to the same 2 interfaces on the gateway router. As far as I can tell I cannot adjust cost individually for each router.

Change the cost on the interfaces of the 6 routers, not on the router that all 6 connect to.

Well I’ve done that. And the 6 routers choose their default gateway accordingly but all this does is force the upload to go one direction. The gateway router still shows both paths back to the each of the 6 routers so the downloads are still sent 50/50.

Would anybody be interested in looking at them if I setup a read only access to them and maybe well me what I need to do?

My idea on failover may be usefull. I’m not doing load balancing, only failover. I have three routers: primary uplink, secondary uplink and LAN router. I’m manipulating with Default Route Metric in OSPF instance settings.

Topology:
(adsl interface)PrimaryUplink(eth1)-------(eth3)LAN(eth2)----------(eth1)SecondaryUplink(adsl interface)

SecondaryUplink has Default Route Metric in OSPF instance setting set to 5. PrimaryUplink has Default Route Metric set to 1.
With netwach on PrimaryUplink router I’m checking reliable host on internet.
When netwatch changes status to down, executes script prim_down. When netwatch changes status to up, executes script prim_up.

script prim_down:

/routing ospf instance set metric-default=10 numbers=0
/interface ethernet disable numbers=1
delay 3
/interface ethernet enable numbers=1

script prim_up:

/routing ospf instance set metric-default=1 numbers=0
/interface ethernet disable numbers=1
delay 3
/interface ethernet enable numbers=1

Scripts change Default Route Metric parameter and disable and enable interface that is connected to LAN router, so OSPF routes are recalculated and distributed.