Solution¶
Triage¶
- Check iptables rules with counters:
- Test direct TCP connectivity:
- Trace the connection attempt at the syscall level:
- Compare working vs. non-working destinations:
Root Cause¶
The security team added an iptables rule to the OUTPUT chain that drops all traffic to the 203.0.113.0/24 subnet as part of a "block known bad IP ranges" hardening script. The payment gateway payments.provider.com resolves to 203.0.113.50, which falls within this blocked range.
The rule was inserted as rule #3 in the OUTPUT chain, before the general ACCEPT rule for established connections. The DROP rule matches outgoing SYN packets to port 443, silently dropping them. The application's TCP connection attempt times out because no RST or ICMP unreachable is returned.
Fix¶
-
Identify the rule number:
-
Delete the offending rule:
-
If the subnet block is needed, add an exception for the payment gateway:
-
Verify the fix:
-
Persist the rules:
Rollback / Safety¶
- Before modifying rules, save a backup:
iptables-save > /tmp/iptables-backup.rules. - To restore:
iptables-restore < /tmp/iptables-backup.rules. - Test changes immediately; do not leave SSH and rely on
ator a cron job to restore rules if locked out.
Common Traps¶
- Not using
-nflag. Without-n, iptables does reverse DNS lookups on every IP, making the output extremely slow and potentially misleading. - Forgetting rule order matters. Inserting an ACCEPT after a DROP does nothing. The ACCEPT must come before the DROP in the chain.
- Confusing DROP and REJECT. DROP silently discards (connection times out). REJECT sends an ICMP unreachable (connection refused). DROP is harder to diagnose.
- Not checking all tables. Rules can exist in
filter,nat,mangle, andrawtables. Check withiptables -t nat -L -v -n, etc. - Assuming iptables rules persist. On most distributions, iptables rules are ephemeral and lost on reboot unless explicitly saved.