Quote:
Originally posted by dalek
Remember that this is not my strong point here. So all I can say is, Huh???? What is all that? NAT is network address table or something I think.
|
I must admit I am new too this as well and it's not my strong point too. The nat module when loaded helps iptables interact with the nat table, plus i should have mentioned that there are a few more modules that you load as well which make the firewall a stateful packet inspection (SPI) and also allow you to masquerade the internal hosts ip's to the external ip address.
A simple script which is part of one i'm currently working and similar to the rules you posted earlier, has no logging rules but loads alot of modules should work ok to get started with:
#!/bin/sh
IPTABLES="/sbin/iptables"
INTERNET="eth1"
LOCAL="eth0"
dmesg -n 1 ## Kill copyright display on module load
dmesg -n 6
/sbin/modprobe ip_tables
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_mangle
/sbin/modprobe iptable_nat
/sbin/modprobe ipt_TOS
/sbin/modprobe ip_conntrack
/sbin/modprobe ip_nat_irc
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_conntrack_irc
/sbin/modprobe ipt_limit
/sbin/modprobe ipt_state
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_MASQUERADE
/sbin/modprobe ipt_mac
echo "1" > /proc/sys/net/ipv4/ip_forward
echo "1" > /proc/sys/net/ipv4/conf/all/rp_filter
echo "1" > /proc/sys/net/ipv4/conf/all/log_martians
echo 0 > /proc/sys/net/ipv4/tcp_timestamps
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo "0" > /proc/sys/net/ipv4/conf/all/accept_source_route
echo "0" > /proc/sys/net/ipv4/conf/all/send_redirects
echo "0" > /proc/sys/net/ipv4/tcp_ecn
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
echo "0" > /proc/sys/net/ipv4/conf/all/accept_redirects
echo "0" > /proc/sys/net/ipv4/conf/all/secure_redirects
#128 MB of RAM -> 8192 possible entries, 256 MB of RAM --> 16376 possible entries, etc...
echo 8192 > /proc/sys/net/ipv4/ip_conntrack_max
echo 10 > /proc/sys/net/ipv4/tcp_fin_timeout
echo 1800 > /proc/sys/net/ipv4/tcp_keepalive_time
echo 0 > /proc/sys/net/ipv4/tcp_window_scaling
echo 0 > /proc/sys/net/ipv4/tcp_sack
echo 15 > /proc/sys/net/ipv4/ipfrag_time
echo 2048 > /proc/sys/net/ipv4/tcp_max_syn_backlog
echo "32768 61000" > /proc/sys/net/ipv4/ip_local_port_range
echo "2" > /proc/sys/net/ipv4/tcp_synack_retries
#echo "1" > /proc/sys/net/ipv4/ip_dynaddr# Uncomment if you get your external ip from DHCP server
fi
## Reduce DoS'ing ability by reducing timeouts
echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout
echo 2400 > /proc/sys/net/ipv4/tcp_keepalive_time
echo 0 > /proc/sys/net/ipv4/tcp_window_scaling
echo 0 > /proc/sys/net/ipv4/tcp_sack
echo "Module options set"
$IPTABLES -F
$IPTABLES -F -t mangle
$IPTABLES -F -t nat
$IPTABLES -X
$IPTABLES -X -t mangle
$IPTABLES -X -t nat
$IPTABLES -t nat -P POSTROUTING ACCEPT
$IPTABLES -t nat -P PREROUTING ACCEPT
$IPTABLES -t nat -P OUTPUT ACCEPT
## Set default policies to DROP
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD DROP
$IPTABLES -P OUTPUT ACCEPT
##################General rules##################
# INTERNET SIDE
# Allow only established or related from the internet
$IPTABLES -A FORWARD -o $LOCAL -m state --state ESTABLISHED,RELATED -j ACCEPT
# Drop anyone from the internet trying to connect to the router itself
$IPTABLES -A INPUT -i $INTERNET -j DROP
#############################################################
# LAN SIDE
# Allow all from the internal network out to the internet
$IPTABLES -A FORWARD -o $INTERNET -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
# Allow the internal hosts to connect to the router
$IPTABLES -A INPUT -i $LOCAL -j -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
#############################################################
# Lets masquerade the internal hosts ip address to the external ip address
# Uncomment which one applies to your setup
# If you get your external ip address assigned by a DHCP server
#$IPTABLES -t nat -A POSTROUTING -o $INTERNET -j MASQUERADE
# If your external ip address is static
#$IPTABLES -t nat -A POSTROUTING -o $INTERNET -j SNAT --to-source x.x.x.x
exit 0
#########END OF SCRIPT#############