-
Notifications
You must be signed in to change notification settings - Fork 5
/
install-routes-linux
executable file
·40 lines (30 loc) · 1.33 KB
/
install-routes-linux
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# This script assumes a Linux system and something (like quagga) which will
# propagate as null routes the local static routes having a specific nexthop.
# It will sync these static routes with the ones in the list(s) by adding and
# removing local routes as needed.
# Set $DRY_RUN to only get a summary of the changes which would be applied.
source config.sh
BLACKHOLEFILE=$1
if [ "x$BLACKHOLEFILE" == "x" ] ; then
BLACKHOLEFILE=$CONF_IP
fi
if [ ! -e $BLACKHOLEFILE ] ; then
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - ERROR: File $BLACKHOLEFILE not found" >> $LOGFILE
exit
fi
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Install Routes Linux Started" >> $LOGFILE
NUMBER=0
for i in $(ip route | grep lo | cut -f1 -d\ ) ; do
NUMBER=$(expr $NUMBER + 1)
ip route del $i dev lo
done
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Cleared $NUMBER RBH routes" >> $LOGFILE
NUMBER=0
while read -r line ; do
NUMBER=$(expr $NUMBER + 1)
# works with both ip or cidr
ip route add $line via $BLACKHOLE_NEXTHOP
done < $BLACKHOLEFILE
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Added $NUMBER RBH routes" >> $LOGFILE
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Install Routes Linux Ended" >> $LOGFILE