防火墙管理

恢复初始防火墙设置

netsh advfirewall reset

关闭/开启防火墙

netsh advfirewall set allprofiles state off/on

查看防火墙策略

netsh advfirewall firewall show rule name=all

设置默认出入策略:允许/禁止

netsh advfirewall set allprofiles firewallpolicy allowinbound/blockinbound,allowoutbound/blockoutbound

端口管理

开启/关闭端口TCP/UDP

netsh advfirewall firewall add rule name="说明或备注" dir=in protocol=tcp/udp localport=端口 action=allow/block

端口转发

显示端口转发

netsh interface portproxy show all

开启端口转发

netsh interface portproxy add v4tov4 listenaddress=192.168.10.2 listenport=120 connectaddress=192.168.10.3 connectport=22

删除端口转发

netsh interface portproxy delete v4tov4 listenaddress=192.168.10.2 listenport=120

网卡管理

查看网卡接口

netsh interface show interface

禁用/启用网卡

netsh interface set interface "接口名称" disabled/enabled

修改IP地址addr和子网掩码mask

netsh interface ip set address name="接口名称" source=static addr=192.168.10.100 mask=255.255.255.0

修改网关gateway

netsh interface ip set address name="接口名称" gateway=192.168.10.1 gwmetric=0

修改首选(PRIMARY)的DNS

netsh interface ip set dns name="接口名称" source=static addr=8.8.8.8 register=PRIMARY

复合命令:判断端口是否监听

netstat -ano -p tcp | findstr "443" >nul 2>nul && echo 端口状态:已监听 || echo 端口状态:未监听

参考

Microsofa netsh advfirewall documentation)
Microsoft about how to use 'netsh firewall' and 'netsh advfirewall firewall'
Microsoft Windows Server documentation

最后修改:2021 年 03 月 25 日 08 : 56 AM
如果觉得文章帮助了您,您可以随意赞赏。