Notebook

これは日々の作業を通して学んだことや毎日の生活で気づいたことをを記録しておく備忘録である。

HTML ファイル生成日時: 2026/11/12 14:02:00.691 (台灣標準時)

pf と npf について

NetBSD でパケットフィルターを使おうとすると、 npf を使うのがよいそうで ござる。 pf もあるのでござるが、 pf は保守されていないようで、 npf の 利用が強く推奨されているようでござる。

pf のための設定ファイルは /etc/pf.conf でござる。 npf のための設定ファ イルは /etc/npf.conf でござる。例えば、以下のような /etc/pf.conf があ るとするでござる。


ext_if="wm0"
nat on $ext_if inet from 10.0.0.0/24 to any -> ($ext_if)
pass quick on wg0 all
pass in on $ext_if proto udp to port 12345

この pf 用の /etc/pf.conf に書かれている内容を npf 用の /etc/npf.conf に書き直すには以下のようにするようでござる。


# physical network interface
$ext_if = inet4(wm0)

# local private network
$local_net = 10.0.0.0/24

# NAT
map $ext_if dynamic 10.0.0.0/24 -> $ext_if

# packet filter for wm0 interface
group "public" on $ext_if {
    # from outside to inside
    pass stateful in proto udp to $ext_if port 12345
    pass stateful out final all
}

# packet filter rule for wg0 interface
group "wg" on wg0 {
    # passing everything
    pass stateful in all
    pass stateful out all
}

# default
group default {
    pass final all
}

pf 用の設定ファイル /etc/pf.conf が正しい書式で書かれているかどうか確 認するためには、以下のようにすればよいでござる。


# pfctl -nf /etc/pf.conf

それに対して、 npf 用の設定ファイル /etc/npf.conf が正しい書式で書かれ ているかどうか確認するためには、以下のようにすればよいようでござる。


# npfctl validate

npf を起動させるには、 /etc/rc.conf に npf=YES と書いておき、以下を実 行すればよいでござる。


# /etc/rc.d/npf start



Frequently accessed files

  1. Computer___Network/20260127_00.html
  2. Misc___Taiwan/20240207_00.html
  3. Computer___NetBSD/20250301_01.html
  4. Misc___Taiwan/20240819_00.html
  5. Book___Chinese/20240424_00.html
  6. Computer___TeX/20231107_00.html
  7. Computer___TeX/20240414_01.html
  8. Misc___Japan/20240718_00.html
  9. Misc___Japan/20240610_00.html
  10. Computer___TeX/20240411_00.html
  11. Misc___Taiwan/20240903_01.html
  12. Computer___TeX/20230726_01.html
  13. Computer___Network/20241214_00.html
  14. Computer___Python/20230803_00.html
  15. Computer___Network/20230516_00.html
  16. Computer___NetBSD/20230119_00.html
  17. Computer___NetBSD/20250113_00.html
  18. Computer___FreeBSD/20220621_0.html
  19. Computer___TeX/20240414_00.html
  20. Computer___NetBSD/20250307_00.html
  21. Computer___Network/20240130_00.html
  22. Computer___TeX/20240410_00.html
  23. Computer___Python/20250330_00.html
  24. Computer___NetBSD/20220818_1.html
  25. Computer___NetBSD/20240805_03.html
  26. Computer___TeX/20230503_00.html
  27. Computer___Network/20220413_1.html
  28. Computer___Python/20240101_00.html
  29. Computer___NetBSD/20240101_03.html
  30. Computer___Hardware/20240820_00.html


HTML file generated by Kinoshita Daisuke.