
나는 네트워크가 변경될 때마다 pf 규칙을 다시 로드하려고 노력해 왔습니다. 여기 내 plist 파일이 있습니다. /Library/LaunchAgents/com.wwk.networkchange.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.wwk.networkchange</string>
<key>ProgramArguments</key>
<array>
<string>sudo /sbin/pfctl -f /Users/wwk/pf.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WatchPaths</key>
<array>
<string>/private/var/run/resolv.conf</string>
</array>
</dict>
</plist>
네트워크 인터페이스가 변경되면 /private/var/run/resolv.conf가 변경되지만 pf 규칙은 전혀 다시 로드되지 않는 것을 볼 수 있습니다. 참고로, /Users/wwk/pf.conf가 있고 /etc/sudoers 파일을 통해 비밀번호 프롬프트 없이 /sbin/pfctl이 실행되도록 활성화했습니다. 미리 감사드립니다!
답변1
실제로 그것은 내 새 데몬이 Apple의 기본 pfctl 데몬과 충돌했기 때문이었습니다. 그래서 네트워크가 변경될 때마다 변경되는 경로를 감시하기 위해 기본 pfctl 데몬 plist를 업데이트해야 했습니다. 다음에 다음을 추가하십시오./System/Library/LaunchDaemons/com.apple.pfctl.plist
<WatchPaths>
<array>
<string>/private/var/run/resolv.conf</string>
<string>/etc/pf.conf</string>
<string>/Library/Preferences/SystemConfiguration/NetworkInterfaces.plist</string>
<string>/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist</string>
</array>
$ csrutil disable
그런데 위의 plist 파일을 변경하려면 macOS 복구 모드에서 시스템 파일 변경을 활성화해야 합니다 . ( $ csrutil enable
시스템 파일을 필요한 대로 변경한 후에 수행해야 함)