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

How to implement a multi-terminal bridging platform based on websocket in JS

Table of contents 1. What to debug 2. Features of...

Detailed description of ffmpeg Chinese parameters

FFMPEG 3.4.1 version parameter details Usage: ffm...

JavaScript implements checkbox selection function

This article example shares the specific code of ...

Detailed explanation of how to configure Nginx web server sample code

Overview Today we will mainly share how to config...

Detailed explanation of MySQL 8.0.18 commands

Open the folder C:\web\mysql-8.0.11 that you just...

Example of using JSX to build component Parser development

Table of contents JSX environment construction Se...

Detailed steps for debugging VUE projects in IDEA

To debug js code, you need to write debugger in t...

Linux platform mysql enable remote login

During the development process, I often encounter...

Summary of the differences between global objects in nodejs and browsers

In Node.js, a .js file is a complete scope (modul...

In-depth explanation of the style feature in Vue3 single-file components

Table of contents style scoped style module State...

Using CSS3 to create header animation effects

Netease Kanyouxi official website (http://kanyoux...

Develop a vue component that encapsulates iframe

Table of contents 1. Component Introduction 2. Co...

JavaScript gets the scroll bar position and slides the page to the anchor point

Preface This article records a problem I encounte...

Vue Element front-end application development: Use of API Store View in Vuex

Table of contents Overview 1. Separation of front...

Double loading issue when the page contains img src

<br />When the page contains <img src=&qu...