一、查看防火墙状态

1、首先查看防火墙是否开启,如未开启,需要先开启防火墙并作开机自启
systemctl status firewalld
在这里插入图片描述
开启
在这里插入图片描述
开启防火墙并设置开机自启
systemctl start firewalld
systemctl enable firewalld

二、开放或限制端口

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
输出yes 表示开启,no表示未开启
(4)如下命令可查看当前系统打开的所有端口
firewall-cmd --zone=public --list-ports
详细信息
firewall-cmd --list-all
2、限制端口
(1)比如我们现在需要关掉刚刚打开的22端口
firewall-cmd --zone=public --remove-port=22/tcp --permanent
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd --reload
在这里插入图片描述
3、更改文件方式开放端口
iptables -A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT //开放8080端口
iptables-save
4、开放了那些白名单
firewall-cmd --zone=public --list-rich-rules
5、限制ip
比如限制IP为192.168.0.200的地址禁止访问80端口即禁止访问机器
firewall-cmd --permanent --add-rich-rule=“rule family=“ipv4” source address=“192.168.0.200” port protocol=“tcp” port=“80” reject”
6、防火墙重启
systemctl restart firewalld
7、删除规则
firewall-cmd --remove-rich-rule ‘****’ --permanent
****表示要删除的规则
firewall-cmd --reload
firewall-cmd --list-all
防火墙启动关闭
1、启动防火墙
systemctl start firewalld
2、关闭防火墙
systemctl stop firewalld
3、查看状态
systemctl status firewalld
4、开机禁用
systemctl disable firewalld
5、开机启用
systemctl enable firewalld

开启Linux系统的22端口(linux22端口开启)

1、第一步,让我们首先登录Linux系统,使用root帐号,可以使用putty进行登录。
2、打开终端,使用vim或者nano等编辑器打开文件/etc/ssh/sshd_config。
3、在文件中找到“#Port 22 ”,将它改成Port 22,表明要开放22端口。
4、然后,保存更改,然后用以下命令重启ssh服务:/etc/init.d/ssh restart
5、最后,使用自己的帐号登录Linux系统,并用ssh localhost命令来确保开放功能:
ssh user@localhos。
以上就是开启Linux系统的22端口的方法,使用此方法可以让Linux操作系统更加安全。通过开放端口,可以使Linux系统得到更好的控制,并可以管理系统中的其他应用程序和服务。如果是必须将开放端口关闭,也可以使用/etc/init.d/ssh stop命令将22端口关闭。

Logo

快速构建 Web 应用程序

更多推荐