[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

iptables script review



Hi, I have a home server and workstation. Values used in LTSP setup are
Server: 192.168.0.1
WS01: 192.168.0.2
Gateway: 192.168.0.1

I have used Oskar Andreasson's rc.firewall.txt
<http://iptables-tutorial.frozentux.net/scripts/rc.firewall.txt>
script as a template
 <
http://iptables-tutorial.frozentux.net/iptables-tutorial.html#RCFIREWALLTXT
>
but can't connect to the net after running
/home/adam$ ./iptables
unless I then run the 'flush-iptables' script.

I'm fairly sure there is a simple error here. LTSP values and Oskar's
script should be right but
I may have bungled  INET_BROADCAST and LAN_IP_RANGE

I'd be grateful if someone could tell me where I've gone wrong.

Adam Bogacki,
afb@paradise.net.nz

> #!/bin/sh
>
>
> INET_IP="192.168.0.1"
> INET_IFACE="eth0"
> INET_BROADCAST="192.168.0.100"
>
> LAN_IP="192.168.0.2"
> LAN_IP_RANGE="192.168.0.0/16"
> LAN_IFACE="eth1"
>
> LO_IFACE="lo"
> LO_IP="127.0.0.1"
>
> IPTABLES="/usr/sbin/iptables"
>
> /sbin/depmod -a
>
> /sbin/modprobe ip_tables
> /sbin/modprobe ip_conntrack
> /sbin/modprobe iptable_filter
> /sbin/modprobe iptable_mangle
> /sbin/modprobe iptable_nat
> /sbin/modprobe ipt_LOG
> /sbin/modprobe ipt_limit
> /sbin/modprobe ipt_state
>
>
> echo "1" > /proc/sys/net/ipv4/ip_forward
>
> iptables -P INPUT DROP
> iptables -P OUTPUT DROP
> iptables -P FORWARD DROP
>
> iptables -N bad_tcp_packets
>
> iptables -N allowed
> iptables -N tcp_packets
> iptables -N udp_packets
> iptables -N icmp_packets
>
> iptables -A bad_tcp_packets -p tcp --tcp-flags SYN,ACK SYN,ACK \
> -m state --state NEW -j REJECT --reject-with tcp-reset
> iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j LOG \
> --log-prefix "New not syn:"
> iptables -A bad_tcp_packets -p tcp ! --syn -m state --state NEW -j DROP
>
> iptables -A allowed -p TCP --syn -j ACCEPT
> iptables -A allowed -p TCP -m state --state ESTABLISHED,RELATED -j
> ACCEPT
> iptables -A allowed -p TCP -j DROP
>
> iptables -A tcp_packets -p TCP -s 0/0 --dport 21 -j allowed
> iptables -A tcp_packets -p TCP -s 0/0 --dport 22 -j allowed
> iptables -A tcp_packets -p TCP -s 0/0 --dport 80 -j allowed
> iptables -A tcp_packets -p TCP -s 0/0 --dport 113 -j allowed
>
> #$IPTABLES -A udp_packets -p UDP -s 0/0 --destination-port 53 -j ACCEPT
> #$IPTABLES -A udp_packets -p UDP -s 0/0 --destination-port 123 -j ACCEPT
> iptables -A udp_packets -p UDP -s 0/0 --destination-port 2074 -j ACCEPT
> iptables -A udp_packets -p UDP -s 0/0 --destination-port 4000 -j ACCEPT
>
> iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 8 -j ACCEPT
> iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT
>
> iptables -A INPUT -p tcp -j bad_tcp_packets
>
> iptables -A INPUT -p ALL -i $LAN_IFACE -s $LAN_IP_RANGE -j ACCEPT
> iptables -A INPUT -p ALL -i $LO_IFACE -s $LO_IP -j ACCEPT
> iptables -A INPUT -p ALL -i $LO_IFACE -s $LAN_IP -j ACCEPT
> iptables -A INPUT -p ALL -i $LO_IFACE -s $INET_IP -j ACCEPT
>
> iptables -A INPUT -p UDP -i $LAN_IFACE --dport 67 --sport 68 -j ACCEPT
>
> iptables -A INPUT -p ALL -d $INET_IP -m state --state
> ESTABLISHED,RELATED \
> -j ACCEPT
> iptables -A INPUT -p TCP -i $INET_IFACE -j tcp_packets
> iptables -A INPUT -p UDP -i $INET_IFACE -j udp_packets
> iptables -A INPUT -p ICMP -i $INET_IFACE -j icmp_packets
>
> iptables -A INPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
> --log-level DEBUG --log-prefix "IPT INPUT packet died: "
>
> iptables -A FORWARD -p tcp -j bad_tcp_packets
>
> iptables -A FORWARD -i $LAN_IFACE -j ACCEPT
> iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
>
> iptables -A FORWARD -p tcp -j LOG --log-tcp-options
> iptables -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j LOG \
> --log-level DEBUG --log-prefix "IPT FORWARD packet died: "
>
> iptables -A OUTPUT -p tcp -j bad_tcp_packets
>
> iptables -A OUTPUT -p ALL -s $LO_IP -j ACCEPT
> iptables -A OUTPUT -p ALL -s $LAN_IP -j ACCEPT
> iptables -A OUTPUT -p ALL -s $INET_IP -j ACCEPT
>
> iptables -A OUTPUT -m limit --limit 3/minute --limit-burst 3 -j LOG \
> --log-level DEBUG --log-prefix "IPT OUTPUT packet died: "
>
> iptables -t nat -A POSTROUTING -o $INET_IFACE -j SNAT --to-source
> $INET_IP
>
>
'iptables-save' gives me

> Tux:/home/adam# iptables-save
> # Generated by iptables-save v1.3.1 on Sun Jul 24 21:50:45 2005
> *mangle
> :PREROUTING ACCEPT [21493:19009893]
> :INPUT ACCEPT [21489:19009487]
> :FORWARD ACCEPT [0:0]
> :OUTPUT ACCEPT [19249:2744637]
> :POSTROUTING ACCEPT [19387:2768585]
> COMMIT
> # Completed on Sun Jul 24 21:50:45 2005
> # Generated by iptables-save v1.3.1 on Sun Jul 24 21:50:45 2005
> *filter
> :INPUT DROP [0:0]
> :FORWARD DROP [0:0]
> :OUTPUT DROP [0:0]
> -A INPUT -i lo -j ACCEPT
> -A INPUT -s 127.0.0.0/255.0.0.0 -i ! lo -j LOG
> -A INPUT -s 127.0.0.0/255.0.0.0 -i ! lo -j DROP
> -A INPUT -d 255.255.255.255 -i eth1 -j ACCEPT
> -A INPUT -s 192.168.0.0/255.255.255.0 -i eth1 -j ACCEPT
> -A INPUT -d 224.0.0.0/240.0.0.0 -i eth1 -p ! tcp -j ACCEPT
> -A INPUT -s 192.168.0.0/255.255.255.0 -i eth0 -j LOG
> -A INPUT -s 192.168.0.0/255.255.255.0 -i eth0 -j DROP
> -A INPUT -d 255.255.255.255 -i eth0 -j ACCEPT
> -A INPUT -d 203.79.110.81 -i eth0 -j ACCEPT
> -A INPUT -d 203.79.110.255 -i eth0 -j ACCEPT
> -A INPUT -j LOG
> -A INPUT -j DROP
> -A FORWARD -s 192.168.0.0/255.255.255.0 -i eth1 -o eth0 -j ACCEPT
> -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
> -A FORWARD -d 192.168.0.0/255.255.255.0 -o eth0 -j LOG
> -A FORWARD -d 192.168.0.0/255.255.255.0 -o eth0 -j DROP
> -A FORWARD -j LOG
> -A FORWARD -j DROP
> -A OUTPUT -o lo -j ACCEPT
> -A OUTPUT -d 255.255.255.255 -o eth1 -j ACCEPT
> -A OUTPUT -d 192.168.0.0/255.255.255.0 -o eth1 -j ACCEPT
> -A OUTPUT -d 224.0.0.0/240.0.0.0 -o eth1 -p ! tcp -j ACCEPT
> -A OUTPUT -d 192.168.0.0/255.255.255.0 -o eth0 -j LOG
> -A OUTPUT -d 192.168.0.0/255.255.255.0 -o eth0 -j DROP
> -A OUTPUT -d 255.255.255.255 -o eth0 -j ACCEPT
> -A OUTPUT -s 203.79.110.81 -o eth0 -j ACCEPT
> -A OUTPUT -s 203.79.110.255 -o eth0 -j ACCEPT
> -A OUTPUT -j LOG
> -A OUTPUT -j DROP
> COMMIT
> # Completed on Sun Jul 24 21:50:47 2005
> # Generated by iptables-save v1.3.1 on Sun Jul 24 21:50:47 2005
> *nat
> :PREROUTING ACCEPT [218:16878]
> :POSTROUTING ACCEPT [1309:90379]
> :OUTPUT ACCEPT [1309:90379]
> -A POSTROUTING -s 192.168.0.0/255.255.255.0 -o eth0 -j MASQUERADE
> COMMIT
> # Completed on Sun Jul 24 21:50:48 2005
> Tux:/home/adam#
>





 



Reply to: