Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to open the access port on the firewall of CentOS

2025-02-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to open the access port on the CentOS firewall". In the daily operation, I believe that many people have doubts about how to open the access port on the CentOS firewall. The editor consulted all kinds of materials and sorted out a simple and easy-to-use operation method. I hope it will be helpful to answer the doubt of "how to open the access port on the CentOS firewall". Next, please follow the editor to study!

On CentOS/RHEL 6 or earlier, iptables services allow users to interact with netfilter kernel modules to configure firewall rules in user space. However, starting with CentOS/RHEL 7, a new user space interface called firewalld was introduced to replace iptables services.

Use this command to view the current firewall rules:

The code is as follows:

$sudo iptables-L

Now, let's see how to modify the firewall on CentOS/RHEL to open a port.

Open the port on CentOS/RHEL 7

When CentOS/RHEL 7 is started, firewall rule settings are managed by default by the firewalld service process. A command-line client called firewall-cmd supports communicating with this daemon to permanently modify firewall rules.

Use these commands to permanently open a new port (such as TCP/80).

The code is as follows:

$sudo firewall-cmd-zone=public-add-port=80/tcp-permanent

$sudo firewall-cmd-reload

If you do not use the "--permanent" flag, the firewall rules will expire after restart.

Open the port on CentOS/RHEL 6

On CentOS/RHEL 6 or earlier systems, the iptables service is responsible for maintaining firewall rules.

Using the first command of iptables, you can open a new TCP/UDP port through the firewall. In order to permanently save the modified rule, a second command is needed.

The code is as follows:

$sudo iptables-I INPUT-p tcp-m tcp-- dport 80-j ACCEPT

$sudo service iptables save

Another way is through a firewall client called the command line user interface (TUI) called system-config-firewall-tui.

The code is as follows:

$sudo system-config-firewall-tui

Select the "Customize" button in the middle and press the ENTER key.

If you want to modify the firewall for any known service, such as a web server, simply check the service and close the tool. If you want to open any TCP/UDP port, select the "Forward" button and go to the next interface.

Select the Add button to add a new rule.

Specify a port (such as 80) or a port range (such as 3000-3030) and a protocol (such as tcp or udp).

Finally, save the modified configuration and close the tool. In this way, the firewall is saved forever.

At this point, the study on "how to open a traffic port on the firewall of CentOS" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report