Windows7提供窗口界面配置桌面防火墙,但操作比较繁琐,如果要在局域网所有终端上实施,会非常费时费力,因此打算用批处理文件实现。测试环境在我的电脑上,宿主机是Windows7 32位操作系统,为测试桌面防火墙的效果,使用一台虚拟机,操作系统是Windows XP操作系统。 .
虚拟机的网络我先后使用主机模式和桥接模式,主机模式使用Vnet3,虚拟机和主机对应Vnet3的网卡设置同一网段的地址;桥接模式使用默认的Vnet0,虚拟机与主机使用同一网段的地址。测试时发现桌面防火墙禁用139和445端口能生效,但禁用21端口却不生效,感觉十分奇怪,如果有知道的朋友,也请告诉我一下。
.
下面是配置Windows7桌面防火墙使用的命令。写了两个批处理文件,一个是配置桌面防火墙禁用一些危险端口;另一个是恢复桌面防火墙的初始配置。 .
1.配置桌面防火墙 .
(1)启用桌面防火墙 netsh advfirewall set allprofiles state on .
(2)设置默认输入和输出策略 netsh advfirewall set allprofiles firewallpolicy allowinbound,allowoutbound 以上是设置为允许,如果设置为拒绝使用blockinbound,blockoutbound .
(3)关闭tcp协议的139端口 netsh advfirewall firewall add rule dir=in protocol=tcp localport=139 action=block .
(4)关闭udp协议的139端口 netsh advfirewall firewall add rule dir=in protocol=udp localport=139 action=block .
(5)关闭tcp协议的445端口 netsh advfirewall firewall add rule dir=in protocol=tcp localport=445 action=block
.
(6)关闭udp协议的445端口 netsh advfirewall firewall add rule dir=in protocol=udp localport=445 action=block .