Add iptables_init.sh

This commit is contained in:
Reza Behzadan 2025-02-20 14:40:20 -05:00
parent dbbfb0fa1a
commit 11585765d1

30
iptables_init.sh Normal file
View File

@ -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."