homelab/wizard/scripts/update_hairpin_nat.sh

24 lines
613 B
Bash
Raw Normal View History

2022-08-07 14:20:15 -07:00
#!/bin/vbash
source /opt/vyatta/etc/functions/script-template
# get current public IP
2024-01-07 02:26:18 -08:00
NEW_IP=$(show interfaces pppoe pppoe1 | grep "inet\s" | cut -d ' ' -f 6)
2022-08-07 14:20:15 -07:00
# get old public IP
2024-01-07 02:26:18 -08:00
OLD_IP=$(show nat destination rules | grep 1100 | head -1 | tr -s ' ' | cut -d' ' -f 3)
2022-08-07 14:20:15 -07:00
2024-01-07 02:26:18 -08:00
show configuration commands | grep $OLD_IP | sed --expression="s/$OLD_IP/$NEW_IP/" > ipupdate.tmp
configure
source ipupdate.tmp
2022-08-07 14:20:15 -07:00
{ # try commit, save, exit
commit && save && exit
} || { # catch, exit discard and create a very basic error file
exit discard
echo "Script failed. Write some real error handling."
}
2024-01-07 02:26:18 -08:00
rm ipupdate.tmp