change IP interface from script

Hi!

I need a script for the followings:

I have ether1 (WAN - ISPline1)
I have ether3 (WANBCK - ISPLine2) (wireless connection to ISP) - DISABLED (same IP same everything)
I have ether2 local

IP address:
ether1 - 1.1.1.1/29
ether2 - 192.168.1.254/24

And when the gateway down I like to change the IP interface to ether3 so…

I create a netwatch to ping the gateway and if there is problem the netwatch down script

wanscript

/interface disable ether1
/interface enable ether3
/tool e-mail send to=“xx@xy.com” subject=“Problem with the Connection!”
/ip address set/get???..

After the script:

Interfaces
ether1 DISABLED
ether3 enabled

IP address:
ether3 - 1.1.1.1/29
ether2 - 192.168.1.254/24

Any suggestion?


Josh


In command line : If I like to remove the IP for ether 1 and readd the IP to ether3 I need to

/ip address print - to show what i want to remve, but how i do this in a script??? Thanks

You should search under failover scripts. Many people wrote scripts for this purpose. You could always adopt it to your needs.

The command you need to run in your script, is something like:

/ip address set [find name="interfacename’] interface=ether1/wlan2/pppoe-out1

Try and write a script from what you find in the forum, and past it when you get stuck. The easiest way to learn scripting is by struggling till you get it right :smiley:

Having the same address in the router will be somewhat difficult to setup in your case. It will just mess things.
Might try setting up bridge, with RSTP, or using ospf on your link and leave it enabled, while setting priorities to determine wich will be the active connection when both are available.

I agree with jorj. It is not a good idea to have the same address for 2 bandwidth sources.

I would suggest making ISP 1’s ip eg 1.1.1.254/24 and ISP 2’s IP eg 1.1.2.254/24 on your routers connecting to your ISP’s.

You could add static routes to route two hardly ever used IP’s via both ISP’s. (eg, route 196.25.1.1 via ISP1 and 196.25.1.2 via ISP2). Now you can setup monitors to monitor both those IP’s. If eg ISP1’s IP go down, it’s likely that ISP1 is down (but 196.25.1.1 could also be down, so be careful of doing it this way, make sure you use an IP ON that ISP’s backbone).

From here you can write scripts to change your default gateway to the other ISP’s address (1.1.1.254 or 1.1.2.254)