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

Writing Snake Game with Native JS

This article shares the specific code of writing ...

React implements paging effect

This article shares the specific code for React t...

Introduction to the use of MySQL source command

Table of contents Thoughts triggered by an online...

How to use nginx to block a specified interface (URL)

1. Introduction Sometimes, after the web platform...

Use of Linux relative and absolute paths

01. Overview Absolute paths and relative paths ar...

Tips to prevent others from saving as my web page and copying my site

Nowadays, copying websites is very common on the I...

Detailed explanation of vuex persistence in practical application of vue

Table of contents vuex persistence Summarize vuex...

9 Practical Tips for Creating Web Content Pages

Content 1. Give readers a reason to stay. Make the...

Steps to run ASP.NET Core in Docker container

There are too much knowledge to learn recently, a...

Tutorial on installing Odoo14 from source code on Ubuntu 18.04

Table of contents Background of this series Overv...

Native js to implement drop-down menu

Drop-down menus are also very common in real life...

Design theory: people-oriented design concept

<br />When thoughts were divided into East a...

Install and configure MySQL 5.7 under CentOS 7

This article tests the environment: CentOS 7 64-b...