Change IP Tables rules with ISPConfig3

Discussion in 'Tips/Tricks/Mods' started by ledzgio, Feb 6, 2014.

  1. ledzgio

    ledzgio New Member

    Hi all,

    by default ISPConfig3 sets the default iptables rules which, in my case, are:

    iptables -L:

    Chain INPUT (policy ACCEPT)
    target prot opt source destination
    fail2ban-dovecot-pop3imap tcp -- anywhere anywhere multiport dports pop3,pop3s,imap2,imaps
    fail2ban-pureftpd tcp -- anywhere anywhere multiport dports ftp
    fail2ban-sasl tcp -- anywhere anywhere multiport dports smtp
    fail2ban-ssh tcp -- anywhere anywhere multiport dports ssh

    Chain FORWARD (policy ACCEPT)
    target prot opt source destination

    Chain OUTPUT (policy ACCEPT)
    target prot opt source destination

    Chain fail2ban-dovecot-pop3imap (1 references)
    target prot opt source destination
    RETURN all -- anywhere anywhere

    Chain fail2ban-pureftpd (1 references)
    target prot opt source destination
    RETURN all -- anywhere anywhere

    Chain fail2ban-sasl (1 references)
    target prot opt source destination
    RETURN all -- anywhere anywhere

    Chain fail2ban-ssh (1 references)
    target prot opt source destination
    RETURN all -- anywhere anywhere

    which seems to accept all the connections (if I am not wrong).

    I would like to apply a more restrictive iptables rules, for example something like the following:

    *filter

    # allow loopback traffic
    -A INPUT -i lo -j ACCEPT
    -A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT

    # allow established connections
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

    # allow outbound traffic
    -A OUTPUT -j ACCEPT

    # allow running services
    -A INPUT -p tcp --dport 80 -j ACCEPT
    -A INPUT -p tcp --dport 443 -j ACCEPT
    -A INPUT -p tcp --dport 8080 -j ACCEPT
    -A INPUT -p tcp --dport 143 -j ACCEPT
    -A INPUT -p tcp --dport 993 -j ACCEPT
    -A INPUT -p tcp --dport 587 -j ACCEPT
    -A INPUT -p tcp --dport 110 -j ACCEPT

    # allow SSH on port 22
    -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT

    # log denied iptables calls
    -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7

    # denie all the remaining inbound traffic
    -A INPUT -j REJECT
    -A FORWARD -j REJECT

    COMMIT

    Can I completely change the rule file? how can I merge the two without lost the fail2ban rules?

    Thank you very much.
     

Share This Page