Created
August 5, 2012 04:34
-
-
Save loveJesus/3261700 to your computer and use it in GitHub Desktop.
Three gateways to the internet
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
| #The Lord is my Shepherd, I shall not want | |
| #He makes me lie down in green pastures | |
| #He leads me besides quiet waters | |
| #!/bin/bash | |
| #This file is to setup a load balancing across 3 gateways to the internet | |
| #First make sure to add the lines | |
| #echo 200 t1 >> /etc/iproute2/rt_tables | |
| #echo 201 t2 >> /etc/iproute2/rt_tables | |
| #echo 202 t3 >> /etc/iproute2/rt_tables | |
| #These are the subnets that the gateways are on | |
| $P1_NET=192.168.1.0/24 | |
| $P2_NET=192.168.2.0/24 | |
| $P3_NET=192.168.4.0/24 | |
| #These are the ethernet devices connected to the gateways | |
| $IF1=eth0 | |
| $IF2=eth0 | |
| $IF3=eth0 | |
| #These are the IP addresses of the machine that this script is run on | |
| $IP1=192.168.1.20 | |
| $IP2=192.168.2.18 | |
| $IP3=192.168.4.20 | |
| #These are the IP addresses of the gateways | |
| $P1=192.168.1.1 | |
| $P2=192.168.2.1 | |
| $P3=192.168.4.1 | |
| ip route add $P1_NET dev $IF1 src $IP1 table t1 | |
| ip route add $P2_NET dev $IF2 src $IP2 table t2 | |
| ip route add $P3_NET dev $IF3 src $IP3 table t3 | |
| ip route add $P1_NET dev $IF1 src $IP1 | |
| ip route add $P2_NET dev $IF2 src $IP2 | |
| ip route add $P3_NET dev $IF3 src $IP3 | |
| ip rule add from $IP1 table t1 | |
| ip rule add from $IP2 table t2 | |
| ip rule add from $IP3 table t3 | |
| ip route add default scope global nexthop via $P1 dev $IF1 weight 1 \ | |
| nexthop via $P2 dev $IF2 weight 1 \ | |
| nexthop via $P3 dev $IF3 weight 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment