#!/bin/sh # Server.firewall - Version 2.3 # This script configures the firewall and saves the results. # H.V. Sparks, July 2007 # Devices netDev=eth0 lanDev=eth1 # Hosts thisServer=192.168.0.2 otherServer=192.168.1.3 # Kernel flags echo 1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses echo 1 > /proc/sys/net/ipv4/tcp_syncookies echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects # For Dynamic PPP: echo 1 > /proc/sys/net/ipv4/ip_dynaddr # Flush all tables iptables -t filter -F iptables -t filter -X iptables -t filter -Z iptables -t nat -F iptables -t nat -X iptables -t nat -Z iptables -t mangle -F iptables -t mangle -X iptables -t mangle -Z # Set default policies iptables -t filter -P INPUT DROP iptables -t filter -P FORWARD DROP iptables -t filter -P OUTPUT ACCEPT iptables -t nat -P PREROUTING ACCEPT iptables -t nat -P POSTROUTING ACCEPT iptables -t nat -P OUTPUT ACCEPT iptables -t mangle -P PREROUTING ACCEPT iptables -t mangle -P OUTPUT ACCEPT # Chain for bad tcp packets iptables -N badTCP # Stop sequence prediction attacks iptables -A badTCP -p tcp --tcp-flags SYN,ACK SYN,ACK -m state \ --state NEW -j REJECT --reject-with tcp-reset # Drop new packets that are not connection requests iptables -A badTCP -p tcp ! --syn -m state --state NEW -j DROP # Blocklist to deal with "special people" iptables -N blockList for ip in `