Skip to contentSkip to conversation

What's going on with my iptables?

DISCUSSION Jack Knowlton 3 participants 7 messages May 1, 2010 – May 4, 2010

lore
Share & tools
lore
#0 lore raw

Hi all.
Couple years ago I set up a very basic script to have a machine (running Debian SID) on my network to act as a router. Two network interfaces, one with a public IP and the other on the local LAN subnet. It does NAT as well
as open some inbound ports (SSH, WWW).
Yesterday, at roughly 4PM, the firewall setup stopped working. I was still able to forward packets from a LAN client, but any connection originating from the box itself could not be established.
I tried ping and traceroute but none of them went through.

This is my firewall script:

Quoted 40 lines

#!/bin/sh

# Interface connected to Internet
INTERNET="eth1"

# Address connected to LAN
LOCAL="10.0.1.0/24"

# OpenVPN
OV="172.16.0.0/16"

# Clean old firewall
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X

# Load IPTABLES modules for NAT and IP conntrack support modprobe ip_conntrack
modprobe ip_conntrack_ftp

# Enable Forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Enable Munin stats
iptables -A INPUT -d PUBIP
iptables -A OUTPUT -s PUBIP
iptables -A FORWARD -i eth1

iptables -A INPUT -d 10.0.1.2
iptables -A OUTPUT -s 10.0.1.2
#iptables -A FORWARD -s 10.0.1.2
iptables -A FORWARD -i eth0

# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT

Quoted 6 lines

# Unlimited access to loop back
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Allow UDP, DNS and Passive FTP
iptables -A INPUT -i $INTERNET -m state --state ESTABLISHED,RELATED -j

ACCEPT

Quoted 11 lines

# Accept some inbound services
# HTTP
iptables -A INPUT -j ACCEPT -p tcp --destination-port 80 -i eth1

# SSH
iptables -A INPUT -j ACCEPT -p tcp --destination-port 22 -i eth1

# Mediabox P2P
iptables -A FORWARD -i $INTERNET -p tcp --dport 9500 -j ACCEPT iptables -t nat -A PREROUTING -p tcp -i $INTERNET --dport 9500 -j DNAT

--to-destination 10.0.1.11

Quoted 2 lines

iptables -A FORWARD -i $INTERNET -p tcp --dport 8112 -j ACCEPT iptables -t nat -A PREROUTING -p tcp -i $INTERNET --dport 8112 -j DNAT

--to-destination 10.0.1.11

Quoted 14 lines
# block P2P
#iptables -A FORWARD -m ipp2p --ipp2p -j DROP
#iptables -A INPUT -m ipp2p --ipp2p -j DROP
#iptables -A OUTPUT -m ipp2p --ipp2p -j DROP
# set this system as a router for Rest of LAN
iptables -t nat -A POSTROUTING -o $INTERNET -j MASQUERADE
iptables -A FORWARD -s $LOCAL -j ACCEPT
# unlimited access to LAN
iptables -A INPUT -s $LOCAL -j ACCEPT
iptables -A OUTPUT -s $LOCAL -j ACCEPT
Quoted 7 lines
# unlimited access to OPENVPN
iptables -A INPUT -s $OV -j ACCEPT
iptables -A OUTPUT -s $OV -j ACCEPT

# DROP everything and Log it
#iptables -A INPUT -j LOG
iptables -A INPUT -j DROP

Now I can get it to work only by commenting out the last line (iptables -A INPUT -j DROP). But that defies the purpose of a firewall, doesn't it?
What the heck happened last afternoon??

-JK

#1 lore raw
Quoted 5 lines

Now I can get it to work only by commenting out the last line (iptables -A INPUT -j DROP). But that defies the purpose of a firewall, doesn't it?
What the heck happened last afternoon??

Logging helps...

prior to the drop, do a log

iptables -A INPUT -j LOG --log-prefix "FW: "
iptables -A FORWARD -j LOG --log-prefix "FW: "
iptables -A OUTPUT -j LOG --log-prefix "FW: "

Then tail the log file and see what is hitting the drop rule. From there, poke any additional holes necessary.

#2 lore raw
Quoted 8 lines · Gary Smith
Quoted 5 lines

Now I can get it to work only by commenting out the last line (iptables -A INPUT -j DROP). But that defies the purpose of a firewall, doesn't it?
What the heck happened last afternoon??

Logging helps...

Quoted 10 lines

prior to the drop, do a log

iptables -A INPUT -j LOG --log-prefix "FW: "
iptables -A FORWARD -j LOG --log-prefix "FW: "
iptables -A OUTPUT -j LOG --log-prefix "FW: "

Then tail the log file and see what is hitting the drop rule. From there, poke any additional holes necessary.

Thanks Gary.
I went ahead with your suggestion but I still can't seem to figure out where the problem is.
For example, this is me trying to ping google.com from the shell:

[220040.098711] FW: IN= OUT=eth1 SRC=MYPUBIP DST=72.14.234.104 LEN=84

TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=ICMP TYPE=8 CODE=0 ID=871 SEQ=14

[...]

[220040.342816] FW: IN=eth0 OUT=

MAC=00:03:47:42:5c:17:00:04:ed:99:2c:fb:08:00 SRC=72.14.234.104 DST=MYPUBIP LEN=84 TOS=0x00 PREC=0x00 TTL=53 ID=48058 PROTO=ICMP TYPE=0 CODE=0 ID=871 SEQ=14

It all seems to be pretty kosher (except for the fact that the packets are being dropped)..

-JK

#3 lore raw
Quoted 10 lines

Thanks Gary.
I went ahead with your suggestion but I still can't seem to figure out where the problem is.
For example, this is me trying to ping google.com from the shell:

[220040.098711] FW: IN= OUT=eth1 SRC=MYPUBIP DST=72.14.234.104 LEN=84

TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=ICMP TYPE=8 CODE=0 ID=871 SEQ=14

[...]

Quoted 8 lines
[220040.342816] FW: IN=eth0 OUT=

MAC=00:03:47:42:5c:17:00:04:ed:99:2c:fb:08:00 SRC=72.14.234.104 DST=MYPUBIP LEN=84 TOS=0x00 PREC=0x00 TTL=53 ID=48058 PROTO=ICMP TYPE=0 CODE=0 ID=871 SEQ=14

It all seems to be pretty kosher (except for the fact that the packets are being dropped)..

You are dropping outgoing packets. Stop doing that :). Unless you are ultra paranoid about traffic originating from your firewall, there is no need to drop OUTPUT. IMHO, the OUTPUT chain is useful for when you need to block specific outgoing traffic in a certain manner, say, port 25, to make sure that all mail flows through a specific server on your network for compliance, etc. Or in the case of proxying, where you want to ensure that all traffic going to port 80 goes through the proxy and only the proxy can go out.

In essence, you are saying, do let my requests go out...

Then, for the input chain, make sure you have a rule to allow established and related connections to come in (and to be forwarded) and then return packets that originated from your network should be able to return just fine.

-A FORWARD -m conntrack --ctstate ESTABLISHED -j ACCEPT -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT

Give that a try.

#4 lore raw

Hmmm, not necessarily. I don't see a drop rule on the OUTPUT chain and the default policy is ACCEPT. The first packet in the posted log goes out fine (hence the ICMP reply).

Take a look at your logs. You have an outbound ICMP Echo (type 8) going to the internet through eth1. You then have a reply (Type 0) coming back in through...eth0?!?! You have something really funky going on here. Your rule allowing related and established traffic only applies to the external interface, as it should, but something else is going on that is delivering the traffic to your inside interface.

Quoted 35 lines · Gary Smith
Quoted 10 lines

Thanks Gary.
I went ahead with your suggestion but I still can't seem to figure out where the problem is.
For example, this is me trying to ping google.com from the shell:

[220040.098711] FW: IN= OUT=eth1 SRC=MYPUBIP DST=72.14.234.104 LEN=84

TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=ICMP TYPE=8 CODE=0 ID=871 SEQ=14

[...]

Quoted 8 lines
[220040.342816] FW: IN=eth0 OUT=

MAC=00:03:47:42:5c:17:00:04:ed:99:2c:fb:08:00 SRC=72.14.234.104 DST=MYPUBIP LEN=84 TOS=0x00 PREC=0x00 TTL=53 ID=48058 PROTO=ICMP TYPE=0 CODE=0 ID=871 SEQ=14

It all seems to be pretty kosher (except for the fact that the packets are being dropped)..

You are dropping outgoing packets.  Stop doing that :).  Unless you are ultra paranoid about traffic originating from your firewall, there is no need to drop OUTPUT.  IMHO, the OUTPUT chain is useful for when you need to block specific outgoing traffic in a certain manner, say, port 25, to make sure that all mail flows through a specific server on your network for compliance, etc.  Or in the case of proxying, where you want to ensure that all traffic going to port 80 goes through the proxy and only the proxy can go out.

In essence, you are saying, do let my requests go out...

Then, for the input chain, make sure you have a rule to allow established and related connections to come in (and to be forwarded) and then return packets that originated from your network should be able to return just fine.

(quoted diff) +0 -2
-A FORWARD -m conntrack --ctstate ESTABLISHED -j ACCEPT
-A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT

Give that a try.
--
To unsubscribe from this list: send the line "unsubscribe netfilter" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

#5 lore raw
Quoted 52 lines · Bill Prochazka

Hmmm, not necessarily. I don't see a drop rule on the OUTPUT chain and the default policy is ACCEPT. The first packet in the posted log goes out fine (hence the ICMP reply).

Take a look at your logs. You have an outbound ICMP Echo (type 8) going to the internet through eth1. You then have a reply (Type 0) coming back in through...eth0?!?! You have something really funky going on here. Your rule allowing related and established traffic only applies to the external interface, as it should, but something else is going on that is delivering the traffic to your inside interface.

Quoted 38 lines · Gary Smith
Quoted 12 lines

Thanks Gary.
I went ahead with your suggestion but I still can't seem to figure out where the problem is.
For example, this is me trying to ping google.com from the shell:

[220040.098711] FW: IN= OUT=eth1 SRC=MYPUBIP DST=72.14.234.104 LEN=84

TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=ICMP TYPE=8 CODE=0 ID=871 SEQ=14

[...]

[220040.342816] FW: IN=eth0 OUT=
Quoted 8 lines

MAC=00:03:47:42:5c:17:00:04:ed:99:2c:fb:08:00 SRC=72.14.234.104 DST=MYPUBIP LEN=84 TOS=0x00 PREC=0x00 TTL=53 ID=48058 PROTO=ICMP TYPE=0 CODE=0 ID=871 SEQ=14

It all seems to be pretty kosher (except for the fact that the packets are
being dropped)..

You are dropping outgoing packets.  Stop doing that :).  Unless you are ultra paranoid about traffic originating from your firewall, there is no need to drop OUTPUT.  IMHO, the OUTPUT chain is useful for when you need to block specific outgoing traffic in a certain manner, say, port 25, to make sure that all mail flows through a specific server on your network for compliance, etc.  Or in the case of proxying, where you want to ensure that all traffic going to port 80 goes through the proxy and only the proxy can go out.

In essence, you are saying, do let my requests go out...

Then, for the input chain, make sure you have a rule to allow established and related connections to come in (and to be forwarded) and then return packets that originated from your network should be able to return just fine.

Quoted 5 lines
Quoted 5 lines
(quoted diff) +0 -2
-A FORWARD -m conntrack --ctstate ESTABLISHED -j ACCEPT
-A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT

Give that a try.
--

That actually makes sense. But Gary's solution worked and both forwarding from LAN & local transmission are ok. (I still have troubles with forwarding tho)

What puzzles me the most is that I had been running that same iptables setup for years without problems..then one day BHAM! it just stopped working

-JK

#6 lore raw
In reply to Gary Smith
Quoted 40 lines · Gary Smith
Quoted 11 lines

Thanks Gary.
I went ahead with your suggestion but I still can't seem to figure out where the problem is.
For example, this is me trying to ping google.com from the shell:

[220040.098711] FW: IN= OUT=eth1 SRC=MYPUBIP DST=72.14.234.104 LEN=84

TOS=0x00 PREC=0x00 TTL=64 ID=0 DF PROTO=ICMP TYPE=8 CODE=0 ID=871 SEQ=14

[...]

[220040.342816] FW: IN=eth0 OUT=
Quoted 8 lines

MAC=00:03:47:42:5c:17:00:04:ed:99:2c:fb:08:00 SRC=72.14.234.104 DST=MYPUBIP LEN=84 TOS=0x00 PREC=0x00 TTL=53 ID=48058 PROTO=ICMP TYPE=0 CODE=0 ID=871 SEQ=14

It all seems to be pretty kosher (except for the fact that the packets are
being dropped)..

You are dropping outgoing packets. Stop doing that :). Unless you are ultra paranoid about traffic originating from your firewall, there is no need to drop OUTPUT. IMHO, the OUTPUT chain is useful for when you need to block specific outgoing traffic in a certain manner, say, port 25, to make sure that all mail flows through a specific server on your network for compliance, etc. Or in the case of proxying, where you want to ensure that all traffic going to port 80 goes through the proxy and only the proxy can go out.

In essence, you are saying, do let my requests go out...

Then, for the input chain, make sure you have a rule to allow established and related connections to come in (and to be forwarded) and then return packets that originated from your network should be able to return just fine.

(quoted diff) +0 -2
-A FORWARD -m conntrack --ctstate ESTABLISHED -j ACCEPT
-A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
Quoted 2 lines

Give that a try.

Thanks!
That seemed to do the trick.
I guess my original rule:

-A INPUT -i $INTERNET -m state --state ESTABLISHED,RELATED -j ACCEPT

somehow stopped working.

Unfortunately I am having troubles with port forwarding & opening now..none of them are accessible from the outside :(

-A INPUT -j ACCEPT -p tcp --destination-port 80 -i $INTERNET -A INPUT -j ACCEPT -p tcp --destination-port 22 -i $INTERNET

-A FORWARD -i $INTERNET -p tcp --dport 9500 -j ACCEPT -t nat -A PREROUTING -p tcp -i $INTERNET --dport 9500 -j DNAT --to-destination 10.0.1.11
-A FORWARD -i $INTERNET -p tcp --dport 8112 -j ACCEPT -t nat -A PREROUTING -p tcp -i $INTERNET --dport 8112 -j DNAT --to-destination 10.0.1.11

What's wrong now??

-JK