macOS Sierra: recarregue o firewall quando a rede mudar

macOS Sierra: recarregue o firewall quando a rede mudar

Tenho tentado recarregar as regras de PF sempre que a rede muda. Aqui está meu arquivo 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>

Posso ver que /private/var/run/resolv.conf é alterado quando as interfaces de rede são alteradas, mas as regras de PF não são recarregadas. Para sua informação, /Users/wwk/pf.conf está lá e eu habilitei /sbin/pfctl para ser executado sem solicitação de senha por meio do arquivo /etc/sudoers. Obrigado desde já!

Responder1

Na verdade, foi porque meu novo daemon entrou em conflito com o daemon pfctl padrão da Apple. Então, tive que atualizar o plist daemon pfctl padrão para observar os caminhos que são alterados sempre que a rede muda. Adicione o seguinte ao/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>

A propósito, temos que habilitar alterações nos arquivos do sistema no $ csrutil disablemodo de recuperação do macOS para fazer alterações no arquivo plist acima. (deve ser feito $ csrutil enableapós as alterações necessárias nos arquivos do sistema)

informação relacionada