CentOS7 firewall and port related commands introduction

CentOS7 firewall and port related commands introduction

The corresponding Linux system version in the following situation is CentOS7. If the environment used is CentOS6, please use service iptables state/start/stop/restart to replace the corresponding systemctl status /start/stop/restart firewalld.service command;

1. Check the current status of the firewall

Method 1

 [root@hu ~]# firewall-cmd --state
not running ---Not running [root@hu ~]# firewall-cmd --state
Running --- Running

Method 2

 [root@hu ~]# systemctl status firewalld.service
Normal operation 👇

Figure 1

Abnormal/Not running👇

insert image description here

2. Start the firewall service

 [root@hu ~]# systemctl start firewalld.service

3. Disable the firewall service

 [root@hu ~]# systemctl stop firewalld.service

4. Open the specified port

 #Add the --permanent parameter, restart the service to take effect and permanently take effect;
#If the --permanent parameter is not added, it will take effect immediately and will become invalid after the service is restarted;
[root@hu ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
success
[root@hu ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
#Restart the service to make the open port take effect [root@hu ~]# firewall-cmd --reload
success
#4.1. Verify whether the newly opened port is effective. Yes means it is effective, and no means it is not invalid. [root@hu ~]# firewall-cmd --zone=public --query-port=8080/tcp
yes

5. Remove the specified port and restart the firewall service to take effect

 [root@hu ~]# firewall-cmd --zone=public --remove-port=8080/tcp --permanent

#Command to verify whether the removal is successful [root@hu ~]# firewall-cmd --zone=public --query-port=80/tcp
#Or check the ports currently open on the firewall [root@hu ~]# firewall-cmd --permanent --zone=public --list-ports
8081/tcp 3306/tcp 111/tcp 111/udp 2049/tcp 2049/udp 1001/tcp 1001/udp 1002/tcp 1002/udp 30001/tcp 30002/udp 80/tcp 8080/tcp
#Add multiple ports by configuring multiple --add-port parameters, for example:
[root@hu ~]# firewall-cmd --zone=public --add-port=80/tcp --add-port=8080/tcp --permanent

6. Restart the firewall

Method 1

 [root@hu ~]# systemctl restart firewalld.service

Method 2

 [root@hu ~]# firewall-cmd --reloadsuccess

7. Set the firewall to start automatically at boot

 [root@hu ~]# systemctl enable firewalld.service
#Restart the machine and check the firewall status[root@hu ~]# reboot
..
..
..
[root@hu ~]# firewall-cmd --state
Running --- indicates that the boot is successful

Summarize

This is the end of this article about CentOS7 firewall and port related commands. For more related CentOS7 firewall and port content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • A brief introduction to the simple use of CentOS7 firewall and open ports
  • Centos7 (Firewall) firewall opens common port commands
  • Centos7.1 firewall open port quick method
  • Detailed explanation of CentOS7 using firewalld to open and close firewalls and ports

<<:  Detailed explanation of the difference between JavaScript spread operator and rest operator

>>:  Dynamic starry sky background implemented with CSS3

Recommend

15 JavaScript functions worth collecting

Table of contents 1. Reverse the numbers 2. Get t...

How to configure nginx to limit the access frequency of the same IP

1. Add the following code to http{} in nginx.conf...

How to clean up the disk space occupied by Docker

Docker takes up a lot of space. Whenever we run c...

Share the responsive frameworks commonly used by web design masters (summary)

This article introduces and shares the responsive...

Html page supports dark mode implementation

Since 2019, both Android and IOS platforms have s...

Introduction to user management under Linux system

Table of contents 1. The significance of users an...

About scroll bar in HTML/removing scroll bar

1. The color of the scroll bar under xhtml In the ...

Some experience sharing on enabling HTTPS

As the domestic network environment continues to ...

Detailed explanation of the basic knowledge of front-end componentization

Table of contents Basic concepts of components Th...

Bootstrap 3.0 study notes grid system case

Preface In the previous article, we mainly learne...

How to implement Svelte's Defer Transition in Vue

I recently watched Rich Harris's <Rethinki...