Blocking traffic with iptables can either make packets disappear or send a clear failure back to the client. Choosing between DROP and REJECT changes how scanners, health checks, applications, and users experience the blocked path.
DROP ends rule traversal without replying, so TCP clients usually wait until their own timeout. REJECT is also a terminating target, but it returns an ICMP error or a TCP reset when the rule and protocol support that response.
Use DROP when silent blocking is the desired signal, such as unwanted internet noise. Use REJECT when fast failure is better for controlled clients, internal troubleshooting, load balancer health checks, or routes that should fail closed without long waits.
Related: How to block a port with iptables
Related: How to block an IP address with iptables
Related: How to list iptables rules with counters
Tool: iptables Rule Generator
Use INPUT for services on the local host, FORWARD for routed traffic, and OUTPUT for locally generated traffic. Choose REJECT only when the client should receive a visible failure.
$ sudo iptables --list INPUT --line-numbers --numeric --verbose Chain INPUT (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination
Rule order matters. Insert the chosen block before broader ACCEPT rules that would otherwise permit the same traffic.
Related: How to list iptables rules with counters
$ sudo iptables -A INPUT -p tcp --dport 8080 -j DROP
DROP is usually appropriate for unsolicited traffic where a delayed client timeout is acceptable.
$ sudo iptables -A INPUT -p tcp --dport 8081 -j REJECT --reject-with tcp-reset
--reject-with tcp-reset applies only to TCP rules. For UDP, use an ICMP reject type such as --reject-with icmp-port-unreachable.
$ sudo iptables -S INPUT -P INPUT ACCEPT -A INPUT -p tcp -m tcp --dport 8080 -j DROP -A INPUT -p tcp -m tcp --dport 8081 -j REJECT --reject-with tcp-reset
$ nc -vz -w 2 server.example.com 8080 nc: connect to server.example.com port 8080 (tcp) timed out: Operation now in progress
A timeout is expected with DROP when no earlier rule accepts the packet and no upstream device sends a different failure.
$ nc -vz -w 2 server.example.com 8081 nc: connect to server.example.com port 8081 (tcp) failed: Connection refused
Fast failure helps internal clients and monitoring systems distinguish a deliberate block from packet loss or an unreachable host.
$ sudo iptables --list INPUT --line-numbers --numeric --verbose --exact Chain INPUT (policy ACCEPT 0 packets, 0 bytes) num pkts bytes target prot opt in out source destination 1 2 120 DROP tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8080 2 2 120 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8081 reject-with tcp-reset
The counters prove the client tests reached the chosen rules. A zero counter usually means another rule or upstream firewall handled the packets first.
$ sudo iptables -D INPUT -p tcp --dport 8080 -j DROP $ sudo iptables -A INPUT -p tcp --dport 8080 -j REJECT --reject-with tcp-reset
Reordering or replacing block rules can immediately change client behavior. Keep management access and rollback commands ready on remote systems.
Related: How to delete an iptables rule
$ sudo netfilter-persistent save run-parts: executing /usr/share/netfilter-persistent/plugins.d/15-ip4tables save
Persist only the target that matches the operational need: silent timeout for DROP or explicit failure for REJECT.
Related: How to save iptables rules permanently