/etc/iptables
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ipt-static-ruleset 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #######################################################################################################################
  2. # Firewall configuration for this host ################################################################################
  3. #######################################################################################################################
  4. # Allow minimum for all VLANS (ping, dhcp, dns, ntp)
  5. sudo iptables -A INPUT -j ACCEPT -p icmp --icmp-type 8 -m comment --comment "accept incomming pings"
  6. sudo iptables -A OUTPUT -j ACCEPT -p icmp --icmp-type 8 -m comment --comment "accept outgoing pings"
  7. sudo iptables -A INPUT -j ACCEPT -p udp --dport 67:68 --sport 67:68 -m comment --comment "accept incomming dhcp"
  8. sudo iptables -A OUTPUT -j ACCEPT -p udp --dport 67:68 --sport 67:68 -m comment --comment "accept outgoing dhcp"
  9. sudo iptables -A INPUT -j ACCEPT -p udp --dport 53 -m comment --comment "accept incomming dns"
  10. sudo iptables -A INPUT -j ACCEPT -p tcp --dport 53 -m comment --comment "accept incomming dns"
  11. sudo iptables -A OUTPUT -j ACCEPT -p udp --dport 53 -m comment --comment "accept outgoing dns"
  12. sudo iptables -A OUTPUT -j ACCEPT -p tcp --dport 53 -m comment --comment "accept outgoing dns"
  13. sudo iptables -A INPUT -j ACCEPT -p udp --dport 123 -m comment --comment "accept incomming ntp"
  14. sudo iptables -A OUTPUT -j ACCEPT -p udp --dport 123 -m comment --comment "accept outgoing ntp"
  15. # Allow some usefull outgoing traffic for all VLANS (ssh)
  16. sudo iptables -A OUTPUT -j ACCEPT -p tcp --dport 22 -m comment --comment "accept outgoing ssh"
  17. sudo iptables -A OUTPUT -j ACCEPT -p tcp --dport 80 -m comment --comment "accept outgoing http"
  18. # Allow established and related trafic
  19. sudo iptables -A INPUT -j ACCEPT -m conntrack --ctstate ESTABLISHED,RELATED -m comment --comment "accept all incomming established and related trafic"
  20. sudo iptables -A OUTPUT -j ACCEPT -m conntrack --ctstate ESTABLISHED,RELATED -m comment --comment "accept all outgoing established and related trafic"
  21. # Allow everything for trusted networks
  22. sudo iptables -A INPUT -j ACCEPT -i lo -m comment --comment "accept all incoming traffic of loopback device"
  23. sudo iptables -A OUTPUT -j ACCEPT -o lo -m comment --comment "accept all outgoing traffic of the loopback device"
  24. sudo iptables -A INPUT -j ACCEPT -i eth0.30 -m comment --comment "accept all incoming traffic of eth0.30 device"
  25. sudo iptables -A OUTPUT -j ACCEPT -o eth0.30 -m comment --comment "accept all outgoing traffic of the eth0.30 device"
  26. sudo iptables -A OUTPUT -j ACCEPT -o eth0 ! -d 192.168.0.0/16 -m comment --comment "accept all outgoing traffic to the internet"
  27. # Add reject rule for propper feedback
  28. sudo iptables -A INPUT -j REJECT -m comment --comment "Reject all remaining traffic"
  29. #######################################################################################################################
  30. # Cros VLAN forwarding ################################################################################################
  31. #######################################################################################################################
  32. # General
  33. sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
  34. sudo iptables -A FORWARD -j ACCEPT -m conntrack --ctstate ESTABLISHED,RELATED -m comment --comment "forward all established and related traffic"
  35. sudo iptables -A FORWARD -j ACCEPT -p icmp --icmp-type 8 -m comment --comment "forward all pings"
  36. sudo iptables -A FORWARD -j ACCEPT -p udp --dport 123 -m comment --comment "forward all ntp request"
  37. sudo iptables -A FORWARD -j ACCEPT -p udp --sport 123 -m comment --comment "forward all ntp request"
  38. #---------------------
  39. # -> VLAN10 (Internet)
  40. #---------------------
  41. # Allow VLAN30 full access to the internet
  42. sudo iptables -A FORWARD -j ACCEPT -i eth0.30 -o eth0 ! -d 192.168.0.0/16 -m comment --comment "forward all traffic from vlan30 to the internet"
  43. sudo iptables -A FORWARD -j ACCEPT -i eth0.30 -o eth0 -d 192.168.0.0/24 -m comment --comment "forward all traffic from vlan30 to vlan10"
  44. # Allow VLAN40 access to to http,https
  45. sudo iptables -A FORWARD -j ACCEPT -i eth0.40 -o eth0 ! -d 192.168.0.0/16 -p tcp --dport 80:443 -m comment --comment "forward all http and https traffic from vlan40 to the internet"
  46. sudo iptables -A FORWARD -j ACCEPT -i eth0.40 -o eth0 ! -d 192.168.0.0/16 -p tcp --dport 8080 -m comment --comment "forward port 8080 to the internet for siemens dishwasher"
  47. # Allow VLAN60 access to to http,https
  48. sudo iptables -A FORWARD -j ACCEPT -i eth0.60 -o eth0 ! -d 192.168.0.0/16 -p tcp --dport 80:443 -m comment --comment "forward all http and https traffic from vlan60 to the internet"
  49. #--------------------
  50. # -> VLAN20 (Network)
  51. #--------------------
  52. # Allow VLAN30 full access
  53. sudo iptables -A FORWARD -j ACCEPT -i eth0.30 -o eth0.20 -d 192.168.20.0/24 -m comment --comment "forward traffic from vlan30 to VLAN20"
  54. #--------------------------------------
  55. # -> VLAN30 (Family) - VERY RESTRICTIVE
  56. #--------------------------------------
  57. # Allow VLAN40 and VLAN50 access to the mqtt port
  58. sudo iptables -A FORWARD -j ACCEPT -i eth0.40 -o eth0.30 -p tcp --dport 1883 -d 192.168.30.0/24 -m comment --comment "forward mqtt traffic from vlan40 to VLAN30"
  59. sudo iptables -A FORWARD -j ACCEPT -i eth0.50 -o eth0.30 -p tcp --dport 1883 -d 192.168.30.0/24 -m comment --comment "forward mqtt traffic from vlan50 to VLAN30"
  60. sudo iptables -A FORWARD -j ACCEPT -i eth0.50 -o eth0.30 -p tcp --dport 21 -d 192.168.30.0/24 -m comment --comment "forward ftp traffic from vlan50 to VLAN30 (brother printer)"
  61. #-------------------------------
  62. # -> VLAN40 (Untrusted Internet)
  63. #-------------------------------
  64. # Allow VLAN30 full access
  65. sudo iptables -A FORWARD -j ACCEPT -i eth0.30 -o eth0.40 -d 192.168.40.0/24 -m comment --comment "forward traffic from vlan30 to VLAN40"
  66. #---------------------------------
  67. # -> VLAN50 (Untrusted no Internet
  68. #---------------------------------
  69. # Allow VLAN30 full access
  70. sudo iptables -A FORWARD -j ACCEPT -i eth0.30 -o eth0.50 -d 192.168.50.0/24 -m comment --comment "forward traffic from vlan30 to VLAN50"
  71. #------------------
  72. # -> VLAN60 (Gäste)
  73. #------------------
  74. #----------------------
  75. # Masquerade traffic to
  76. #----------------------
  77. sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE -m comment --comment "masquerade ->eth0.10"
  78. sudo iptables -t nat -A POSTROUTING -o eth0.20 -j MASQUERADE -m comment --comment "masquerade ->eth0.20"
  79. sudo iptables -t nat -A POSTROUTING -o eth0.30 -j MASQUERADE -m comment --comment "masquerade ->eth0.30"
  80. sudo iptables -t nat -A POSTROUTING -o eth0.40 -j MASQUERADE -m comment --comment "masquerade ->eth0.40"
  81. sudo iptables -t nat -A POSTROUTING -o eth0.50 -j MASQUERADE -m comment --comment "masquerade ->eth0.50"
  82. #######################################################################################################################
  83. # Change policy to drop all remainig ##################################################################################
  84. #######################################################################################################################
  85. sudo iptables -P INPUT DROP
  86. sudo iptables -P OUTPUT DROP
  87. sudo iptables -P FORWARD DROP
  88. #######################################################################################################################
  89. # Show configuration ##################################################################################################
  90. #######################################################################################################################
  91. sudo iptables -L -n -v --line-numbers
  92. echo "********************************************************************************************"
  93. echo "* -> Execute sudo sh -c \"iptables-save > /etc/iptables/rules.v4\""
  94. echo "********************************************************************************************"