Advertisement
Smalls1652

fwrules.sh 9-30-15

Sep 30th, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.88 KB | None | 0 0
  1. #!/bin/bash
  2. #Firewall that protects an end host
  3. #Copyright 2014, lee w toderick. all rights reserved.
  4. #Students in ICTN4800 have permission to use and modify this code
  5. #
  6. # Flush all firewall rules
  7. iptables -F
  8. iptables -t nat -F
  9. #
  10. #Default rules
  11. iptables -P INPUT ACCEPT
  12. iptables -P OUTPUT ACCEPT
  13. iptables -P FORWARD ACCEPT
  14. iptables -t nat -P OUTPUT ACCEPT
  15. iptables -t nat -P PREROUTING ACCEPT
  16. iptables -t nat -P POSTROUTING ACCEPT
  17.  
  18. # All traffic that is a response to traffic originating from this host must be allowed.
  19. iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  20.  
  21. #Loopback interface lo has unrestricted access
  22. iptables -A INPUT -i lo -j ACCEPT
  23.  
  24. #SSH allowed in from eth0
  25. iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW -j ACCEPT
  26.  
  27. #Unrestricted access on eth2
  28. iptables -A INPUT -i eth2 -j ACCEPT
  29.  
  30. #Reject everything else
  31. iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
  32.  
  33. #Forward rejected traffic
  34. iptables -A FORWARD -i eth0 -j REJECT
  35.  
  36. #Something
  37. iptables -I INPUT -s 172.16.0.4 -i eth1 -p tcp --dport 22 -m state --state NEW -j ACCEPT
  38.  
  39. iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
  40.  
  41. iptables -I FORWARD -s 172.16.0.4 -m state --state NEW -j ACCEPT
  42.  
  43. iptables -I FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
  44.  
  45. iptables -t nat -I PREROUTING -d 10.0.0.2 -i eth0 -p tcp --dport 80 -j DNAT --to-destination 172.16.0.3
  46.  
  47. iptables -t nat -I PREROUTING -d 10.0.0.2 -i eth0 -p tcp --dport 443 -j DNAT --to-destination 172.16.0.3
  48.  
  49. iptables -I FORWARD -p tcp --dport 80 -d 172.16.0.3 -j ACCEPT
  50.  
  51. iptables -I FORWARD -p tcp --dport 443 -d 172.16.0.3 -j ACCEPT
  52.  
  53. iptables -t nat -I PREROUTING -d 10.0.0.2 -i eth0 -p tcp --dport 21 -m state --state NEW,RELATED,ESTABLISHED -j DNAT --to-destination 172.16.0.2
  54.  
  55. iptables -I FORWARD -d 172.16.0.2 -i eth0 -p tcp --dport 21 -j ACCEPT
  56.  
  57.  
  58.  
  59. #Save rules
  60. service iptables save
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement