host-npf.conf revision 1.12
11.12Stsutsui# $NetBSD: host-npf.conf,v 1.12 2023/07/31 16:09:01 tsutsui Exp $
21.2Sspz#
31.9Ssevan# Simple ruleset for a host with (i.e., not routing) two interfaces,
41.9Ssevan# ethernet and wifi.
51.1Sspz#
61.9Ssevan# DHCP (v4 and v6), SLAAC, ICMPv6, ICMP echo requests, traceroute, mDNS traffic
71.9Ssevan# are permitted, inbound, on either interface.
81.9Ssevan#
91.9Ssevan# SSH to the host is allowed in via the ethernet interface.
101.9Ssevan# blacklistd(8) is used to prevent SSH bruteforce attempts.
111.9Ssevan#
121.9Ssevan# No specific rules for the wifi interface.
131.9Ssevan#
141.9Ssevan# All traffic from the host is permitted, outbound, on either interface.
151.1Sspz#
161.4Srmind
171.1Sspz$wired_if = "wm0"
181.9Ssevan$wifi_if  = "iwn0"
191.12Stsutsui$wired_addrs= ifaddrs($wired_if)
201.12Stsutsui$wifi_addrs = ifaddrs($wifi_if)
211.1Sspz
221.9Ssevanalg "icmp"
231.1Sspz
241.1Sspzprocedure "log" {
251.10Ssevan    # Send log events to npflog0, see npfd(8)
261.10Ssevan    log: npflog0
271.1Sspz}
281.1Sspz
291.5Sspzgroup "wired" on $wired_if {
301.10Ssevan    # Placeholder for blacklistd (configuration separate) to add blocked hosts
311.10Ssevan    ruleset "blacklistd"
321.1Sspz
331.10Ssevan    # Allow SSH on wired interface and log all connection attempts
341.11Ssevan    pass stateful in on $wired_if proto tcp to $wired_addrs port ssh apply "log"
351.1Sspz}
361.1Sspz
371.5Sspzgroup "wifi" on $wifi_if {
381.9Ssevan
391.1Sspz}
401.1Sspz
411.5Sspzgroup default {
421.10Ssevan    # Default deny, otherwise last matching rule wins
431.10Ssevan    block all apply "log"
441.9Ssevan
451.10Ssevan    # Don't block loopback
461.10Ssevan    pass on lo0 all
471.9Ssevan
481.10Ssevan    # Allow incoming DHCP server responses
491.10Ssevan    pass in family inet4 proto udp from any port bootps to any port bootpc
501.10Ssevan    pass in family inet6 proto udp from any to any port "dhcpv6-client"
511.9Ssevan
521.10Ssevan    # Allow IPv6 ICMP
531.10Ssevan    pass family inet6 proto ipv6-icmp all
541.9Ssevan
551.10Ssevan    # Allow incoming IPv4 pings
561.10Ssevan    pass in family inet4 proto icmp icmp-type echo all
571.9Ssevan
581.10Ssevan    # Allow being tracerouted
591.10Ssevan    pass in proto udp to any port 33434-33600
601.9Ssevan
611.10Ssevan    # Allow incoming mDNS traffic from neighbours
621.10Ssevan    pass in proto udp to any port mdns
631.9Ssevan
641.10Ssevan    # Allow all outbound traffic
651.10Ssevan    pass stateful out all
661.1Sspz}
67