diff options
Diffstat (limited to 'baseline/ufw-allow-mosh')
-rwxr-xr-x | baseline/ufw-allow-mosh | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/baseline/ufw-allow-mosh b/baseline/ufw-allow-mosh new file mode 100755 index 0000000..3f696ca --- /dev/null +++ b/baseline/ufw-allow-mosh @@ -0,0 +1,31 @@ +#!/bin/bash +# ripped off from here:https://stephenreescarter.net/mosh-and-ufw-without-1000-open-ports/ +# add entry in sudoers: my-awesome-user ALL:(ALL:ALL) NOPASSWD: /usr/local/bin/ufw-allow-mosh +# then add this in zshrc: sudo /usr/local/bin/ufw-allow-mosh + +# Load active ports +PORTS=`lsof -i | grep mosh-serv | cut -f2 -d":"` +STATUS=`sudo ufw status` + +# Add Rules for new ports +for PORT in $PORTS; do + + echo $STATUS | grep "$PORT/udp" > /dev/null + if [ $? -gt 0 ]; then + echo "Allowing new port $PORT" + sudo ufw allow $PORT/udp > /dev/null + fi +done + +# Remove closed ports +PORTS=`sudo ufw status | grep "^60.../udp" | cut -f1 -d"/" | sort | uniq` +OPEN=`lsof -i | grep mosh-serv` + +for PORT in $PORTS; do + + echo $OPEN | grep $PORT > /dev/null + if [ $? -gt 0 ]; then + echo "Removing closed port $PORT." + sudo ufw delete allow $PORT/udp > /dev/null + fi +done |