Fix
Outgoing connections time out behind a DROP firewall
The firewall lets requests out but drops the replies, because no rule accepts packets of connections it already allowed. Add the ESTABLISHED,RELATED rule.
Likely causes
- A default
DROPpolicy with rules that accept only what comes from the inside, and noconntrack --ctstate ESTABLISHED,RELATEDrule. - That rule exists but sits below a rule that drops first.
Diagnose
Run these in order. The output is what each printed on a lab's real Linux machines.
-
stageDoor:~# iptables -v -A FORWARD -p tcp --dport 80 -j ACCEPT - Under a
DROPpolicy, a rule accepts requests to port 80…ACCEPT tcp opt -- in * out * 0.0.0.0/0 -> 0.0.0.0/0 tcp dpt:80
-
patron:~# curl -sS -m 3 http://10.40.2.10/ - …and the page still times out: the request reaches the server, and its answer fits no rule on the way back.
curl: (28) Connection timed out after 3007 milliseconds
Fix
-
ridgeGate:~# iptables -v -I FORWARD 1 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT - Accept packets of conversations the firewall already let through, at the top of the chain.
ACCEPT all opt -- in * out * 0.0.0.0/0 -> 0.0.0.0/0 ctstate RELATED,ESTABLISHED
-
nightDesk:~# curl -sS -m 3 http://203.0.113.20/ - The page loads, with no rule for answers on the list.
Star catalogue: 2,539,913 stars. Bright list at /bright
-
ridgeGate:~# conntrack -L - conntrack lists each conversation it let out, so its answers match.
conntrack v1.4.8 (conntrack-tools): 3 flow entries have been shown. tcp 6 118 SYN_SENT src=10.41.1.10 dst=203.0.113.99 sport=55230 dport=80 [UNREPLIED] src=203.0.113.99 dst=10.41.1.10 sport=80 dport=55230 mark=0 use=3 tcp 6 118 TIME_WAIT src=10.41.1.10 dst=203.0.113.20 sport=37772 dport=80 src=203.0.113.20 dst=10.41.1.10 sport=80 dport=37772 [ASSURED] mark=0 use=1 tcp 6 299 ESTABLISHED src=10.41.1.10 dst=203.0.113.20 sport=37778 dport=80 src=203.0.113.20 dst=10.41.1.10 sport=80 dport=37778 [ASSURED] mark=0 use=1
-
visitor:~# curl -sS -m 3 --local-port 80 http://10.41.1.20:9200/ - A stranger still can't open a connection in, even sending from port 80.
curl: (28) Connection timed out after 3003 milliseconds
-
iptables -D FORWARD 1 - If the rule is there but a
DROPsits above it, delete theDROP: the first match decides.
Break it and fix it yourself
Each lab is a small network of real Linux machines in your browser, where this fault happens.
- Firewall rules: keep the street out and let the staff in : its challenge "The counter climbs and the page never loads" set the fault for you to find and fix.
- Stateful inspection: a firewall that remembers who started it : its challenge "Every answer dies at the gate" set the fault for you to find and fix.
Open Firewall rules: keep the street out and let the staff in