Chinaunix首页 | 论坛 | 博客
  • 博客访问: 733769
  • 博文数量: 235
  • 博客积分: 4309
  • 博客等级: 中校
  • 技术积分: 2325
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-17 11:25
个人简介

If you don\\\\\\\\\\\\\\\'t wanna do it, you find an EXCUSE; if you do, you\\\\\\\\\\\\\\\'ll find a WAY :-)

文章分类

全部博文(235)

文章存档

2014年(3)

2013年(2)

2012年(31)

2011年(199)

分类: BSD

2011-10-11 22:06:24

1:
  1. PF( Packet Filtering)
  2. vim /etc/rc.conf
  3. pf_enable="YES"
  4. pflog_enable="YES"
  5. :wq
  6. vim /etc/pf.conf
  7. #1. Macros
  8. #2. Tables
  9. #3. Options
  10. #4. Packet normalization
  11. #5. Bandwidth management
  12. #6. Translation
  13. #7. Redirection
  14. #8. Packet filtering
  15. interface="em0"
  16. scrub in all
  17. block in on $interface
  18. # allow SSH and POP3 traffic from our network
  19. pass in on $interface proto tcp from 192.168.1.0/24 to $interface port 22
  20. pass in on $interface proto tcp from 192.168.1.0/24 to $interface port 110
  21. # allow SMTP (25), HTTP (80), and HTTPS (443) to the world
  22. pass in on $interface proto tcp from any to $interface port 25
  23. pass in on $interface proto tcp from any to $interface port 80
  24. pass in on $interface proto tcp from any to $interface port 443
  25. # allow the world to query our DNS server
  26. pass in on $interface proto tcp from any to $interface port 53
  27. pass in on $interface proto udp from any to $interface port 53
  28. # allow outgoing traffic
  29. pass out on $interface proto { tcp, udp } all
  30. :wq



  31. # 检查语法 但不加载规则
  32. # pfctl -nf /etc/pf.conf
  33. # 加载规则
  34. # pfctl -f /etc/pf.conf
  35. # 查看 filter规则
  36. # pfctl -sr (-s rules)
  37. # pfctl -s info
  38. # 清空所有规则
  39. # pfctl -Fa (-F all)
  40. # pf -e (/etc/rc.d/pf start)
  41. # pf -d (/etc/rc.d/pf stop)
  42. --------------------------------------------------------------------
  43. block in all
  44. pass out all

  45. tcp_services = "{ ssh, smtp, domain, www, pop3, auth, https, pop3s }"
  46. udp_services = "{ domain }"
  47. block all
  48. pass out proto tcp to any port $tcp_services
  49. pass out proto udp to any port $udp_services

  50. Gateway:
  51. Vim /etc/rc.conf
  52. gateway_enable="YES" # for ipv4
  53. ipv6_gateway_enable="YES" # for ipv6

  54. ext_if = "re0" # macro for external interface - use tun0 or pppoe0 for PPPoE
  55. int_if = "re1" # macro for internal interface
  56. localnet = $int_if:192.168.1.0/24

  57. client_out = "{ ftp-data, ftp, ssh, domain, pop3, auth, nntp, http,\
  58. https, 446, cvspserver, 2628, 5999, 8000, 8080 }"
  59. udp_services = "{ domain, ntp }"

  60. # ext_if IP address could be dynamic, hence ($ext_if)
  61. nat on $ext_if from $localnet to any -> ($ext_if)
  62. block all
  63. pass in inet proto tcp from any to $ext_if port ssh
  64. pass quick inet proto { tcp, udp } to any port $udp_services

  65. # For each packet or
  66. connection evaluated by PF, the last matching rule in the rule set is the one
  67. that is applied. quick keyword offers an escape from the ordinary sequence
  68. The rule processing stops without considering any further rules that
  69. might have matched the packet.

  70. pass from { lo0, $localnet } to any keep state
2:

3:

4:

5:

6:
阅读(589) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~