windows添加端口规则(入站规则):

单个端口:

 netsh advfirewall firewall add rule name ="1111111111111" dir=in localport=8888 protocol=tcp action=allow

 netsh advfirewall firewall add rule name=1111111111111 dir=in localport=111 protocol=TCP action=allow

端口段:

(放行):

netsh advfirewall firewall add rule name=111111111111端口段 dir=in localport=111-222 protocol=TCP action=allow

(拦截):

netsh advfirewall firewall add rule name=111111111111端口段 dir=in localport=111-222 protocol=TCP action=block

 

Linux添加端口规则:

单个端口:   iptables -A INPUT -p TCP --dport 1111 -j ACCEPT

端口段:       iptables -A INPUT -p TCP --dport 111:222 -j ACCEPT

拦截: iptables -A INPUT -p TCP --dport 111:222 -j REJECT

 

 

windows添加ip规则(入站):

netsh advfirewall firewall add rule name=测试规则放行192.168.0.10 protocol=any dir=in action=allow remoteip=192.168.0.10

 

linux添加ip规则:

(单个ip放行)iptables -I INPUT -s 192.168.0.10 -j ACCEPT

(ip段拦截)iptables -I INPUT -s 192.168.0.0/24 -j DROP

 

注意:Linux每次都需要重启防火墙

           windows的端口写法是111-222,linux是111:222

参考:https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/dd734783(v=ws.10)

Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐