First commit for Spacewalk Ansible roles
This commit is contained in:
79
roles/iptables/templates/firewall.bash.j2
Executable file
79
roles/iptables/templates/firewall.bash.j2
Executable file
@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
# iptables firewall for common LAMP servers.
|
||||
#
|
||||
# This file should be located at /etc/firewall.bash, and is meant to work with
|
||||
# Jeff Geerling's firewall init script.
|
||||
#
|
||||
# Common port reference:
|
||||
# 22: SSH
|
||||
# 25: SMTP
|
||||
# 80: HTTP
|
||||
# 123: DNS
|
||||
# 443: HTTPS
|
||||
# 2222: SSH alternate
|
||||
# 4949: Munin
|
||||
# 6082: Varnish admin
|
||||
# 8080: HTTP alternate (often used with Tomcat)
|
||||
# 8983: Tomcat HTTP
|
||||
# 8443: Tomcat HTTPS
|
||||
# 9000: SonarQube
|
||||
#
|
||||
# @author Jeff Geerling
|
||||
|
||||
# No spoofing.
|
||||
if [ -e /proc/sys/net/ipv4/conf/all/rp_filter ]
|
||||
then
|
||||
for filter in /proc/sys/net/ipv4/conf/*/rp_filter
|
||||
do
|
||||
echo 1 > $filter
|
||||
done
|
||||
fi
|
||||
|
||||
# Remove all rules and chains.
|
||||
iptables -F
|
||||
iptables -X
|
||||
|
||||
# Accept traffic from loopback interface (localhost).
|
||||
iptables -A INPUT -i lo -j ACCEPT
|
||||
|
||||
# Forwarded ports.
|
||||
{# Add a rule for each forwarded port #}
|
||||
{% for forwarded_port in firewall_forwarded_tcp_ports %}
|
||||
iptables -t nat -I PREROUTING -p tcp --dport {{ forwarded_port.src }} -j REDIRECT --to-port {{ forwarded_port.dest }}
|
||||
{% endfor %}
|
||||
{% for forwarded_port in firewall_forwarded_udp_ports %}
|
||||
iptables -t nat -I PREROUTING -p udp --dport {{ forwarded_port.src }} -j REDIRECT --to-port {{ forwarded_port.dest }}
|
||||
{% endfor %}
|
||||
|
||||
# Open ports.
|
||||
{# Add a rule for each open port #}
|
||||
{% for port in firewall_allowed_tcp_ports %}
|
||||
iptables -A INPUT -p tcp -m tcp --dport {{ port }} -j ACCEPT
|
||||
{% endfor %}
|
||||
{% for port in firewall_allowed_udp_ports %}
|
||||
iptables -A INPUT -p tcp -m udp --dport {{ port }} -j ACCEPT
|
||||
{% endfor %}
|
||||
|
||||
# Accept icmp ping requests.
|
||||
iptables -A INPUT -p icmp -j ACCEPT
|
||||
|
||||
# Allow NTP traffic for time synchronization.
|
||||
iptables -A OUTPUT -p udp --dport 123 -j ACCEPT
|
||||
iptables -A INPUT -p udp --sport 123 -j ACCEPT
|
||||
|
||||
# Additional custom rules.
|
||||
{% for rule in firewall_additional_rules %}
|
||||
{{ rule }}
|
||||
{% endfor %}
|
||||
|
||||
# Allow established connections:
|
||||
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
|
||||
|
||||
# Log EVERYTHING (ONLY for Debug).
|
||||
# iptables -A INPUT -j LOG
|
||||
|
||||
# Log other incoming requests (all of which are dropped) at 15/minute max.
|
||||
iptables -A INPUT -m limit --limit 15/minute -j LOG --log-level 7 --log-prefix "Dropped by firewall: "
|
||||
|
||||
# Drop all other traffic.
|
||||
iptables -A INPUT -j DROP
|
41
roles/iptables/templates/firewall.j2
Executable file
41
roles/iptables/templates/firewall.j2
Executable file
@ -0,0 +1,41 @@
|
||||
#! /bin/sh
|
||||
# /etc/init.d/firewall
|
||||
#
|
||||
# Firewall init script, to be used with /etc/firewall.bash by Jeff Geerling.
|
||||
#
|
||||
# @author Jeff Geerling
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: firewall
|
||||
# Required-Start: $remote_fs $syslog
|
||||
# Required-Stop: $remote_fs $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Short-Description: Start firewall at boot time.
|
||||
# Description: Enable the firewall.
|
||||
### END INIT INFO
|
||||
|
||||
# Carry out specific functions when asked to by the system
|
||||
case "$1" in
|
||||
start)
|
||||
echo "Starting firewall."
|
||||
/etc/firewall.bash
|
||||
;;
|
||||
stop)
|
||||
echo "Stopping firewall."
|
||||
iptables -F
|
||||
;;
|
||||
restart)
|
||||
echo "Restarting firewall."
|
||||
/etc/firewall.bash
|
||||
;;
|
||||
status)
|
||||
echo -e "`iptables -L -n`"
|
||||
;;
|
||||
*)
|
||||
echo "Usage: /etc/init.d/firewall {start|stop|status|restart}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
exit 0
|
Reference in New Issue
Block a user