firewall2.conf 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/sh
  2. # firewall command
  3. FwCMD="/sbin/ipfw -q"
  4. ${FwCMD} -f flush
  5. # Interfaces setup
  6. LAN_IF="INTERNAL_INTERFACE"
  7. WAN_IF="EXTERNAL_INTERFACE"
  8. INTERNAL_IP="INT_ADDR"
  9. ENABLE_VLANS="YES"
  10. BRIDGE_NAME="bridge0"
  11. VLAN_INTERFACE=${LAN_IF}
  12. VLAN_COUNT="20"
  13. VLAN_FROM="101"
  14. case $ENABLE_VLANS in
  15. YES)
  16. #Bridge interface creation
  17. /sbin/ifconfig bridge create
  18. #casting VLANS and adding it to bridge
  19. for i in $( jot ${VLAN_COUNT} ${VLAN_FROM} );
  20. do
  21. echo "Creating vlan: ${VLAN_INTERFACE}.${i}"
  22. /sbin/ifconfig ${VLAN_INTERFACE}.${i} create
  23. /sbin/ifconfig ${VLAN_INTERFACE}.${i} up
  24. echo "Adding vlan: ${VLAN_INTERFACE}.${i} to ${BRIDGE_NAME}"
  25. /sbin/ifconfig ${BRIDGE_NAME} addm ${VLAN_INTERFACE}.${i} up
  26. /sbin/ifconfig ${BRIDGE_NAME} private ${VLAN_INTERFACE}.${i}
  27. done
  28. USER_INTERFACE=${BRIDGE_NAME}
  29. /sbin/ifconfig ${BRIDGE_NAME} maxaddr 9000
  30. ;;
  31. NO)
  32. USER_INTERFACE=${LAN_IF}
  33. ;;
  34. esac
  35. #manual MAC inherit
  36. #/sbin/ifconfig ${USER_INTERFACE} ether a0:36:9f:c0:da:aa
  37. #setting internal interface IP
  38. /sbin/ifconfig ${USER_INTERFACE} ${INTERNAL_IP}
  39. echo "Internal interface IP set to ${INTERNAL_IP}"
  40. # Networks define
  41. ${FwCMD} table 2 add INTERNAL_NETWORK
  42. #access for our site and other things
  43. ${FwCMD} add 62100 allow ip from table\(2\) to table\(17\)
  44. ${FwCMD} add 62100 allow ip from table\(17\) to table\(2\)
  45. #NAT
  46. ${FwCMD} nat 1 config log if ${WAN_IF} reset same_ports
  47. ${FwCMD} add 6000 nat 1 ip from table\(2\) to not table\(9\) out xmit ${WAN_IF}
  48. ${FwCMD} add 6001 nat 1 ip from any to me in recv ${WAN_IF}
  49. #Shape
  50. ${FwCMD} add 12001 pipe tablearg ip from any to table\(4\) via ${USER_INTERFACE} out
  51. ${FwCMD} add 12000 pipe tablearg ip from table\(3\) to any via ${USER_INTERFACE} in
  52. #security
  53. ${FwCMD} add 3 deny ip6 from any to any
  54. ${FwCMD} add 4 deny ip from table\(42\) to any
  55. ${FwCMD} add 4 deny ip from any to table\(42\)
  56. # allow access to my http for all
  57. ${FwCMD} add 62000 allow tcp from any to me dst-port 80
  58. ${FwCMD} add 62000 allow tcp from me to any src-port 80
  59. # default block policy
  60. ${FwCMD} add 65533 deny all from table\(2\) to any via ${USER_INTERFACE}
  61. ${FwCMD} add 65534 deny all from any to table\(2\) via ${USER_INTERFACE}
  62. ${FwCMD} add 65535 allow all from any to any
  63. # netflow stats
  64. /usr/local/bin/softflowd -i ${USER_INTERFACE} -n NF_HOST