47

I have been reading RedHat iptables documentation but can't figure out what does the following line do:

... -j REJECT --reject-with icmp-host-prohibited
Vlastimil Burián
  • 27,586
  • 56
  • 179
  • 309
David
  • 573
  • 1
  • 4
  • 5

1 Answers1

51

The REJECT target rejects the packet. If you do not specify which ICMP message to reject with, the server by default will send back ICMP port unreachable (type 3, code 3).

--reject-with modifies this behaviour to send a specific ICMP message back to the source host. You can find information about --reject-with and the available rejection messages in man iptables:

REJECT

This is used to send back an error packet in response to the matched packet: otherwise it is equivalent to DROP so it is a terminating TARGET, ending rule traversal. This target is only valid in the INPUT, FORWARD and OUTPUT chains, and user-defined chains which are only called from those chains. The following option controls the nature of the error packet returned:

--reject-with type

The type given can be:

  • icmp-net-unreachable
  • icmp-host-unreachable
  • icmp-port-unreachable
  • icmp-proto-unreachable
  • icmp-net-prohibited
  • icmp-host-prohibited or
  • icmp-admin-prohibited (*)

which return the appropriate ICMP error message (port-unreachable is the default). The option tcp-reset can be used on rules which only match the TCP protocol: this causes a TCP RST packet to be sent back. This is mainly useful for blocking ident (113/tcp) probes which frequently occur when sending mail to broken mail hosts (which won't accept your mail otherwise).

(*) Using icmp-admin-prohibited with kernels that do not support it will result in a plain DROP instead of REJECT

Chris Down
  • 122,090
  • 24
  • 265
  • 262
  • Can or should I rate limit ICMP replies so as to avoid my server being used in an amplification attack? How would the rules look like? (e.g. 1/sec ICMP net-unreachable, rest DROP)? – Ned64 Aug 01 '22 at 15:55