欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

学习如何设置Linux基本防火墙和打开端口的命令

最编程 2024-08-11 14:39:55
...

关闭防火墙

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 永久生效,没有此参数重启后失效 


推荐阅读