Advertisement
Guest User

iptables-rules

a guest
Nov 2nd, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.87 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Set the default policies to allow everything while we set up new rules
  4. # Prevents cutting yourself off when running from remote SSH
  5. iptables -P INPUT ACCEPT
  6. iptables -P FORWARD ACCEPT
  7. iptables -P OUTPUT ACCEPT
  8.  
  9. # Flush any existing rules, leaving just the defaults
  10. iptables -F
  11. iptables -X
  12. iptables -t nat -F
  13. iptables -t nat -X
  14. iptables -t mangle -F
  15. iptables -t mangle -X
  16.  
  17. # Open port 22 only for incoming SSH connections
  18. iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  19.  
  20. # accept any localhost (loopback) calls
  21. iptables -A INPUT -i lo -j ACCEPT
  22.  
  23. # allow any existing connection to remain
  24. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  25.  
  26. # reset the default policies to stop all incoming and forward requests
  27. iptables -P INPUT DROP
  28. iptables -P FORWARD DROP
  29.  
  30. # accept any outbound requests from this server
  31. iptables -P OUTPUT ACCEPT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement