2019-08-25 02:06:19 +00:00
|
|
|
*filter
|
|
|
|
:INPUT {{ firewall_iptables_input_policy }}
|
|
|
|
:FORWARD {{ firewall_iptables_forward_policy }}
|
|
|
|
:OUTPUT {{ firewall_iptables_output_policy }}
|
|
|
|
|
2019-08-27 05:35:14 +00:00
|
|
|
-N LOG_ACCEPT
|
2019-09-02 17:51:48 +00:00
|
|
|
-A LOG_ACCEPT -j NFLOG --nflog-group {{ firewall_iptables_nflog_group }}
|
2019-09-02 17:50:56 +00:00
|
|
|
{% if firewall_use_ulogd %}
|
|
|
|
-A LOG_ACCEPT -m limit --limit {{ firewall_log_limit }} --limit-burst {{ firewall_log_limit_burst }} -j NFLOG --nflog-group {{ firewall_ulogd_nflog_group }} --nflog-prefix "[iptables ACCEPT] "
|
|
|
|
{% else %}
|
2019-08-25 02:06:19 +00:00
|
|
|
-A LOG_ACCEPT -m limit --limit {{ firewall_log_limit }} --limit-burst {{ firewall_log_limit_burst }} -j LOG --log-prefix "[iptables ACCEPT] " --log-level info
|
2019-09-02 17:50:56 +00:00
|
|
|
{% endif %}
|
2019-08-25 02:06:19 +00:00
|
|
|
-A LOG_ACCEPT -j ACCEPT
|
|
|
|
|
2019-08-27 05:35:14 +00:00
|
|
|
-N LOG_DROP
|
2019-09-02 17:51:48 +00:00
|
|
|
-A LOG_DROP -j NFLOG --nflog-group {{ firewall_iptables_nflog_group }}
|
2019-09-02 17:50:56 +00:00
|
|
|
{% if firewall_use_ulogd %}
|
|
|
|
-A LOG_DROP -m limit --limit {{ firewall_log_limit }} --limit-burst {{ firewall_log_limit_burst }} -j NFLOG --nflog-group {{ firewall_ulogd_nflog_group }} --nflog-prefix "[iptables DROP] "
|
|
|
|
{% else %}
|
2019-08-25 02:06:19 +00:00
|
|
|
-A LOG_DROP -m limit --limit {{ firewall_log_limit }} --limit-burst {{ firewall_log_limit_burst }} -j LOG --log-prefix "[iptables DROP] " --log-level info
|
2019-09-02 17:50:56 +00:00
|
|
|
{% endif %}
|
2019-08-27 05:35:14 +00:00
|
|
|
-A LOG_DROP -p tcp -m tcp -m comment --comment "reject tcp" -j REJECT --reject-with tcp-reset
|
|
|
|
-A LOG_DROP -p udp -m udp -m comment --comment "drop udp" -j DROP
|
|
|
|
-A LOG_DROP -m comment --comment "reject all" -j REJECT --reject-with icmp-admin-prohibited
|
|
|
|
|
|
|
|
{% if firewall_limit_ssh %}
|
|
|
|
-N LIMIT_SSH
|
2019-09-02 17:54:36 +00:00
|
|
|
-A LIMIT_SSH -p tcp -m tcp -m set --match-set cooloff_v4 src -m comment --comment "rate limit ssh 22/tcp" -j REJECT --reject-with tcp-reset
|
2019-08-27 05:35:14 +00:00
|
|
|
-A LIMIT_SSH -m recent --set --name SSH --rsource
|
2019-09-02 17:50:56 +00:00
|
|
|
{% if firewall_use_ulogd %}
|
|
|
|
-A LIMIT_SSH -m recent --update --seconds {{ firewall_limit_ssh_seconds }} --hitcount {{ firewall_limit_ssh_hitcount }} --name SSH --rsource -m limit --limit {{ firewall_log_limit }} --limit-burst {{ firewall_log_limit_burst }} -j NFLOG --nflog-prefix "[iptables SSH BRUTE] "
|
|
|
|
{% else %}
|
2019-08-27 05:35:14 +00:00
|
|
|
-A LIMIT_SSH -m recent --update --seconds {{ firewall_limit_ssh_seconds }} --hitcount {{ firewall_limit_ssh_hitcount }} --name SSH --rsource -m limit --limit {{ firewall_log_limit }} --limit-burst {{ firewall_log_limit_burst }} -j LOG --log-prefix "[iptables SSH BRUTE] " --log-level info
|
2019-09-02 17:50:56 +00:00
|
|
|
{% endif %}
|
2019-08-30 02:34:58 +00:00
|
|
|
-A LIMIT_SSH -p tcp -m tcp -m recent --update --seconds {{ firewall_limit_ssh_seconds }} --hitcount {{ firewall_limit_ssh_hitcount }} --name SSH --rsource -j SET --add-set cooloff_v4 src
|
2019-08-27 05:35:14 +00:00
|
|
|
-A LIMIT_SSH -j ACCEPT
|
|
|
|
{% endif %}
|
2019-08-25 02:06:19 +00:00
|
|
|
|
|
|
|
{% if firewall_drop_icmp_flood %}
|
|
|
|
-N ICMP_FLOOD
|
|
|
|
-A ICMP_FLOOD -m recent --set --name ICMP --rsource
|
2019-09-02 17:50:56 +00:00
|
|
|
{% if firewall_use_ulogd %}
|
|
|
|
-A ICMP_FLOOD -m recent --update --seconds {{ firewall_limit_icmp_flood_seconds }} --hitcount {{ firewall_limit_icmp_flood_hitcount }} --name ICMP --rsource --rttl -m limit --limit {{ firewall_log_limit }} --limit-burst {{ firewall_log_limit_burst }} -j NFLOG --nflog-prefix "[iptables ICMP FLOOD] "
|
|
|
|
{% else %}
|
2019-08-27 06:08:19 +00:00
|
|
|
-A ICMP_FLOOD -m recent --update --seconds {{ firewall_limit_icmp_flood_seconds }} --hitcount {{ firewall_limit_icmp_flood_hitcount }} --name ICMP --rsource --rttl -m limit --limit {{ firewall_log_limit }} --limit-burst {{ firewall_log_limit_burst }} -j LOG --log-prefix "[iptables ICMP FLOOD] " --log-level info
|
2019-09-02 17:50:56 +00:00
|
|
|
{% endif %}
|
2019-08-27 06:08:19 +00:00
|
|
|
-A ICMP_FLOOD -m recent --update --seconds {{ firewall_limit_icmp_flood_seconds }} --hitcount {{ firewall_limit_icmp_flood_hitcount }} --name ICMP --rsource --rttl -m comment --comment "drop icmp flood" -j REJECT --reject-with icmp-admin-prohibited
|
2019-08-25 02:06:19 +00:00
|
|
|
-A ICMP_FLOOD -j ACCEPT
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
-A INPUT -i lo -m comment --comment "lo accept all" -j ACCEPT
|
|
|
|
|
2019-08-27 06:08:19 +00:00
|
|
|
-A INPUT -m state --state INVALID -m comment --comment "drop invalid" -j DROP
|
2019-08-27 05:35:14 +00:00
|
|
|
|
|
|
|
{% if firewall_ipset_mgmt.v4 is defined %}
|
2019-08-27 06:08:19 +00:00
|
|
|
-A INPUT -p tcp -m tcp --dport 22 -m set --match-set mgmt_v4 src -m comment --comment "accept mgmt ssh 22/tcp" -j ACCEPT
|
2019-08-27 05:35:14 +00:00
|
|
|
{% endif %}
|
2019-08-25 02:06:19 +00:00
|
|
|
|
2019-08-27 05:35:14 +00:00
|
|
|
{% if firewall_ipset_blacklist.v4 is defined %}
|
2019-08-25 02:06:19 +00:00
|
|
|
-A INPUT -m set --match-set mgmt_v4 src -m comment --comment "drop blacklist" -j LOG_DROP
|
2019-08-27 05:35:14 +00:00
|
|
|
{% endif %}
|
2019-08-25 02:06:19 +00:00
|
|
|
|
2019-08-27 05:35:14 +00:00
|
|
|
{% if firewall_ipset_bogons.v4 is defined %}
|
2019-08-25 02:06:19 +00:00
|
|
|
-A INPUT -i {{ firewall_bogon_interface }} -m set --match-set bogons_v4 src,dst -m comment --comment "drop bogons" -j LOG_DROP
|
2019-08-27 05:35:14 +00:00
|
|
|
{% endif %}
|
2019-08-25 02:06:19 +00:00
|
|
|
|
|
|
|
-A INPUT -p icmp -m icmp --icmp-type destination-unreachable -m comment --comment "accept icmp destination-unreachable" -j ACCEPT
|
|
|
|
-A INPUT -p icmp -m icmp --icmp-type time-exceeded -m comment --comment "accept icmp time-exceeded" -j ACCEPT
|
|
|
|
-A INPUT -p icmp -m icmp --icmp-type parameter-problem -m comment --comment "accept icmp parameter-problem" -j ACCEPT
|
|
|
|
{% if firewall_drop_icmp_flood %}
|
|
|
|
-A INPUT -p icmp -m icmp --icmp-type echo-request -m comment --comment "accept icmp echo-request" -j ICMP_FLOOD
|
|
|
|
{% else %}
|
|
|
|
-A INPUT -p icmp -m icmp --icmp-type echo-request -m comment --comment "accept icmp echo-request" -j ACCEPT
|
|
|
|
{% endif %}
|
|
|
|
-A INPUT -p icmp -m icmp --icmp-type echo-reply -m comment --comment "accept icmp echo-reply" -j ACCEPT
|
|
|
|
|
|
|
|
{% for type in firewall_allowed_icmp_types.v4 | default([]) %}
|
|
|
|
-A INPUT -p icmp -m icmp --icmp-type {{ type }} -m comment --comment "accept icmp {{ type }}" -j ACCEPT
|
|
|
|
{% endfor %}
|
|
|
|
|
2019-08-27 05:35:14 +00:00
|
|
|
{% if firewall_limit_ssh %}
|
2019-08-27 06:08:19 +00:00
|
|
|
-A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m comment --comment "accept ssh 22/tcp" -j LIMIT_SSH
|
2019-08-27 05:35:14 +00:00
|
|
|
{% else %}
|
2019-08-27 06:08:19 +00:00
|
|
|
-A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m comment --comment "accept ssh 22/tcp" -j ACCEPT
|
2019-08-27 05:35:14 +00:00
|
|
|
{% endif %}
|
|
|
|
|
2019-08-25 02:06:19 +00:00
|
|
|
{% for port in firewall_allowed_tcp_ports.v4 | default([]) %}
|
|
|
|
-A INPUT -p tcp -m tcp --dport {{ port }} -m comment --comment "accept {{ port }}/tcp" -j ACCEPT
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% for port in firewall_allowed_udp_ports.v4 | default([]) %}
|
|
|
|
-A INPUT -p udp -m udp --dport {{ port }} -m comment --comment "accept {{ port }}/udp" -j ACCEPT
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
-A INPUT -m state --state RELATED,ESTABLISHED -m comment --comment "accept related/established" -j ACCEPT
|
|
|
|
|
2019-08-27 06:08:19 +00:00
|
|
|
-A INPUT -m comment --comment "default drop" -j LOG_DROP
|
2019-09-02 17:54:06 +00:00
|
|
|
|
|
|
|
-A FORWARD -m comment --comment "default forward drop" -j LOG_DROP
|
|
|
|
|
|
|
|
-A OUTPUT -m comment --comment "default output accept" -j ACCEPT
|
2019-08-30 00:33:49 +00:00
|
|
|
COMMIT
|
2019-08-25 02:06:19 +00:00
|
|
|
|
2019-08-30 00:33:49 +00:00
|
|
|
*raw
|
|
|
|
:PREROUTING ACCEPT -
|
|
|
|
:OUTPUT ACCEPT -
|
|
|
|
{% if firewall_loopback_notrack %}
|
|
|
|
-A PREROUTING -i lo -j NOTRACK
|
|
|
|
-A OUTPUT -o lo -j NOTRACK
|
|
|
|
{% endif %}
|
2019-08-25 02:06:19 +00:00
|
|
|
COMMIT
|
2019-08-27 06:08:19 +00:00
|
|
|
|
|
|
|
# vim: tw=0
|