User Tools

Site Tools


networking:firewall:arno_s_firewall

This is an old revision of the document!


Arno's Firewall

Install

Verify current network setup:

ifconfig						#show network interfaces
route -n						#show routing
iptables -nL |grep ACCEPT				#show 'allow' rules
iptables -t nat -n -L					#show NAT rules

Additional for CentOS minimal installations:

yum install wget which bind-utils

Install:

wget http://rocky.eld.leidenuniv.nl/arno-iptables-firewall/arno-iptables-firewall_2.0.1d.tar.gz

tar -xzvf arno-iptables-firewall<tab>
cd arno-iptables-firewall<tab>
./install.sh

The install script calls the configure script at the end:

/root/arno-iptables-firewall_2.0.1d/configure.sh

service arno-iptables-firewall start

Configure

Startup verbosity:

vim /etc/init.d/arno-iptables-firewall

Firewall:

vim /etc/arno-iptables-firewall/firewall.conf

# open from anywhere
OPEN_TCP="2222"
# limited by source address
HOST_OPEN_TCP="209.193.64.254~80,443,10000:10010 109.169.59.200,209.104.9.39~389,636"

service arno-iptables-firewall restart

iptables -nL | grep ACCEPT

Logging

Logging defaults to /var/log/messages. Here we configure logging to a separate file /var/log/firewall.log.

Edit /etc/arno-iptables-firewall/firewall.conf and change:

FIREWALL_LOG="/var/log/firewall.log"
LOGLEVEL="debug"	# if you want the highest level of logging

Then configure log rotation:

cat << EOF >> /etc/logrotate.d/firewall
/var/log/firewall.log {
        rotate 4
        weekly
        compress
        notifempty
        create 0600 root root
        delaycompress
        create
}
EOF

cat << EOF >> /etc/syslog.conf

# Log all iptables messages to /var/log/firewall.log
kern.=debug                                             /var/log/firewall.log
EOF

kill -HUP $(pidof syslogd)

arno-iptables-firewall check-conf

service arno-iptables-firewall restart

Auto Startup

chkconfig arno-iptables-firewall on
chkconfig iptables off
chkconfig ip6tables off

Port Check

iptables -nL | grep 2222
iptables -nL|grep ACCEPT

Restart

service iptables stop
service ip6tables stop
service arno-iptables-firewall restart

Adaptive Ban Plugin

The new Adaptive Ban plugin uses the same technique as fail2ban ( http://www.fail2ban.org ).

Example Plugin Settings

--- snip ---

# ------------------------------------------------------------------------------
#            -= Arno's iptables firewall - Adaptive Ban plugin =-
# ------------------------------------------------------------------------------

# To actually enable this plugin make ENABLED=1:
# ------------------------------------------------------------------------------
ENABLED=1

# Log file where failed access attempts are derived
# ------------------------------------------------------------------------------
ADAPTIVE_BAN_FILE="/var/log/messages"

# The time in seconds between each iteration of analyzing the log file
# ------------------------------------------------------------------------------
ADAPTIVE_BAN_TIME=90

# The number of log failures to ban host
# ------------------------------------------------------------------------------
ADAPTIVE_BAN_COUNT=6

# A list of analysis types that are applied
# Choose from: sshd asterisk mini_httpd
# ------------------------------------------------------------------------------
ADAPTIVE_BAN_TYPES="asterisk"

# By default, inbound packets from banned IP addresses will be silently DROP'ed
# As an option, the packets can be REJECT'ed instead of being DROP'ed
# Define ADAPTIVE_BAN_REJECT=1 for an ICMP error message to be returned
# ------------------------------------------------------------------------------
ADAPTIVE_BAN_REJECT=1

# Bt default, INTERNAL (LAN) networks will be whitelisted against banning
# As an option, this automatic whitelisting can be disabled
# Define ADAPTIVE_BAN_WHITELIST_INTERNAL=0 to disable INTERNAL whitelisting
# ------------------------------------------------------------------------------
ADAPTIVE_BAN_WHITELIST_INTERNAL=1

# Whitelist Hosts
# A list of IP addresses whose traffic will never be banned
# ------------------------------------------------------------------------------
ADAPTIVE_BAN_WHITELIST=""

--- snip ---

Block Hosts (Blackhole)

vim /etc/arno-iptables-firewall/firewall.conf
# Put in the following variable which hosts you want to block (blackhole,
# dropping every packet from the host).
# -----------------------------------------------------------------------------
BLOCK_HOSTS="217.16.182.187"
/etc/init.d/arno-iptables-firewall restart
networking/firewall/arno_s_firewall.1658434530.txt.gz · Last modified: 2022/07/21 14:15 by gcooper