vi /etc/rc.local
sudo /etc/rc.local
#!/bin/sh -e # ###-----------------------------------------------------### echo "Set path of iptables" echo IPTABLES="/sbin/iptables" ###-----------------------------------------------------### echo "Set external ......" echo #FW_IP="" #FW_IP_RANGE="" #FW_IFACE="eth0" ###-----------------------------------------------------### echo "Set internal ......" echo #LAN_IP="192.168.1.1" LAN_IP_RANGE="192.168.1.0/24" #LAN_BCAST_ADRESS="192.168.1.255" #LAN_IFACE="eth1" # loopback interface LO_IFACE="lo" LO_IP="127.0.0.1" ###-----------------------------------------------------### #echo "Enable ip_forward ......" #echo #echo "1" > /proc/sys/net/ipv4/ip_forward ###-----------------------------------------------------### echo "Flush fiter table ......" echo # Flush filter $IPTABLES -F $IPTABLES -X echo "Flush nat table ......" echo # Flush nat $IPTABLES -F -t nat $IPTABLES -t nat -X ###-----------------------------------------------------### $IPTABLES -P INPUT ACCEPT $IPTABLES -P OUTPUT ACCEPT $IPTABLES -P FORWARD ACCEPT ###-----------------------------------------------------### #$IPTABLES -t nat -A POSTROUTING -o $FW_IFACE -j SNAT --to-source $FW_IP ###-----------------------------------------------------### #$IPTABLES -t nat -A PREROUTING -p tcp -d $FW_IP --dport 8080 -j DNAT --to 192.168.1.3:80 ###-----------------------------------------------------### #$IPTABLES -A FORWARD -o $FW_IFACE -p tcp -s 192.168.1.6 --dport 6677 -j ACCEPT #$IPTABLES -A FORWARD -o $FW_IFACE -p tcp --dport 6677 -j DROP ###-----------------------------------------------------### #$IPTABLES -A INPUT -i $FW_IFACE -p tcp -s 192.168.1.0/24 --dport 6677 -j ACCEPT #$IPTABLES -A INPUT -i $FW_IFACE -p tcp --dport 6677 -j DROP #iptables -A ratelimit -p tcp -m state --state ESTABLISHED,RELATED -j ACCEPT #iptables -A ratelimit -p icmp --icmp-type echo-request -m limit --limit 3/m --limit-burst 10 -j ACCEPT #iptables -A ratelimit -p icmp --icmp-type echo-request -j LOG --log-level "NOTICE" --log-prefix "[RATELIMIT$ #iptables -A ratelimit -p icmp --icmp-type echo-request -j DROP #iptables -A INPUT -p icmp --icmp-type echo-request -j ratelimit #iptables -A INPUT -p tcp --dport 443 -j LOG --log-level "NOTICE" --log-prefix "[9999]" $IPTABLES -A INPUT -p tcp -s 127.0.0.1 --dport 21 -j ACCEPT $IPTABLES -A INPUT -p tcp --dport 21 -j DROP $IPTABLES -A INPUT -p tcp -s $LAN_IP_RANGE --dport 22 -j ACCEPT $IPTABLES -A INPUT -p tcp -s 120.115.3.33 --dport 22 -j ACCEPT $IPTABLES -A INPUT -p tcp -s 127.0.0.1 --dport 22 -j ACCEPT $IPTABLES -A INPUT -p tcp --dport 22 -j DROP $IPTABLES -A INPUT -p tcp -s 127.0.0.1 --dport 111 -j ACCEPT $IPTABLES -A INPUT -p tcp --dport 111 -j DROP /sbin/ip6tables -F /sbin/ip6tables -A INPUT -p tcp --dport 22 -j DROP exit 0