当前位置:首页 > Linux > 正文内容

Linux CentOS 7 防火墙/端口设置

放牧的风6年前 (2019-01-28)Linux1076

CentOS升级到7之后用firewall代替了iptables来设置Linux端口,

下面是具体的设置方法:

[]:选填

<>:必填

[<zone>]:作用域(block、dmz、drop、external、home、internal、public、trusted、work)

<port>:端口号

[-<port>]:或者端口范围

<protocol>:端口协议(tcp、udp)

[<seconds>]:过期时间,使用N秒后自动关闭(秒)

[--permanent]:永久设置,在重启后依然保证设置可用,如果不加此项,重启后端口会恢复关闭状态

注:设置端口后要重启防火墙使其生效 firewall-cmd --reload

1、检查端口状态

yes:已开通

no:未开通

firewall-cmd --query-port=<port>[-<port>]/<protocol>
firewall-cmd [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>
firewall-cmd [--permanent] [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

1010568-20190128183602618-1753651140.png

 查看已开放的端口

firewall-cmd --zone=public --list-ports

172889-20160831154143324-870883085.jpg

2、启用端口

success:执行成功

warning:警告xxx

firewall-cmd --add-port=<port>[-<port>]/<protocol>
firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
firewall-cmd [--permanent] [--zone=<zone>] --add-port=<port>[-<port>]/<protocol>

172889-20160831135015496-617743534.jpg

3、禁用端口 

success:执行成功

warning:警告xxx

firewall-cmd --remove-port=<port>[-<port>]/<protocol>
firewall-cmd [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>
firewall-cmd [--permanent] [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>

172889-20160831135028121-1364100740.jpg

4、防火墙相关

--reload:不改变状态的条件下重启防火墙

--complete-reload:状态信息将会丢失,当防火墙有问题时可以使用,如,状态信息和防火墙规则都正常却无法建立任何链接的情况等

firewall-cmd --reload
firewall-cmd --complete-reload

查看防火墙状态

firewall-cmd --state

查看、打开、关闭应急模式(应急模式阻断所有网络连接,防止出现紧急状况)

firewall-cmd --query-panic
firewall-cmd --panic-on
firewall-cmd --panic-off

打开、关闭、重启防火墙 

systemctl stop firewalld
systemctl start firewalld
systemctl restart firewalld

 开启/关闭 开机自启动防火墙

systemctl enable firewalld
systemctl disable firewalld

 参考:https://www.cnblogs.com/taiyonghai/p/5825578.html


扫描二维码推送至手机访问。

版权声明:本文由放牧的风发布,如需转载请注明出处。

本文链接:https://grazingwind.com/post/31.html

分享给朋友:
返回列表

没有更早的文章了...

下一篇:CentOS7一键安装nodejs

相关文章

CentOS下配置redis允许远程连接

CentOS下配置redis允许远程连接

1. 目的因为想要学习redis,因此在虚拟机中安装了redis,为了实现在物理机可以访问redis,弄了好久;因此记录下来,以免忘记。2. 环境虚拟机:CentOS Linux release 7.4.1708 (Core)redis:4...

linux服务器git pull/push时提示输入账号密码之免除设置

linux服务器git pull/push时提示输入账号密码之免除设置

1、先cd到根目录,执行git config --global credential.helper store命令[root@iZ25mi9h7ayZ ~]# git config --global&...

VPS免费检测工具

VPS免费检测工具

1、一键测试服务器到国内的速度脚本Superspeed.sh :wget https://raw.githubusercontent.com/oooldking/script/master/superspeed.shchmod&n...

ubuntu下screen的使用

ubuntu下screen的使用

关掉xshell之后执行的脚本也随之停止,我们可以使用screen命令,来让保证退出ssh之后程序继续在后台跑。利用SSH远程连接服务器,运行程序需要保证在此期间窗口不能关闭并且连接不能断开,否则当前窗口所运行的任务就被杀死。参考GNU&#...

CentOS下文件/文件夹的压缩和解压命令用法详解

CentOS下文件/文件夹的压缩和解压命令用法详解

tar功能:文件的压缩或解压语法:tar 命令-c 建立一个压缩文件的参数指令(create) –压缩-x 解开一个压缩文件的参数指令(extract) –解压-z 是否需要gzip压缩-v 显示压缩的过程(verbose)-f 使用档名,...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。