Created
May 31, 2023 12:29
-
-
Save chofstede/b5598956315969e3de25d11dd49b30ff to your computer and use it in GitHub Desktop.
proxmox-firewall-config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # | |
| # iptables firewall script v1.0 | |
| # | |
| PATH=/usr/sbin:/sbin:/bin:/usr/bin | |
| #den Namen eurer Netzwerkkarte könnt ihr mit dem Befehl ip addr herausfinden. | |
| WAN=enp0s31f6 | |
| #IP Adressen sind ebenfalls mit dem Befehl ip addr herauszufinden. | |
| IPv6=2a01:4f9:2b:a52::2 | |
| IPv4=95.216.74.62 | |
| #einfacher Switch Case (siehe weiter unten für Bedeutung) | |
| case $1 in | |
| start) | |
| #stoppe das Script zuerst | |
| $0 stop | |
| #default policy setzen Output ist generell okay. | |
| iptables -P INPUT DROP | |
| ip6tables -P INPUT DROP | |
| iptables -P OUTPUT ACCEPT | |
| ip6tables -P OUTPUT ACCEPT | |
| iptables -P FORWARD ACCEPT | |
| ip6tables -P FORWARD ACCEPT | |
| #localhost traffic ist okay. | |
| iptables -A INPUT -i lo -j ACCEPT | |
| ip6tables -A INPUT -i lo -j ACCEPT | |
| #pings gegen die firewall sind okay. | |
| iptables -A INPUT -p icmp -d $IPv4 -j ACCEPT | |
| ip6tables -A INPUT -p icmpv6 -j ACCEPT | |
| #verbindungen welche die firewall akzeptiert hat sind okay. | |
| #siehe iptables Tutorial für die Bedeutung von ESTABLISHED,RELATED. | |
| iptables -A INPUT -i $WAN -m state --state ESTABLISHED,RELATED -j ACCEPT | |
| ip6tables -A INPUT -i $WAN -m state --state ESTABLISHED,RELATED -j ACCEPT | |
| #verbindungen auf port 22 zur firewall werden akzeptiert. | |
| iptables -A INPUT -i $WAN -p tcp -d $IPv4 --dport 30822 -j ACCEPT | |
| ip6tables -A INPUT -i $WAN -p tcp -d $IPv6 --dport 30822 -j ACCEPT | |
| #verbindungen auf port 2222 zur firewall werden akzeptiert | |
| iptables -A INPUT -i $WAN -p tcp -d $IPv4 --dport 2222 -j ACCEPT | |
| ip6tables -A INPUT -i $WAN -p tcp -d $IPv6 --dport 2222 -j ACCEPT | |
| echo "Firewall activated after stopped" | |
| ;; | |
| stop) | |
| iptables -F | |
| iptables -X | |
| iptables -P INPUT ACCEPT | |
| iptables -P OUTPUT ACCEPT | |
| iptables -P FORWARD ACCEPT | |
| ip6tables -F | |
| ip6tables -X | |
| ip6tables -P INPUT ACCEPT | |
| ip6tables -P OUTPUT ACCEPT | |
| ip6tables -P FORWARD ACCEPT | |
| echo "Firewall stopped" | |
| ;; | |
| restart) | |
| $0 start | |
| ;; | |
| *) | |
| echo "Usage: $0 {start|stop|restart}" | |
| ;; | |
| esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment