Enable the linux system firewall and allow other ports.

Published: 2019-12-26

Our elastic cloud hosts do not restrict ports externally by default. If the port is inaccessible externally after the service is running, you can refer to this tutorial to allow the corresponding port in the firewall.

1. Allowing Ports in the WDCP System:

(1) Version 3.2

After logging in to the wdcp panel, click "Security Management" — "Firewall Settings" — "Quick Add". Fill in the port as shown in the figure (the protocol defaults to tcp), and save to allow it.

(2) Version 2.5

After logging in to wdcp, click "Security Management" — "Firewall (iptables)" — Add Rule

As shown in the figure, generally just fill in the port that needs to be allowed, and click OK.



2. Allowing Ports in 宝塔面板:

After logging in to the panel, click "Security". In the firewall, select "Allow Port", fill in the port number after it; the remark can be left blank. Click Allow. The figure below shows allowing port 3306 for the mysql database.



3. Allowing Ports in the Clean Version System:

(1) Allow using a script (supports pre-installed panels or clean versions of centos6, 7 systems and ubuntu systems)

a. Log in to the server using ssh

b. Paste the following script and press Enter to run it

wget -O portctl.sh http://downinfo.myhostadmin.net/vps/portctl.sh && bash portctl.sh && rm -rf portctl.sh

Enter the port that needs to be allowed and press Enter, then enter the protocol. If it is the tcp protocol, just press Enter to complete the allowlisting. If it is a port range, you can enter the range ports separated by a colon in English. Deleting ports that have already been allowed is supported.

(2) Command-line operation (requires logging into the server via ssh):

centos6:

iptables -I INPUT -p protocol -m protocol --dport port -j ACCEPT
iptables-save > /etc/sysconfig/iptables
service iptables restart

centos7 (only one of firewalld and iptables can be used):

a. iptables

iptables -I INPUT -p protocol -m protocol --dport port -j ACCEPT
iptables-save > /etc/sysconfig/iptables
systemctl restart iptables

b. firewall

firewall-cmd --permanent --zone=public --add-port=port/protocol
firewall-cmd --reload

ubuntu:

For this system, our company does not enable the firewall by default. If needed, you can use the script above to allow ports or enable the system ufw firewall to perform the operation.

ufw enable   (start the firewall)
ufw allow port/protocol
ufw reload

If the port is still inaccessible after following this tutorial, please check whether the relevant application or service inside the server is listening. You can use netstat -nptl to check. If you cannot resolve it on your own, you can submit a ticket, and our technical staff will assist with handling it.