Created
          April 22, 2016 10:26 
        
      - 
      
 - 
        
Save alexalouit/15bc7c92fe1eec953e4a585f88779f79 to your computer and use it in GitHub Desktop.  
    Connection status checker with iptables-conditions for dynamic routing, load balancing and failover
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/sh | |
| # | |
| # cron ex: @reboot /usr/bin/nice -n 19 /usr/bin/ionice -c2 -n7 /root/scripts/100_up.sh >> /root/scripts/cron.log | |
| while true ; do | |
| # do ping with interface | |
| if /bin/ping -qc 3 8.8.8.8 -I eth0.100 > /dev/null; then | |
| if /bin/grep -q 0 /proc/net/nf_condition/100_up; then /bin/echo 1 > /proc/net/nf_condition/100_up; fi | |
| else | |
| # do ping with fwmark, and to another target | |
| if /bin/ping -qc 3 8.8.4.4 -m 100 > /dev/null; then | |
| if /bin/grep -q 0 /proc/net/nf_condition/100_up; then /bin/echo 1 > /proc/net/nf_condition/100_up; fi | |
| else | |
| if /bin/grep -q 1 /proc/net/nf_condition/100_up; then /bin/echo 0 > /proc/net/nf_condition/100_up; fi | |
| fi | |
| fi | |
| sleep 3 | |
| done | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
This example assumes you have a eth0.100 interface, which has reachable valid default route and reachable number 100 fwmark.