2014-05-25 :-)
_ [NetBSD][npf][npf.conf]NetBSD npf.conf の例を読む
ref.
host-npf.conf
例 /usr/share/examples/npf/host-npf.conf
有線と無線のネットワーク
# $NetBSD: host-npf.conf,v 1.2.4.4 2012/12/15 23:31:07 riz Exp $
#
# this is an example of NPF rules for a host (i.e., not routing) with
# two network interfaces, wired and wifi
#
# it does both IPv4 and IPv6 and allows for DHCP in v4 and SLAAC in v6
# it also does IPSEC on the wifi
#
# 有線 NIC は wm0
$wired_if = "wm0"
# IPv4 ネットワークアドレス
$wired_v4 = { inet4(wm0) }
# IPv6 ネットワークアドレス
$wired_v6 = { inet6(wm0) }
# 無線 NIC は iwn0
$wifi_if = "iwn0"
# IPv4 ネットワークアドレス
$wifi_v4 = { inet4(iwn0) }
# IPv6 ネットワークアドレス
$wifi_v6 = { inet6(iwn0) }
# DHCP サーバーのアドレス
$dhcpserver = { 198.51.100.1 }
# ntp を使う
$services_udp = { ntp }
# sample mixed service
# バックアップサーバー IPv4
$backupsrv_v4 = { 198.51.100.11 }
# バックアップサーバー IPv6
$backupsrv_v6 = { 2001:0DB8:404::11 }
# バックアップのポート amanda を使う
$backup_port = { amanda }
# npflog0 を使ってログする。という処理を定義。定義の名前は "log"
procedure "log" {
log: npflog0
}
# グループを定義。名前: "wired" インターフェース: $wired_if
group (name "wired", interface $wired_if) {
# 以下のものを許可。final なので必ずこのルールを使う
# 内向きパケット
# IPv6
# ICMP
pass in final family inet6 proto ipv6-icmp all
# 以下のものを許可。final なので必ずこのルールを使う
# 外向きパケット
# IPv6
# ICMP
pass out final family inet6 proto ipv6-icmp all
# 以下のものを許可。final なので必ずこのルールを使う
# 内向きパケット
# IPv4 {注: inet じゃなくて inet4 じゃないのか?}
# ICMP
pass in final family inet proto icmp all
# 以下のものを許可。final なので必ずこのルールを使う
# 内向きパケット
# IPv4
# TCP
# 送信元: $dhcpserver のポート bootps
# 送信先: $wired_v4 の ポート bootpc
pass in final family inet proto tcp \
from $dhcpserver port bootps to $wired_v4 port bootpc
# ↑を udp にも適用
pass in final family inet proto udp \
from $dhcpserver port bootps to $wired_v4 port bootpc
# 以下のものを許可。final なので必ずこのルールを使う
# 内向きパケット
# IPv6
# TCP
# 送信先: $wired_v6 の ssh
pass in final family inet6 proto tcp to $wired_v6 port ssh
# 以下のものを許可。final なので必ずこのルールを使う
# 内向きパケット
# IPv4
# TCP
# 送信元: $backupsrv_v4
# 送信先: $wired_v4 ポート $backup_port
# S/SA ( S と A (SYN と ACK) フラグだけに注目し、SYN フラグが "on" の場合に マッチ )
pass in final family inet proto tcp flags S/SA \
from $backupsrv_v4 to $wired_v4 port $backup_port
# 以下のものを許可。final なので必ずこのルールを使う
# 内向きパケット
# IPv4
# UDP
# 送信元: $backupsrv_v4
# 送信先: $wired_v4 ポート $backup_port
pass in final family inet proto udp \
from $backupsrv_v4 to $wired_v4 port $backup_port
# 以下のものを許可。final なので必ずこのルールを使う
# 内向きパケット
# IPv6
# TCP
# S/SA
# 送信元: $backupsrv_v6
# 送信先: $wired_v6 ポート $backup_port
pass in final family inet6 proto tcp flags S/SA \
from $backupsrv_v6 to $wired_v6 port $backup_port
# 以下のものを許可。final なので必ずこのルールを使う
# 内向きパケット
# IPv6
# UDP
# 送信元: $backupsrv_v6
# 送信先: $wired_v6 ポート $backup_port
pass in final family inet6 proto udp \
from $backupsrv_v6 to $wired_v6 port $backup_port
# 以下のものを許可。final なので必ずこのルールを使う。stateful で状態監視
# 内向きパケット
# IPv6
# UDP
# 送信先: $wired_v6 ポート $services_udp
pass stateful in final family inet6 proto udp to $wired_v6 \
port $services_udp
# 以下のものを許可。final なので必ずこのルールを使う。stateful で状態監視
# 内向きパケット
# IPv4
# UDP
# 送信先: $wired_v6 ポート $services_udp {注: wired_v4 ではないのか?}
pass stateful in final family inet proto udp to $wired_v6 \
port $services_udp
# 以下のものを許可。final なので必ずこのルールを使う。stateful で状態監視
# 外向きパケット
# IPv6
# TCP
# フラグ S/SA
# 送信元: $wired_v6
pass stateful out final family inet6 proto tcp flags S/SA \
from $wired_v6
# 以下のものを許可。final なので必ずこのルールを使う。stateful で状態監視
# 外向きパケット
# IPv4
# TCP
# フラグ S/SA
# 送信元: $wired_v4
pass stateful out final family inet proto tcp flags S/SA \
from $wired_v4
# 以下のものを許可。final なので必ずこのルールを使う。
# 外向きパケット
# IPv6
# TCP
# 送信元: $wired_v6
pass out final family inet6 proto tcp from $wired_v6
# IPv4 も同様
pass out final family inet proto tcp from $wired_v4
# 以下のものを許可。final なので必ずこのルールを使う。stateful で状態監視
# 外向きパケット
# IPv6
# 送信元: $wired_v6
pass stateful out final family inet6 from $wired_v6
# IPv4 も同様
pass stateful out final family inet from $wired_v4
}
# 省略
group (name "wifi", interface $wifi_if) {
:
:
:
}
# デフォルトグループ。default は必須
group (default) {
# lo0 をすべて許可
pass final on lo0 all
# ブロックしたパケットに "log" で処理
block all apply "log"
}
soho_gw-npf.conf
例 /usr/share/examples/npf/soho_gw-npf.conf
NAT です
# $NetBSD: soho_gw-npf.conf,v 1.2.4.4 2012/12/15 23:31:07 riz Exp $
#
# SOHO border
#
# This is a natting border gateway/webserver/mailserver/nameserver
# IPv4 only
#
# 外部インターフェースは wm0
$ext_if = "wm0"
# wm0 のアドレス
$ext_v4 = inet4(wm0)
# ifnet ってなんだ。inet4 がアドレスじゃないのか
$ext_addrs = { ifnet(wm0) }
# 内側インターフェースは wm1
$int_if = "wm1"
# 1 という名前の静的テーブル。ハッシュ型。内容は hashtablefile から読む
table <1> type hash file "/usr/share/examples/npf/hashtablefile"
# 2 という名前の動的テーブル。ツリー型
table <2> type tree dynamic
# TCP のサービス
$services_tcp = { http, https, smtp, domain, 6000, 9022 }
# UDP のサービス
$services_udp = { domain, ntp, 6000 }
$localnet = { 198.51.100.0/24 }
# NAT 生成。$ext_if で 198.51.100.0/24 から $ext_v4 へ転送。
map $ext_if dynamic 198.51.100.0/24 -> $ext_v4
# NAT traffic arriving on port 9022 of the external interface address
# to host 198.51.100.2 port 22
# NAT 生成。$ext_if で $ext_v4 port 9022 から 198.51.100.2 port 22 へ転送
map $ext_if dynamic 198.51.100.2 port 22 <- $ext_v4 port 9022
# "log" というプロシージャを定義
procedure "log" {
log: npflog0
}
# グループ 名前は "external" NIC は $ext_if
group (name "external", interface $ext_if) {
# 以下のものを許可。final なので必ずこのルールを使う。stateful で状態監視
# すべてのパケット
pass stateful out final all
# 以下のものを破棄。final なので必ずこのルールを使う。
# グループ <1> からのすべてのパケット
block in final from <1>
# 以下のものを許可。final なので必ずこのルールを使う。stateful で状態監視
# 内向きパケット
# IPv4
# TCP
# 送信先 $ext_v4 port ssh
# プロシージャ "log" を実行
pass stateful in final family inet proto tcp to $ext_v4 port ssh \
apply "log"
# 以下のものを許可。final なので必ずこのルールを使う。stateful で状態監視
# 内向きパケット
# TCP
# 送信先 $ext_addrs port $services_tcp
pass stateful in final proto tcp to $ext_addrs port $services_tcp
# UDP も同様
pass stateful in final proto udp to $ext_addrs port $services_udp
# Passive FTP
# 以下のものを許可。final なので必ずこのルールを使う。stateful で状態監視
# 内向きパケット
# TCP
# 送信先 $ext_addrs port 49151-65535
pass stateful in final proto tcp to $ext_addrs port 49151-65535
# Traceroute
# 以下のものを許可。final なので必ずこのルールを使う。stateful で状態監視
# 内向きパケット
# UDP
# 送信先 $ext_addrs port 33434-33600
pass stateful in final proto udp to $ext_addrs port 33434-33600
}
# グループ 名前は "internal" NIC は $int_if
group (name "internal", interface $int_if) {
# すべてのパケットを破棄
block in all
# 以下のものを許可。final なので必ずこのルールを使う。↑の block in all を上書き
# 内向きパケット
# 送信元 グループ <2>
pass in final from <2>
# 以下のものを許可。final なので必ずこのルールを使う。↑の block in all を上書き
# 外向きパケット
# あらゆるパケット
pass out final all
}
# デフォルト
# ようするにデフォルト破棄
group (default) {
# lo0 をすべて許可。final なので必ずこのルールを使う
pass final on lo0 all
# すべてのパケットを破棄
block all
}
[ツッコミを入れる]








