Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2017
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.04 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # LAN interface
  4. LAN_IF="eth0"
  5.  
  6. # WAN interface
  7. WAN_IF="eth1"
  8.  
  9. # IP WAN interface
  10. WAN_IP="110.120.130.205"
  11.  
  12. # gateway
  13. WAN_GW="110.120.130.254"
  14.  
  15. # LAN netmask
  16. LAN_NET="10.0.0.0/24"
  17.  
  18. # WAN netmask
  19. WAN_NET="110.120.130.0/24"
  20.  
  21. ####################
  22.  
  23. # Очистить все правила
  24. iptables -P INPUT ACCEPT
  25. iptables -P FORWARD ACCEPT
  26. iptables -P OUTPUT ACCEPT
  27. iptables -t nat -P PREROUTING ACCEPT
  28. iptables -t nat -P POSTROUTING ACCEPT
  29. iptables -t nat -P OUTPUT ACCEPT
  30. iptables -t mangle -P PREROUTING ACCEPT
  31. iptables -t mangle -P OUTPUT ACCEPT
  32. iptables -F
  33. iptables -t nat -F
  34. iptables -t mangle -F
  35. iptables -X
  36. iptables -t nat -X
  37. iptables -t mangle -X
  38.  
  39. ### Правила по умолчанию
  40. iptables -P INPUT DROP
  41. iptables -P FORWARD DROP
  42. iptables -P OUTPUT ACCEPT
  43.  
  44. # Разрешаем localhost и локалку
  45. iptables -A INPUT -i lo -j ACCEPT
  46. iptables -A INPUT -i $LAN_IF -j ACCEPT
  47. iptables -A OUTPUT -o lo -j ACCEPT
  48. iptables -A OUTPUT -o $LAN_IF -j ACCEPT
  49.  
  50. # Разрешаем установленные подключения
  51. iptables -A INPUT -p all -m state --state ESTABLISHED,RELATED -j ACCEPT
  52. iptables -A OUTPUT -p all -m state --state ESTABLISHED,RELATED -j ACCEPT
  53. iptables -A FORWARD -p all -m state --state ESTABLISHED,RELATED -j ACCEPT
  54.  
  55. # Отбрасываем неопознанные пакеты
  56. iptables -A INPUT -m state --state INVALID -j DROP
  57. iptables -A FORWARD -m state --state INVALID -j DROP
  58.  
  59. # Отбрасываем нулевые пакеты
  60. iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
  61.  
  62. # Закрываемся от syn-flood атак
  63. iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
  64. iptables -A OUTPUT -p tcp ! --syn -m state --state NEW -j DROP
  65.  
  66. # Разрешаем все исходящие подключения сервера
  67. iptables -A OUTPUT -o $WAN_IF -j ACCEPT
  68.  
  69. # Закрываем доступ снаружи в локалку
  70. iptables -A FORWARD -i $WAN_IF -o $LAN_IF -j REJECT
  71.  
  72. # Фильтруем по mac-адресу
  73. #iptables -I FORWARD -m mac --mac-source 94:DE:80:A1:1D:BF -j DROP
  74. #iptables -I FORWARD -m mac --mac-source 00:02:44:1f:d1:78 -j DROP
  75. #iptables -I FORWARD -m mac --mac-source 00:50:22:B4:E7:B2 -j DROP
  76. #iptables -I FORWARD -m mac --mac-source * -j DROP
  77.  
  78.  
  79. ### ПОРТЫ
  80. # Открываем доступ к SSH
  81. iptables -A INPUT -p tcp --dport 44022 -j ACCEPT
  82. # Открываем доступ к RDP rinetd
  83. iptables -A INPUT -p tcp --dport 55555 -j ACCEPT
  84. # Открываем доступ к RDP iptables
  85. iptables -A INPUT -p tcp --dport 3389 -j ACCEPT
  86. # Открываем доступ к web серверу
  87. iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
  88. # p2p синхронизация
  89. iptables -A INPUT -p tcp -m tcp --dport 4444 -j ACCEPT
  90. iptables -A INPUT -i $WAN_IF -p tcp --dport 22000 -j ACCEPT
  91. # Синхронизация времени
  92. iptables -A INPUT -p tcp -i $LAN_IF --dport 123 -j ACCEPT
  93. iptables -A INPUT -p udp -i $LAN_IF --dport 123 -j ACCEPT
  94. # Разрешить запросы к кэширующему DNS серверу только из локальной сети
  95. iptables -A INPUT -p TCP -s $LAN_NET --dport 53 -j ACCEPT
  96. iptables -A INPUT -p UDP -s $LAN_NET --dport 53 -j ACCEPT
  97.  
  98. # Разрешаем пинги
  99. iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT
  100. iptables -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT
  101. iptables -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT
  102. iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
  103.  
  104. # Разрешаем доступ из локалки наружу
  105. iptables -A FORWARD -i $LAN_IF -o $WAN_IF -j ACCEPT
  106.  
  107.  
  108. ### ПРОБРОС ПОРТВ
  109. # Пробросить порт на локальный веб сервер на нестандартный порт
  110. #iptables -t nat -A PREROUTING -p TCP -d $WAN_IP --dport 3389 -j DNAT --to-destination 10.0.0.10:3389
  111.  
  112. #iptables -t nat -A PREROUTING -p tcp -m tcp -d $WAN_IP --dport 3389 -j DNAT --to-destination 10.0.0.10:3389
  113. #iptables -t nat -A POSTROUTING -p tcp -m tcp -d 10.0.0.10 --sport 3389 -j SNAT --to-source $WAN_IP:3389
  114.  
  115. iptables -t nat -A PREROUTING -d $WAN_IP -p tcp --dport 3389 -j DNAT --to-destination 10.0.0.10:3389
  116. iptables -t filter -A FORWARD -m state --state NEW -p tcp --dport 3389 -j ACCEPT
  117.  
  118.  
  119. ### SQUID
  120. # Переадресация 80 и 443 портов на прозрачный сквид
  121. iptables -t nat -A PREROUTING -p tcp -m tcp -s 10.0.0.0/24 --dport 443 -j REDIRECT --to-ports 3443
  122. iptables -t nat -A PREROUTING -p tcp -m multiport -s 10.0.0.0/24 --dports 80,81,82,88,1080,3127,3128,7900,8000,8080,8081,8088,8123,8888,9090 -j REDIRECT --to-ports 3080
  123.  
  124.  
  125. ### NAT
  126. # Включить NAT для локальной подсети
  127. iptables -t nat -A POSTROUTING -s $LAN_NET -o $WAN_IF -j SNAT --to-source $WAN_IP
  128. #iptables -t nat -F POSTROUTING
  129. #iptables -t nat -A POSTROUTING -s $LAN_NET -o $WAN_IF -j MASQUERADE
  130.  
  131.  
  132.  
  133. ### Сохраняем правила
  134. /sbin/iptables-save  > /etc/iptables.rules
  135. iptables-restore < /etc/iptables.rules
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement