Centos 7 set firewall to open specified ports

1. Centos7 set up firewall and open ports

  1. View open ports (no ports are opened by default)
    firewall-cmd --list-ports
  2. open port 80 
    firewall-cmd --zone=public (scope) --add-port= 80 /tcp (port and access type) --permanent (permanent effect)
  3. restart firewall 
    firewall-cmd --reload
  4. stop firewall 
    systemctl stop firewalld.service
  5. Disable firewall startup 
    systemctl disable firewalld.service
  6. delete the specified port
    firewall-cmd --zone=public (scope) --remove-port= 80 /tcp (port and access type) --permanent (permanent)

     

2. Set firewall and open ports below Centos 7

  1. Open ports 80, 22, 8080
    /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT 
    /sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT 
    /sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT 
  2. keep
    /etc/rc.d/init.d/iptables save
  3. View open ports
    /etc/init.d/iptables status
  4. turn off firewall
    1.  Permanent effect, will not be restored after restart
      Enable: chkconfig iptables on
      Off: chkconfig iptables off
    2. Takes effect immediately, restores after restart
      Start: service iptables start
      Shutdown: service iptables stop

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324519860&siteId=291194637