From 3f150e469db368a58e589ad1bae68c1800fbcae4 Mon Sep 17 00:00:00 2001 From: Joey Hafner Date: Sun, 7 Aug 2022 14:20:15 -0700 Subject: [PATCH] Init update hairpin nat script --- router/scripts/update_hairpin_nat.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 router/scripts/update_hairpin_nat.sh diff --git a/router/scripts/update_hairpin_nat.sh b/router/scripts/update_hairpin_nat.sh new file mode 100644 index 0000000..f106eeb --- /dev/null +++ b/router/scripts/update_hairpin_nat.sh @@ -0,0 +1,25 @@ +#!/bin/vbash +source /opt/vyatta/etc/functions/script-template + +# create copies of config for modification and backup +cp /config/config.boot /config/config.new +cp /config/config.boot /config/backups/config.bk-$(date +%Y-%m-%d) +# get current public IP +NEW_IP=$(run show interfaces pppoe pppoe1 | grep "inet\s" | cut -d ' ' -f 6) +# get old public IP +OLD_IP=$(run show nat destination rules | grep 1100 | head -1 | cut -d ' ' -f 8) + +# edit the config.new file +sed -i "s/$OLD_IP/$NEW_IP/" /config/config.new + +# switch mode to config +configure + +# apply the new config +load /config/config.new +{ # 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." +}