Skip to content

Instantly share code, notes, and snippets.

@whiler
Created May 28, 2018 07:20
Show Gist options
  • Save whiler/e20ba1017282649f04366be021590153 to your computer and use it in GitHub Desktop.
Save whiler/e20ba1017282649f04366be021590153 to your computer and use it in GitHub Desktop.
ping before ssh
iptables --table filter --append INPUT --match conntrack --ctstate ESTABLISHED,RELATED --match comment --comment "Allow established and related connections" --jump ACCEPT
iptables --table filter --append INPUT --protocol icmp --icmp-type echo-request --match length --length 84 --match recent --set --name openSSH --rsource --match comment --comment "ping before ssh" --jump LOG --log-prefix "OpenDoor SSH: " --log-level 7
iptables --table filter --append INPUT --protocol tcp --dport ssh --syn --match recent ! --rcheck --seconds 30 --name openSSH --rsource --match comment --comment "Drop SSH connection not pinged recently" --jump DROP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment