Con questo Post andiamo a illustrare la procedura per installare e configurare iptables su un server Linux CentOS 6.3.
Iptables è un pacchetto software che permette al sistema Linux di diventare un potente Firewall Software.
E’ usato per impostare, mantenere e ispezionare le tabelle delle regole di filtraggio dei pacchetti IP direttamente dal Kernel di Linux.
Interfacciandolo alla rete Lan, Iptables permette a Linux di eseguire anche un controllo e filtraggio dei pacchetti di rete.
1. Per installare iptables, basta eseguire il seguente comando:
[root@centos63 ~]# yum install iptables -y
2. Controllate a questo punto la versione del pacchetto di Iptables installato:
[root@centos63 ~]# rpm -qa | grep iptables
iptables-ipv6-1.4.7-5.1.el6_2.i686
iptables-1.4.7-5.1.el6_2.i686
3. Controllate lo stato di Iptables:
[root@centos63 ~]# /etc/init.d/iptables status
iptables: Firewall is not running.
o
[root@centos63 ~]# service iptables status
iptables: Firewall is not running.
4. Avvio e Stop di Iptables :
Start :
[root@centos63 ~]# service iptables start
iptables: Applying firewall rules: [ OK ]
Stop :
[root@centos63 ~]# service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
5. Settare l’avvio automatic alla partenza di Iptables:
[root@centos63 ~]# chkconfig iptables on
6. Visualizzare le regole di base di Iptables:
[root@centos63 ~]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
7. Visualizzare le porte correnti aperte:
[root@centos63 ~]# netstat -plunt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:46915 0.0.0.0:* LISTEN 1170/rpc.statd
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1538/mysqld
tcp 0 0 127.0.0.1:3310 0.0.0.0:* LISTEN 1406/clamd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1152/rpcbind
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1390/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1629/master
tcp 0 0 :::111 :::* LISTEN 1152/rpcbind
tcp 0 0 :::59988 :::* LISTEN 1170/rpc.statd
tcp 0 0 :::22 :::* LISTEN 1390/sshd
tcp 0 0 ::1:25 :::* LISTEN 1629/master
udp 0 0 0.0.0.0:59738 0.0.0.0:* 1170/rpc.statd
udp 0 0 0.0.0.0:111 0.0.0.0:* 1152/rpcbind
udp 0 0 192.168.1.54:123 0.0.0.0:* 1398/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 1398/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 1398/ntpd
udp 0 0 0.0.0.0:903 0.0.0.0:* 1152/rpcbind
udp 0 0 0.0.0.0:922 0.0.0.0:* 1170/rpc.statd
udp 0 0 :::50667 :::* 1170/rpc.statd
udp 0 0 :::111 :::* 1152/rpcbind
udp 0 0 fe80::20c:29ff:fe1b:b39c:123 :::* 1398/ntpd
udp 0 0 ::1:123 :::* 1398/ntpd
udp 0 0 :::123 :::* 1398/ntpd
udp 0 0 :::903 :::* 1152/rpcbind
8. Modificare il file originale di Iptables:
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
Notate che due regole sono state aggiunte alle regole standard di Iptables:
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
Buon lavoro e buon divertimento con il vostro nuovo Firewall !