I'm trying to set up iptables for 2 purposes:
- configure NAT (my gentoo box is a gateway)
- protect my computers
I read some articles / tutorials about iptables, and I reached this file:
Code: Select all
/bin/echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t filter -F
iptables -t filter -X
iptables -t filter -P INPUT DROP
#iptables -t filter -P FORWARD DROP
iptables -t filter -P OUTPUT DROP
iptables -t nat -F
iptables -t nat -X
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t mangle -F
iptables -t mangle -X
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P INPUT ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
iptables -t mangle -P FORWARD ACCEPT
iptables -t mangle -P POSTROUTING ACCEPT
# accept everything from lo & LAN
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A OUTPUT -o eth1 -j ACCEPT
#iptables -t filter -A INPUT -i eth0 -m state --state ESTABLISHED -p tcp --sport 80 -j ACCEPT
#iptables -t filter -A OUTPUT -o eth0 -m state --state NEW,ESTABLISHED -p tcp --dport 80 -j ACCEPT
#iptables -t filter -A INPUT -i eth0 -m state --state ESTABLISHED -p tcp -m multiport --sport 22,80,443 -j ACCEPT
#iptables -t filter -A OUTPUT -o eth0 -m state --state NEW,ESTABLISHED -p tcp -m multiport --dport 22,80,443 -j ACCEPT
#iptables -t filter -A INPUT -i eth0 -m state --state ESTABLISHED -p icmp -j ACCEPT
#iptables -t filter -A OUTPUT -o eth0 -m state --state NEW,ESTABLISHED -p icmp -j ACCEPT
#Since the 6 previous lines won't work (except icmp), forget about security until solution is found
iptables -A INPUT -i eth0 -j ACCEPT
iptables -A OUTPUT -o eth0 -j ACCEPT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
#the following lines won't let traffic pass, if iptables -t filter -P FORWARD DROP is set
#iptables -A FORWARD -i eth1 -o eth0 -m state --state NEW,ESTABLISHED -j ACCEPT
#iptables -A FORWARD -i eth1 -o eth0 -m state --state ESTABLISHED -j ACCEPT
(1) NAT works if the line #iptables -t filter -P FORWARD DROP is commented out. The 2 last lines of my config can't allow the traffic from the NATed computers if I wrote iptables -t filter -P FORWARD DROP before.
(2) The 6 lines about the filter rules are problematic: the 4 first lines won't allow anything for ssh, http or https. But the 2 last lines about icmp work, I can ping the internet from my server.
I've then been searching for solutions to those 2 problems.
My temporary solution to the (1) problem is to comment out the iptables -t filter -P FORWARD DROP line, so the NATed comupters can access the internet.
My temporary solution to the (2) problem is to accept everything from eth0, which isn't a good idea, but the only way to have currently an internet connection.
Any suggestions would be welcome.
Thanks already.
Blutch
[EDIT]
I forgot to tell:
eth0 is my internet interface
eth1 is my LAN interface
I'm using iptables v1.3.5


