Δημοσιεύτηκε: 25 Ιουν 2012, 00:28
από pc_magas
Κάνεις ένα bash script όπου θα ρυθμίζει το iptables καλό είναι να το βάλεις κάπου στο /etc

Σου παραθέτω το δικό μου script ρύθμισης των iptables για καλύτερη μελέτη: (Το έχω ονομάσει iptables.sh και το έχω αποθηκεύσει στο /etc)
Κώδικας: Επιλογή όλων
#!/bin/bash

iptables -F
iptables -X

#Allow Outcomming Connections
iptables -A OUTPUT -j ACCEPT

#Allow loppback
iptables -A INPUT -i lo -j ACCEPT
#Allow Active Connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#CREATING LISTS
iptables -N inputl

#Allow chan input to handle incoming connections
iptables -A INPUT -i eth0 -j inputl

#CONFIGURING THE input CHAIN
iptables -A inputl -m limit --limit 5/min -j LOG #Limit Connections
iptables -A inputl -p tcp --dport 80 -j ACCEPT #Open port http
iptables -A inputl -p tcp --dport 8080 -j ACCEPT #Open a another port that listens my apache
iptables -A inputl -p tcp --dport 443 -j ACCEPT# Open https
iptables -A inputl -p tcp --dport 22 -j ACCEPT #Accept ssh
iptables -A inputl -p icmp --icmp-type echo-request -j ACCEPT #Accept echo
iptables -A inputl -j REJECT #Set default to reject

iptables -A INPUT -j REJECT
iptables -A FORWARD -j REJECT


Μετά το εκτελείς και προσθέτεις στο αρχείο /etc/rc.local:

Κώδικας: Επιλογή όλων

sudo <path τοιυ script ρύθμισης iptables>


Πρίν από το exit 0

Πχ στο δικό μου /etc/rc.local
Κώδικας: Επιλογή όλων
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

sudo /etc/iptables.sh& #Rithmisi iptables
sudo apt-get update&
sudo apt-get -y dist-upgrade&
sudo cron-apt
exit 0