From 11585765d139f0559d15512b46e912142a7d79a1 Mon Sep 17 00:00:00 2001 From: Reza Behzadan Date: Thu, 20 Feb 2025 14:40:20 -0500 Subject: [PATCH] Add iptables_init.sh --- iptables_init.sh | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 iptables_init.sh diff --git a/iptables_init.sh b/iptables_init.sh new file mode 100644 index 0000000..43d17c6 --- /dev/null +++ b/iptables_init.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Flush existing rules +iptables -F +ip6tables -F +iptables -t nat -F +ip6tables -t nat -F + +# Set default policies +iptables -P INPUT ACCEPT +iptables -P FORWARD ACCEPT +iptables -P OUTPUT ACCEPT +ip6tables -P INPUT ACCEPT +ip6tables -P FORWARD ACCEPT +ip6tables -P OUTPUT ACCEPT + +# Apply IPv4 rules +iptables -t nat -A PREROUTING -i enX0 -p tcp --dport 443 -j REDIRECT --to-ports 4443 +iptables -t nat -A PREROUTING -i enX0 -p tcp --dport 80 -j REDIRECT --to-ports 4443 + +# Apply IPv6 rules +ip6tables -t nat -A PREROUTING -i enX0 -p tcp --dport 443 -j REDIRECT --to-ports 4443 +ip6tables -t nat -A PREROUTING -i enX0 -p tcp --dport 80 -j REDIRECT --to-ports 4443 + +# Save rules +iptables-save > /etc/iptables/rules.v4 +ip6tables-save > /etc/iptables/rules.v6 + +echo "iptables and ip6tables rules applied successfully." +