#!/bin/bash # Configure iptables # Limit PATH PATH="/sbin:/usr/sbin:/bin:/usr/bin" # iptables configuration firewall_start() { # Define rules /usr/sbin/iptables -A FORWARD -p tcp --destination-port 80 -j ACCEPT /usr/sbin/iptables -A FORWARD -p tcp --destination-port 443 -j ACCEPT /usr/sbin/iptables -t nat -A PREROUTING -j REDIRECT -p tcp --destination-port 80 --to-ports 8080 /usr/sbin/iptables -t nat -A PREROUTING -j REDIRECT -p tcp --destination-port 443 --to-ports 8443 } # clear iptables configuration firewall_stop() { iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT iptables -t nat -F iptables -t mangle -F iptables -F iptables -X } # execute action case "$1" in start|restart) echo "Starting firewall" firewall_stop firewall_start ;; stop) echo "Stopping firewall" firewall_stop ;; esac