LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   how to design gateway heart-bit signal ? (https://www.linuxquestions.org/questions/linux-networking-3/how-to-design-gateway-heart-bit-signal-657584/)

Joydeep Bakshi 07-22-2008 11:39 PM

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

Mr. C. 07-23-2008 12:18 AM

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

garyalex 07-23-2008 12:20 AM

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%

Joydeep Bakshi 07-23-2008 02:03 AM

Quote:

Originally Posted by garyalex (Post 3223355)
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.

Thanks for all responses as well as the links. I'll go through it. Please note mine is a clarkconnect server and syswatch deamon which actually do the auto-failover is buggy. Hence I have stopped that deamon as it comes in action in every min. and checks both the connection but failed to sense the connection which become live from its previous down state. Hence I am trying to do that failover module with shell script. thanks once again for the valuable links and response. What about the heartbit signal ?

Joydeep Bakshi 07-23-2008 03:06 AM

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.

garyalex 07-24-2008 12:24 AM

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.

Joydeep Bakshi 07-24-2008 05:57 AM

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

Mr. C. 07-24-2008 12:48 PM

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 
traceroute: Warning: apple.com has multiple addresses; using 17.149.160.49
traceroute to apple.com (17.149.160.49), 64 hops max, 40 byte packets
 1  10.0.0.1 (10.0.0.1)  0.169 ms
 2  ...  5.688 ms
 3  ...  3.782 ms
 4  ...  2.937 ms
 5  ...  5.792 ms
 6  ...  9.743 ms
 7  ...  7.536 ms
 8  ... 17.427 ms
 9  ...  9.741 ms
10  *
11  *
12  *
13  *
14  *
15  *

...

56  *
57  *
58  *
59  *
60  *
61  *
62  *
63  *
64  *
$ echo $?
0


Joydeep Bakshi 07-24-2008 11:14 PM

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

Mr. C. 07-24-2008 11:33 PM

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?

cmfarley19 07-25-2008 09:53 AM

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
I want to record the timestamps when it goes up/down so I have some hard data when I call Customer No-Service.

Anyone have any thoughts or suggestions?

Joydeep Bakshi 07-25-2008 10:32 AM

[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 )

cmfarley19 07-25-2008 11:56 AM

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
#      echo any arguments
echo $1

# Get the date and time in spreadsheet friendly format
DATE=$(date +%D' '%T)

# Try to connect.  If successful $CON="Google", else empty
CON=$(lynx -dump -connect_timeout=10 google.com|grep -i Lucky|cut -d ' ' -f5)

# Get the last entry in the log
TEMP=$( tail -1 connected.log |cut --complement -d ',' -f1|cut -d ' ' -f2)

# if an argument (DEBUG) echo $TEMP
if [ $1 ]
        then
        echo $TEMP
fi
 
#if $CONNECT is empty...
if [ -z $CON ]
        then
        echo "Not Connected"
        # if $TEMP !empty, last attempt was connected, so log the disconnect
        # else the last attempt was disconnected so do nothing
        if [ $TEMP ]
                then
                echo "$DATE, " >> connected.log
        fi

else
        echo "Connected to $CON"
        # if $TEMP is empty, last attempt was !connected, so log the connection
        # else the last attempt was connected so do nothing
        if [ -z $TEMP ]
                then
                echo "$DATE" >> connected.log
        fi

fi

Here is where I am stuck...
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
07/25/08 11:30:10, 07/25/08 11:30:10
07/25/08 11:30:19, 07/25/08 11:30:19
07/25/08 11:31:07, 07/25/08 11:31:07
07/25/08 11:48:52, 07/25/08 11:48:52
07/25/08 11:48:52,

Can someone offer a way to add the connected timestamp to the end of the last line of of the log file?

Mr. C. 07-25-2008 03:13 PM

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 ?

farslayer 07-25-2008 03:24 PM

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.