how to design gateway heart-bit signal ?
Dear list,
I am not a linux-network guru hence need your king guidance to achieve an important shell-script. I have a linux server with 3 lan cards. 1> eth0 --> 192.168.1.1 working as lan 2> eth1 ---> 192.168.1.3<--- connected with ADSL modem ip 192.168.1.2<< working as gateway 1 3> eth2 ----> 192.168.0.2<--- connected with ADSL modem ip 192.168.0.1<< working as gateway2 here is "route -n" Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth2 I like to make a shell script which will send heart-bit signal to both the gateway to check if the gateway are on line. if it sense the "default route" gateway is down then it will switch over the internet to the second gateway. But the first thing first the heart bit signal. I have checked with " ping -I 192.168.1.3 gmail.com -w 3" and also with " ping -I 192.168.0.2 gmail.com -w 3" with manually disable the gateways alternatively and in both the cases ping works. Hence it is actually not sending the ping through the proper gateways I like to check. Could any one kindly suggest how to do this ? I really need your kind guidance to design the script. thanks |
This network doesn't make sense. You have the same network assigned to multiple interfaces (eth0 and eth1).
Consider when an application makes a socket connection to a remote site. Which interface would the kernel place the packet on? According to your route table, it could place it on either eth0 or eth1. Should the kernel guess? Use only the first? Lets get your network topology worked out first, then we can discuss larger topics. ps. I think you mean "heartbeat". |
Hi Joydeep
Firstly, your eth1 should really be on a separate subnet... your subnet mask is wrong (its 255.255.255.0) and could cause confusion on your interfaces. Maybe use 192.168.2.x for this... Also you should look at using iproute2 for specifying 2 gateways. View this guide for details: Linux Advanced Routing HOWTO. You can also view an article I posted on my blog to set this up. Once you have this working nicely, then you can more easily create a script that will work 100% |
Quote:
|
Ok, I have redesign my network.
1> eth0 --> 192.168.1.1 working as lan ( as before ) 2> eth1 ---> 192.168.2.3<--- connected with ADSL modem ip 192.168.2.2<< working as gateway 1 ( changed eth1 from 192.168.1.3 to 192.168.2.3 and gateway from 192.168.1.2 to 192.168.2.2 ) 3> eth2 ----> 192.168.0.2<--- connected with ADSL modem ip 192.168.0.1<< working as gateway2 ( as before) Now please suggest me how can I check both the gateways with heartbit signal and also tell me if I need some more preparation with iproute command before desiging my code for hearbit signal and autofail over. Thanks for all your effort. |
You might want to look at Zabbix or Nagios as a monitor for your gateways. These can be customised with scripts and notifications should a link or service go down.
If you are looking for a more simplified option check this out. |
Thanks for your suggestion, But I am looking something else which actually don't need Zabbix or Nagios. I am trying to make a shell-script which just monitor my 2 lan cards connectede with 2 ADSl modem in every predefined interval. When it sense that the default gateway link is down then it change the connection to the other lan card connected with another ADSL assuming that connection is on. So the internet connection will never be offline and we can exploit our 2 internet connection properly ( one is primary and one is backup).
I have checked with traceroute command and it did what I am expecting. for ADSL1 connectede with eth1 # traceroute -i eth1 -m 5 gmail.com; echo $? for ADSL2 connected with eth2 # traceroute -i eth2 -m 5 gmail.com; echo $? but when it fails to send package; even then also it returs 0 means success I don't know how to trap the failure signal with $? Help needed. thanks |
This method of detecting network path failures will be prone to error. But you'll discover that as you move along.
A little clarification: traceroute doesn't fail to send a packet unless the remote host isn't resolvable or routable; if it can send, it may not receive a response packet. Traceroute doesn't return an error status if packets are not returned by remote hops. Traceroute did its job, and shouldn't indicate there was an error in execution, so it returns 0. For unresolvable or unroutable hosts, an error is returned. Code:
$ traceroute -f1 -q1 apple.com |
Thanks for your clarification. I am also thinking to use ping as it returns the failure code.
here is my code <code> # Interface for gateway1 GET1=eth1 Provider1=Tataindicom # check Gateway1 #eth1 #traceroute -m 5 -s $IP1 gmail.com ###traceroute -m 5 -i $GET1 gmail.com ping -I $IP1 gmail.com -w 3 net1=$? case $net1 in 0) echo "$Provider1 is UP";; 1) echo "$Provider1 is DOWN";; esac </code> you can Imagine that I will repeat the code for gateway2 i.e. 2nd lan card connected with 2nd ADSL modem. what do u think about it ? But the bigger part is to develop the script so that it can do the automatic connection change to another ADSL if it find the present gateway is off-line. and iproute comes in action for this. Please help me to achieve the script |
It is prone to false positives. ICMP echo requests are often prioritized lower by routers, and are dropped when the router is loaded. This will lead you to believe that path is down. If you are going to test your link to a gateway, only test to the gateway, not some distant site like gmail.
Down vs. Slow to respond are two states that look alike, so its easy to mistake. You are just going to be changing the default route, correct? |
Interesting...
I am attempting to do something very similar. My ISP, Comcast, is highly unreliable. I started working from home about six months ago and connect to the office in CT via a VPN. Since I am at home all day long I've noticed that my internet connection drops out several times a day for many minutes at a time. It is irritating to say the least and often interrupts my work. I was planning on using lynx with the -dump option. Code:
lynx -dump www.google.com Anyone have any thoughts or suggestions? |
[QUOTE=
You are just going to be changing the default route, correct?[/QUOTE] Exactly , but before that I have to check 1> if the gateway working as default route is alive 2> If not then check the second gateway ( i.e.the second ADSL modem ) 3> if the 2nd gateway is UP then change the default route to lan card connected with the 2nd ADSL 4> sending heart-bit signal at an interval of 5 min. to both the gateway ( i.e ADSL modem to check the status ) |
This thread got me to finally do this.
Here is what I came up with. you should be able to modify this slightly for your purpose. Code:
#!/bin/bash I basically want a comma-separated file with two columns. The first column is the (next) time the internet connections goes down. The second is the (next) time it is up. Writing the first column is easy. Just append the down-time to the log file. The second column I need added to the end of the last line of the log file. After a disconnect the log file will look like this: Code:
DOWN, UP |
This is a huge amount of work to be performing to check and monitor a network connection!
a) you don't need to download an entire page, with all the overhead of the HTTP connection, data transfer, etc. Use something designed for this purpose (traceroute, ping) b) google.com is unavailable sometime, and that doesn' mean your network is down. c) google.com may be reachable. which routes to other major hosts such as hotmail.com may be down. d) vice-versa (c) above. e) do all of your post processing of raw data lazily - eg. when you actually want to see it, not each and every network check. f) put all your data into one file, one entry per line, and you can post-process the data with odd lines being DOWN and even lines being UP. Do you know about smokeping ? |
Couldn't you also use BOTH Internet connections rather than let one sit idle until the other fails ? kind of a waste to have that bandwidth sitting there unused isn't it ?
http://lartc.org/howto/lartc.rpdb.multiple-links.html http://www.linuxhorizon.ro/iproute2.html |
All times are GMT -5. The time now is 09:18 PM. |