Linux系统怎么使用firewall限制或开放IP及端口
导读:本文共5707字符,通常情况下阅读需要19分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 一、查看防火墙状态1、首先查看防火墙是否开启,如未开启,需要先开启防火墙并作开机自启systemctlstatusfirewalld开启防火墙并设置开机自启systemctlstartfirewalldsystemctlenablefirewalld一般需要重启一下机器,不然后面做的设置可能不会生效二、开放或限制端口1、开放端口(1)如我们需要开启XShel... ...
目录
(为您整理了一些要点),点击可以直达。一、查看防火墙状态
1、首先查看防火墙是否开启,如未开启,需要先开启防火墙并作开机自启
systemctlstatusfirewalld
开启防火墙并设置开机自启
systemctlstartfirewalldsystemctlenablefirewalld
一般需要重启一下机器,不然后面做的设置可能不会生效
二、开放或限制端口
1、开放端口
(1)如我们需要开启XShell连接时需要使用的22端口
firewall-cmd--zone=public--add-port=22/tcp--permanent
其中–permanent的作用是使设置永久生效,不加的话机器重启之后失效
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd--reload
(3)可通过如下命令查看是否生效
firewall-cmd--zone=public--query-port=22/tcp
(4)如下命令可查看当前系统打开的所有端口
firewall-cmd--zone=public--list-ports
2、限制端口
(1)比如我们现在需要关掉刚刚打开的22端口
firewall-cmd--zone=public--remove-port=22/tcp--permanent
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd--reload
(3)再去查看系统所有开放的端口,已经看到没有22端口了
firewall-cmd--zone=public--list-ports
3、批量开放或限制端口
(1)批量开放端口,如从100到500这之间的端口我们全部要打开
firewall-cmd--zone=public--add-port=100-500/tcp--permanent
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd--reload
(3)查看系统所有开放的端口,可以看到从100到500的端口已被全部开放
firewall-cmd--zone=public--list-ports
(4)同理,批量限制端口为
firewall-cmd--zone=public--remove-port=100-500/tcp--permanentfirewall-cmd--reload
三、开放或限制IP
1、限制IP地址访问
(1)比如限制IP为192.168.0.200的地址禁止访问80端口即禁止访问机器
firewall-cmd--permanent--add-rich-rule="rulefamily="ipv4"sourceaddress="192.168.0.200"portprotocol="tcp"port="80"reject"
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd--reload
(3)查看已经设置的规则
firewall-cmd--zone=public--list-rich-rules
2、解除IP地址限制
(1)解除刚才被限制的192.168.0.200
firewall-cmd--permanent--add-rich-rule="rulefamily="ipv4"sourceaddress="192.168.0.200"portprotocol="tcp"port="80"accept"
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd--reload
(3)再查看规则设置发现已经没有192.168.0.200的限制了
firewall-cmd--zone=public--list-rich-rules
如设置未生效,可尝试直接编辑规则文件,删掉原来的设置规则,重新载入一下防火墙即可
vi/etc/firewalld/zones/public.xml
3、限制IP地址段
(1)如我们需要限制10.0.0.0-10.0.0.255这一整个段的IP,禁止他们访问
firewall-cmd--permanent--add-rich-rule="rulefamily="ipv4"sourceaddress="10.0.0.0/24"portprotocol="tcp"port="80"reject"
其中10.0.0.0/24表示为从10.0.0.0这个IP开始,24代表子网掩码为255.255.255.0,共包含256个地址,即从0-255共256个IP,即正好限制了这一整段的IP地址,具体的设置规则可参考下表
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd--reload
(3)查看规则,确认是否生效
firewall-cmd--zone=public--list-rich-rules
(4)同理,打开限制为
firewall-cmd--permanent--add-rich-rule="rulefamily="ipv4"sourceaddress="10.0.0.0/24"portprotocol="tcp"port="80"accept"firewall-cmd--reload
Linux有哪些版本
Linux的版本有:Deepin、UbuntuKylin、Manjaro、LinuxMint、Ubuntu等版本。其中Deepin是国内发展最好的Linux发行版之一;UbuntuKylin是基于Ubuntu的衍生发行版;Manjaro是基于Arch的Linux发行版;LinuxMint默认的Cinnamon桌面类似Windows XP简单易用;Ubuntu则是以桌面应用为主的Linux操作系统。
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
Linux系统怎么使用firewall限制或开放IP及端口的详细内容,希望对您有所帮助,信息来源于网络。