Linux基本防火墙设置和开放端口命令

系统 Linux
本文主要介绍CentOS 7、RedHat 7 之前的 Linux 发行版防火墙开启和关闭( iptables )、开放端口。

Linux基本防火墙设置和开放端口命令

关闭防火墙

CentOS 7、RedHat 7 之前的 Linux 发行版防火墙开启和关闭( iptables ):

即时生效,重启失效

  1. #开启 
  2. service iptables start 
  3. #关闭 
  4. service iptables stop 

 

重启生效

  1. #开启 
  2. chkconfig iptables on 
  3. #关闭 
  4. chkconfig iptables off 

 

CentOS 7、RedHat 7 之后的 Linux 发行版防火墙开启和关闭( firewall ):

  1. systemctl stop firewalld.service 

开放端口

CentOS 7、RedHat 7 之前的 Linux 发行版开放端口

  1. #命令方式开放5212端口命令 
  2.  
  3. #开启5212端口接收数据 
  4. /sbin/iptables -I INPUT -p tcp --dport 5212 -j ACCEPT 
  5.  
  6.  
  7. #开启5212端口发送数据 
  8. /sbin/iptables -I OUTPUT -p tcp --dport 5212 -j ACCEPT 
  9.  
  10. #保存配置 
  11. /etc/rc.d/init.d/iptables save 
  12.  
  13. #重启防火墙服务 
  14. /etc/rc.d/init.d/iptables restart 
  15.  
  16. #查看是否开启成功 
  17. /etc/init.d/iptables status 

 

CentOS 7、RedHat 7 之后的 Linux 发行版开放端口

  1. firewall-cmd --zone=public --add-port=5121/tcp --permanent 
  2. --zone 作用域 
  3. --add-port=5121/tcp 添加端口,格式为:端口/通讯协议 
  4. --permanent ***生效,没有此参数重启后失效 

 

责任编辑:庞桂玉 来源: segmentfault
相关推荐

2010-03-31 17:43:44

CentOS防火墙

2018-07-17 15:25:02

Linux防火墙端口

2009-12-02 18:54:28

2010-11-19 14:14:11

Oracle服务端口

2018-02-06 10:53:53

2009-12-24 11:00:55

2011-03-15 17:25:38

2009-07-06 17:00:17

Ubuntu Linushorewall防火墙

2009-09-28 10:06:09

Linux防火墙Linux规则

2011-03-17 16:00:57

2009-02-22 09:30:24

2011-03-15 16:35:27

2020-04-07 13:20:52

Linux防火墙ufw

2010-08-20 11:08:46

2009-12-02 18:34:29

Linux关闭防火墙命

2009-12-08 17:37:49

Windows 7防火

2022-01-06 07:59:05

Linux 防火墙进程

2009-09-24 13:53:53

2013-07-04 10:16:24

2010-09-14 14:55:46

点赞
收藏

51CTO技术栈公众号