Advertisement
skybetik

firewall-dil

Sep 6th, 2023
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # firewall command
  4. FwCMD="/sbin/ipfw -q"
  5. ${FwCMD} -f flush
  6.  
  7. # Interfaces setup
  8. LAN_IF="ix0"
  9. WAN_IF="bce0"
  10. INTERNAL_IP="10.0.0.1/24"
  11.  
  12. ENABLE_VLANS="YES"
  13.  
  14. BRIDGE_NAME="bridge0"
  15. VLAN_INTERFACE=${LAN_IF}
  16. VLAN_COUNT="10"
  17. VLAN_FROM="20"
  18.  
  19.  
  20. case $ENABLE_VLANS in
  21. YES)
  22. #Bridge interface creation
  23. /sbin/ifconfig bridge create
  24. #casting VLANS and adding it to bridge
  25. for i in $( jot ${VLAN_COUNT} ${VLAN_FROM} );
  26. do
  27. echo "Creating vlan: ${VLAN_INTERFACE}.${i}"
  28. /sbin/ifconfig ${VLAN_INTERFACE}.${i} create
  29. /sbin/ifconfig ${VLAN_INTERFACE}.${i} up
  30. echo "Adding vlan: ${VLAN_INTERFACE}.${i} to ${BRIDGE_NAME}"
  31. /sbin/ifconfig ${BRIDGE_NAME} addm ${VLAN_INTERFACE}.${i} up
  32. /sbin/ifconfig ${BRIDGE_NAME} private ${VLAN_INTERFACE}.${i}
  33. done
  34. USER_INTERFACE=${BRIDGE_NAME}
  35. /sbin/ifconfig ${BRIDGE_NAME} maxaddr 9000
  36. ;;
  37. NO)
  38. USER_INTERFACE=${LAN_IF}
  39. ;;
  40. esac
  41.  
  42. #manual MAC inherit
  43. /sbin/ifconfig ${USER_INTERFACE} ether 00:e0:ed:9c:9d:b3
  44.  
  45. #setting internal interface IP
  46. /sbin/ifconfig ${USER_INTERFACE} ${INTERNAL_IP}
  47. echo "Internal interface IP set to ${INTERNAL_IP}"
  48.  
  49. #alias vlan interface
  50. /sbin/ifconfig ${USER_INTERFACE} alias 10.0.1.1/24
  51. /sbin/ifconfig ${USER_INTERFACE} alias 10.0.2.1/24
  52. /sbin/ifconfig ${USER_INTERFACE} alias 10.0.3.1/24
  53. /sbin/ifconfig ${USER_INTERFACE} alias 172.31.0.254/24
  54. /sbin/ifconfig ${USER_INTERFACE} alias 172.16.0.254/24
  55.  
  56. # Networks defines
  57. # Users
  58. ${FwCMD} table 2 add 10.0.0.0/24
  59. # Safe zones
  60. ${FwCMD} table 22 add 127.0.0.1
  61. ${FwCMD} table 22 add 185.*.*.*
  62. ${FwCMD} table 22 add 192.168.99.0/24
  63.  
  64. # Safe zones allow policy
  65. ${FwCMD} add 45 allow ip from table\(22\) to me
  66. ${FwCMD} add 45 allow ip from me to table\(22\)
  67.  
  68. # ssh access.
  69. #${FwCMD} add 46 deny ip from any to me dst-port 22
  70. #${FwCMD} add 46 deny ip from me to any src-port 22
  71.  
  72. # mysql access
  73. ${FwCMD} add 47 deny ip from any to me dst-port 3306
  74. ${FwCMD} add 47 deny ip from me to any src-port 3306
  75.  
  76. # sgconf access
  77. ${FwCMD} add 48 deny ip from any to me dst-port 5555
  78. ${FwCMD} add 48 deny ip from me to any src-port 5555
  79.  
  80.  
  81. #destroy
  82. ${FwCMD} add 4 allow ip from table\(2\) to me dst-port 80 via ${USER_INTERFACE}
  83. ${FwCMD} add 4 allow ip from me to table\(2\) src-port 80 via ${USER_INTERFACE}
  84. ${FwCMD} add 5 allow udp from any 67,68,53 to any via ${USER_INTERFACE}
  85. ${FwCMD} add 7 allow ip from table\(2\) to me dst-port 53 via ${USER_INTERFACE}
  86. ${FwCMD} add 7 allow udp from me 53 to table\(2\) via ${USER_INTERFACE}
  87. ${FwCMD} add 12 allow ip from table\(2\) to me dst-port 2222 via ${USER_INTERFACE}
  88. ${FwCMD} add 12 allow ip from me to table\(2\) src-port 2222 via ${USER_INTERFACE}
  89.  
  90. #DENY NETBIOS
  91. ${FwCMD} add 1100 deny udp from any to any 137,138 via ${USER_INTERFACE}
  92. ${FwCMD} add 1100 deny tcp from any to any 135,139 via ${USER_INTERFACE}
  93.  
  94. #UHW
  95. ${FwCMD} add 10 fwd 127.0.0.1,80 ip from 172.31.0.0/24 to not me dst-port 80
  96.  
  97. #NAT-POOL
  98. ${FwCMD} nat 1 config log ip 37.*.*.* reset same_ports
  99.  
  100. ${FwCMD} add 6000 nat tablearg ip from table\(66\) to any via ${WAN_IF}
  101. ${FwCMD} add 6001 nat tablearg ip from any to table\(67\) via ${WAN_IF}
  102.  
  103. #######Abons address############# Which number nat
  104. ${FwCMD} table 66 add 10.0.0.0/24 1
  105.  
  106. #################### EXTERNAL IP# NAT NUMBER
  107. ${FwCMD} table 67 add 37.*.*.* 1
  108.  
  109. #Shaper - table 4 download speed, table 3 - upload speed
  110. ${FwCMD} add 12001 pipe tablearg ip from any to table\(4\) via ${USER_INTERFACE} out
  111. ${FwCMD} add 12000 pipe tablearg ip from table\(3\) to any via ${USER_INTERFACE} in
  112.  
  113. # default block policy
  114. ${FwCMD} add 65533 deny all from table\(2\) to any via ${USER_INTERFACE}
  115. ${FwCMD} add 65534 deny all from any to table\(2\) via ${USER_INTERFACE}
  116. ${FwCMD} add 65535 allow all from any to any
  117.  
Tags: Firewall
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement