From 8c72ea3f31ee396b7e70a23d1bc6ad52913c9cb9 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sun, 18 Jul 2021 12:57:56 -0500 Subject: [PATCH] Added Mordhau-Open-Ports.bash --- Mordhau/Mordhau-Open-Ports.bash | 14 ++++++ Port-Forward.bash | 76 +++++++++++++++++---------------- 2 files changed, 54 insertions(+), 36 deletions(-) create mode 100755 Mordhau/Mordhau-Open-Ports.bash diff --git a/Mordhau/Mordhau-Open-Ports.bash b/Mordhau/Mordhau-Open-Ports.bash new file mode 100755 index 0000000..9605f86 --- /dev/null +++ b/Mordhau/Mordhau-Open-Ports.bash @@ -0,0 +1,14 @@ +#!/bin/bash --posix + +set -e + +firewall-cmd --add-port 7770-7779/tcp --permanent +firewall-cmd --add-port 27000-27009/tcp --permanent +firewall-cmd --add-port 15000-15009/tcp --permanent +firewall-cmd --add-port 26000-26009/tcp --permanent + +echo "All ports open for Mordhau servers - reloading firewall-cmd..." + +firewall-cmd --reload + +echo "Finished opening ports." diff --git a/Port-Forward.bash b/Port-Forward.bash index cce82f5..ad41b43 100755 --- a/Port-Forward.bash +++ b/Port-Forward.bash @@ -24,50 +24,54 @@ usage() { All above flags must be passed with arguments" } - error() { - printf '%s\n' "$1" >&2 - exit 1 + printf '%s\n' "$1" >&2 + exit 1 } while :; do - case $1 in - -h|-\?|--help) - usage # Display a usage synopsis. - exit - ;; - --) # End of all options. - shift - break - ;; - --ip) - shift - [[ "${1}" == "" ]] && error "--ip requires an argument" - IP=${1} - ;; - --inbound-port) - shift - [[ "${1}" == "" ]] && error "--inbound-port requires an argument" - INBOUND_PORT=${1} - ;; - --forward-port) - shift - [[ "${1}" == "" ]] && error "--forward-port requires an argument" - FORWARD_PORT=${1} - ;; - -?*) - printf 'Unknown option: %s\n' "$1" >&2 - usage - ;; - *) # Default case: No more options, so break out of the loop. - break - esac - + case $1 in + -h | -\? | --help) + usage # Display a usage synopsis. + exit + ;; + --) # End of all options. shift + break + ;; + --ip) + shift + [[ "${1}" == "" ]] && error "--ip requires an argument" + IP=${1} + ;; + --inbound-port) + shift + [[ "${1}" == "" ]] && error "--inbound-port requires an argument" + INBOUND_PORT=${1} + ;; + --forward-port) + shift + [[ "${1}" == "" ]] && error "--forward-port requires an argument" + FORWARD_PORT=${1} + ;; + -?*) + printf 'Unknown option: %s\n' "$1" >&2 + usage + ;; + *) # Default case: No more options, so break out of the loop. + break ;; + esac + + shift done +[[ "${IP}" == "" ]] && error "--ip requires an argument" +[[ "${FORWARD_PORT}" == "" ]] && error "--forward-port requires an argument" +[[ "${INBOUND_PORT}" == "" ]] && error "--inbound-port requires an argument" + firewall-cmd --permanent --add-forward-port=port="${INBOUND_PORT}":proto=tcp:toaddr="${IP}":toport="${FORWARD_PORT}" firewall-cmd --permanent --add-port="${INBOUND_PORT}"/tcp firewall-cmd --add-masquerade +firewall-cmd --reload -echo "Routing all data on ${INBOUND_PORT} to ${IP}${FORWARD_PORT}" \ No newline at end of file +echo "Routing all data on ${INBOUND_PORT} to ${IP}:${FORWARD_PORT}" \ No newline at end of file