透過 GUI 逐台設定防火牆效率極低,需以批次檔(`.bat`)推送至區域網路所有終端。測試環境:宿主機 Win7 32-bit,虛擬機 XP(NAT/橋接模式均測)。
netsh advfirewall set allprofiles state on
# 允許所有(預設)
netsh advfirewall set allprofiles firewallpolicy allowinbound,allowoutbound
# 拒絕所有
netsh advfirewall set allprofiles firewallpolicy blockinbound,blockoutbound
# TCP 139 (NetBIOS Session)
netsh advfirewall firewall add rule dir=in protocol=tcp localport=139 action=block
# UDP 139
netsh advfirewall firewall add rule dir=in protocol=udp localport=139 action=block
# TCP 445 (SMB)
netsh advfirewall firewall add rule dir=in protocol=tcp localport=445 action=block
# UDP 445
netsh advfirewall firewall add rule dir=in protocol=udp localport=445 action=block
netsh advfirewall reset
netsh advfirewall set allprofiles state on
netsh advfirewall set allprofiles firewallpolicy allowinbound,allowoutbound