Guest User

Untitled

a guest
Jul 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. # Firewall Script 2
  2. # Matt Beaudin (040-559-386)
  3. # Stateful Firewall Rules
  4.  
  5.  
  6. # Variables
  7. iptables="/sbin/iptables"
  8.  
  9.  
  10. # Flush firewall rules
  11. $iptables --flush
  12. $iptables -t nat --flush
  13. $iptables -t mangle --flush
  14. $iptables -X
  15.  
  16.  
  17. # Rules
  18. # ssh to the host and back
  19. $iptables -A FORWARD -p tcp -s 0/0 -d 192.168.159.1 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
  20. $iptables -A FORWARD -p tcp -s 192.168.159.1 -d 0/0 --sport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
  21.  
  22. # ssh from host to VM2 (server)
  23. $iptables -A FORWARD -p tcp -s 192.168.159.1/24 -d 10.20.0.100/16 --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
  24. $iptables -A FORWARD -p tcp -s 10.20.0.100/16 -d 192.168.159.1/24 --dport 22 -m state --state ESTABLISHED -j ACCEPT
  25.  
  26. # access web server from any host
  27. $iptables -A FORWARD -p tcp -s 0/0 -d 10.20.0.100 --sport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
  28. $iptables -A FORWARD -p tcp -s 10.20.0.100 -d 0/0 --dport 80 -m state --state ESTABLISHED -j ACCEPT
  29. $iptables -A OUTPUT -p tcp -s 10.20.0.1 -d 10.20.0.100 --sport 80 -m state --state NEW -j ACCEPT
  30. $iptables -A INPUT -p tcp -s 10.20.0.100 -d 10.20.0.1 --dport 80 -m state --state ESTABLISHED -j ACCEPT
  31.  
  32. # DNS resolution
  33. $iptables -A FORWARD -p udp -s 0/0 -d 0/0 --sport 53 -m state --state NEW -j ACCEPT
  34. $iptables -A FORWARD -p udp -s 0/0 -d 0/0 --dport 53 -m state --state ESTABLISHED -j ACCEPT
  35.  
  36. # Allow ping and traceroute to any host from internal network
  37. $iptables -A FORWARD -p icmp -s 10.20.0.0/16 -d 0/0 -m state --state NEW,ESTABLISHED -j ACCEPT
  38.  
  39. # Allow host to ping and traceroute to VM2 only
  40. $iptables -A FORWARD -p icmp -s 192.168.159.1 -d 10.20.0.100 -m state --state NEW,ESTABLISHED -j ACCEPT
  41. #$iptables -A INPUT -p icmp -s 192.168.159.1 -d 192.168.159.129 -m state --state NEW,ESTABLISHED -j DROP
  42. #$iptables -A INPUT -p icmp -s 192.168.159.1 -d 10.20.0.1 -m state --state NEW,ESTABLISHED -j DROP
  43.  
  44. # host can ftp to VM2 using FTP
  45. $iptables -A FORWARD -p tcp -s 192.168.159.1 -d 10.20.0.100 --sport 21 -m state --state NEW -j ACCEPT
Add Comment
Please, Sign In to add comment