Enabling the Firewall

# enable firewall
systemctl start firewalld
Copy the code

Disabling the Firewall

# disable firewall
systemctl stop firewalld.service
Copy the code

Viewing a Firewall

Check the firewall status
firewall-cmd --state
Copy the code

Restarting the Firewall

Restart the firewall (after modifying the configuration)
firewall-cmd --reload
Copy the code

Viewing Open Ports

View all open ports on the firewall
firewall-cmd --zone=public --list-ports
Copy the code

Port configuration

Open port 8090
firewall-cmd --zone=public --add-port=8090/tcp --permanent

# Disable port 6379
firewall-cmd --zone=public --remove-port=6379/tcp --permanent

Allow HTTP communication
firewall-cmd --permanent --zone=public --add-service=http

# allow HTTPS communication
firewall-cmd --permanent --zone=public --add-service=https
Copy the code

Locking the firewall

Execute the command when locking firewalld
systemctl mask firewalld
Copy the code

unlocked

To unlock firewalld, run the following command
systemctl unmask firewalld
Copy the code

Viewing Listening Ports

# check the listening port
netstat -lnpt

Note: Centos7 does not have the netstat command by default. You need to install net-tools
yum install -y net-tools
Copy the code

Checking Port Usage

Check which process is occupying the port
netstat -lnpt |grep 6379
Copy the code

Check the process

View the details of the process
ps 6832
ps axu | grep redis
Copy the code

Suspend the process

# abort process
kill6379-9Copy the code