Guest User

Untitled

a guest
May 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. #The overall philosophy of this firewall is to reject any traffic we don't explicitly allow.
  2. #There are 2 main servers, but they can be thought of as 3, as one uses 2 ips to separate some services
  3. # First, 207.70.62.18 should nearly always forward to 192.168.0.30 - this is Elwood
  4. # Next, 207.70.62.19 should nearly always forward to 192.168.0.20 - this is Jake
  5. # Third, 207.70.62.20 should nearly always forward to 192.168.0.31 - this is on Elwood, but does different things
  6. # Finally, there are some exceptions to these rules (stuff like remote support traffic that his my laptop
  7. # instead of going on to elwood or jake, etc.
  8.  
  9. #We don't know or care what openwrt has done with the firewall prior to running this script. Off we go!
  10.  
  11. #Set everything to accept
  12. iptables -t nat -P PREROUTING ACCEPT
  13. iptables -t nat -P POSTROUTING ACCEPT
  14.  
  15. #Barrroooommmm -- flush all rules
  16. iptables -t nat -F
  17. iptables -t nat -X
  18.  
  19. #set default policy of acceptance on everything
  20. iptables -t filter -P INPUT ACCEPT
  21. iptables -t filter -P FORWARD ACCEPT
  22. #don't enable this drop until after verifying the rest of the forward and nat rules work.
  23. #iptables -t filter -P FORWARD DROP
  24.  
  25. iptables -t filter -P OUTPUT ACCEPT
  26. iptables -t filter -F
  27. iptables -t filter -X
  28.  
  29. #these IPs are not allowed to talk to us at all - (web crawlers that are misbehaving)
  30. iptables -t filter -A FORWARD -s 66.17.15.166 -j DROP
  31. iptables -t filter -A FORWARD -s 69.84.207.147 -j DROP
  32.  
  33. #first, set up exclusions to the rules of straight external IP -> internal IP translation
  34. # Set up services that need to hit Kimball's laptop
  35. #port 5500 is for reverse VNC - remote support to our customers.
  36. iptables -t nat -A PREROUTING -d 207.70.62.19 -p udp -m udp --dport 5500 -j DNAT --to-destination 192.168.0.21
  37. iptables -t nat -A PREROUTING -d 207.70.62.19 -p tcp -m tcp --dport 5500 -j DNAT --to-destination 192.168.0.21
  38. iptables -A FORWARD -d 192.168.0.21 -p tcp --dport 5500 -j ACCEPT
  39. iptables -A FORWARD -d 192.168.0.21 -p udp --dport 5500 -j ACCEPT
  40. # ports 44555 and 49152 are for remote debugging. Not needed frequently, so disabled for now.
  41. #iptables -t nat -A PREROUTING -d 207.70.62.19 -p udp -m udp --dport 44555 -j DNAT --to-destination 192.168.0.21
  42. #iptables -t nat -A PREROUTING -d 207.70.62.19 -p tcp -m tcp --dport 44555 -j DNAT --to-destination 192.168.0.21
  43. #iptables -t nat -A PREROUTING -d 207.70.62.19 -p udp -m udp --dport 49152 -j DNAT --to-destination 192.168.0.21
  44. #iptables -t nat -A PREROUTING -d 207.70.62.19 -p tcp -m tcp --dport 49152 -j DNAT --to-destination 192.168.0.21
  45.  
  46. #This sets up Cameron's machine to receive incoming remote support requests
  47. iptables -t nat -A PREROUTING -d 207.70.62.18 -p udp -m udp --dport 5500 -j DNAT --to-destination 192.168.0.4
  48. iptables -t nat -A PREROUTING -d 207.70.62.18 -p tcp -m tcp --dport 5500 -j DNAT --to-destination 192.168.0.4
  49. iptables -A FORWARD -d 192.168.0.4 -p tcp --dport 5500 -j ACCEPT
  50. iptables -A FORWARD -d 192.168.0.4 -p udp --dport 5500 -j ACCEPT
  51.  
  52. #catch all to send everything to elwood that comes in on .18 - though everything that is natted in this fashion will be
  53. #dropped by the forward chain, so we'll explicitly list some things to allow through (web, mail, ssh, etc)
  54. iptables -t nat -A PREROUTING -d 207.70.62.18 -j DNAT --to-destination 192.168.0.30
  55.  
  56. #catch all to send everything to Jake
  57. iptables -t nat -A PREROUTING -d 207.70.62.19 -j DNAT --to-destination 192.168.0.20
  58.  
  59. #catch all to send everything to 192.168.0.31 that comes in on 207.70.62.20
  60. iptables -t nat -A PREROUTING -d 207.70.62.20 -j DNAT --to-destination 192.168.0.31
  61.  
  62. #take care of some lan routing - always let traffic originating from the lan through.
  63. iptables -A FORWARD -i br-lan -j ACCEPT
  64.  
  65. #explicitly forward some ports on 207.70.62.18 to elwood
  66. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 80 -j ACCEPT
  67. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 22 -j ACCEPT
  68. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 443 -j ACCEPT
  69. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 993 -j ACCEPT
  70. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 995 -j ACCEPT
  71. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 2500 -j ACCEPT
  72. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 3493 -j ACCEPT
  73. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 3306 -j ACCEPT
  74. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 110 -j ACCEPT
  75. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 143 -j ACCEPT
  76. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 10000 -j ACCEPT
  77. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 53 -j ACCEPT
  78. iptables -A FORWARD -d 192.168.0.30 -p udp --dport 53 -j ACCEPT
  79. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 25 -j ACCEPT
  80.  
  81. #explicitly forward some ports on 207.70.62.19 to jake
  82. iptables -A FORWARD -d 192.168.0.20 -p tcp --dport 80 -j ACCEPT
  83. iptables -A FORWARD -d 192.168.0.20 -p tcp --dport 8080 -j ACCEPT
  84. iptables -A FORWARD -d 192.168.0.20 -p tcp --dport 22 -j ACCEPT
  85.  
  86. #explicitly forward some ports on 207.70.62.20 to 192.168.0.31 (also on elwood, but separate interface)
  87. iptables -A FORWARD -d 192.168.0.31 -p tcp --dport 80 -j ACCEPT
  88. iptables -A FORWARD -d 192.168.0.30 -p tcp --dport 443 -j ACCEPT
  89.  
  90. #log some forwarding
  91. iptables -A FORWARD -j LOG --log-prefix would_drop
  92.  
  93. #snat everything back to servers as needed
  94. iptables -t nat -A POSTROUTING -s 192.168.0.30 -j SNAT --to-source 207.70.62.18
  95. iptables -t nat -A POSTROUTING -s 192.168.0.20 -j SNAT --to-source 207.70.62.19
  96. iptables -t nat -A POSTROUTING -s 192.168.0.31 -j SNAT --to-source 207.70.62.20
  97.  
  98. #and local subnets are always masqueraded (eth0.1 is the modem-facing interface on the router)
  99. iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -o eth0.1 -j MASQUERADE
  100. iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -d 207.70.62.16/29 -j MASQUERADE
  101. exit
Add Comment
Please, Sign In to add comment