前面讲过命令行创建IP安全策略(IPSEC),让系统更安全,但是IPSEC只能针对IP、端口、协议等进行简单限制,而防火墙功能更强大!除了IPSEC的功能,还可以对文件、网卡等进行限制。
操作之前,需要先确定两个东西,一个是防火墙的服务处于运行状态:
另一个是防火墙的设置没有被关闭:
命令操作防火墙示例例1:创建一个电脑 名称为QQ的入站规则和出站规则,并限制它访问网络:netsh advfirewall firewall add rule name="QQ" dir=in program="C:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe" action=blocknetsh advfirewall firewall add rule name="QQ" dir=out program="C:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe" action=block
netsh advfirewall firewall add rule name="QQ" dir=in program="C:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe" action=allownetsh advfirewall firewall add rule name="QQ" dir=out program="C:\Program Files (x86)\Tencent\QQ\Bin\QQ.exe" action=allow
netsh advfirewall firewall add rule name="QQ" dir=in program="C:\Program Files (x86)\Tencent\QQ\Bin\电脑QQ.exe" security=authenticate action=allow
netsh advfirewall firewall add rule name="网站端口" dir=out protocol=TCP remoteport=80,443 action=block
netsh advfirewall firewall set rule "网站端口" new enable=no
netsh advfirewall 电脑firewall delete rule name="网站端口"
netsh advfirewall firewall add rule name="安全防护" dir=in protocol=TCP localport=135,139,445 action=block
netsh advfirewall firewall add rule name="谷歌DNS" dir=out remoteip=8.8.8.8,8.8.4.4 action=block
限制单个IP访问本机:netsh advfirewall firewall add rule name="禁止访问IP" dir=in remoteip=192.168.1.1 ?action=block限制一段IP访问本机:netsh advfirewall firewall add rule name="禁止访问IP" dir=in remoteip=192.168.1.1-192.168.1.100 ?action=block限制一个子网访问本机:netsh advfirewall firewall add rule name="禁止访问IP" dir=in remoteip=192.168.1.0/24 ?action=block电脑
禁止本机ping其它机子:ipv4:netsh advfirewall firewall add rule name="ipv4禁Ping" dir=out protocol=icmpv4 action=blockipv6:netsh advfirewall firewall add rule name="ipv6禁Ping" dir=out protocol=icmpv6 action=block禁止其它机子ping本机:ipv4:netsh advfirewall firewall add rule name="ipv4禁Ping" dir=in protocol=icmpv4 action=blockipv6:netsh advfirewall firewall add rule name="ipv6禁Ping" dir=in protocol=icmpv6 action=block
netsh advfirewall firewall add rule name="无线网络" dir=out interfacetype=wireless action=block
运行中输入:wf.msc 回车,可以快速打开防火墙的高级设置:
电脑dir=in 是入站规则。其它主动访问本机,属于“入站”
dir=out 是出站规则。本机主动访问其它,属于“出站”
限制访问的规则优先于允许访问的规则!
?
电脑 电脑