First: The firewall used by CentOS 7 is: Firewall not iptables
To view the ports that are already open: Here I've opened the MySQL port
[Email protected] ~]# Firewall-cmd--list-ports
3306/tcp
Open port: Prompt success indicates success
[Email protected] ~]# firewall-cmd--zone=public--add-port=3306/tcp--permanent
Success
Meaning of the command:
--zone # indicates scope
--add-port=3306/tcp #添加端口 in the format: port number/Communication protocol
--permanent #永久生效, fail after reboot without this parameter
Need to restart the firewall:
Firewall-cmd--reload #重启firewall
Systemctl Stop Firewalld.service #停止firewall
Systemctl Disable Firewalld.service #禁止firewall开机启动
viewing ports for listening (Listen)
Netstat-lntp
Check which process the port is using
Netstat-lnp|grep 8080
After restarting the firewall, you need to set up a remote access account in MySQL
[Email protected] ~]# mysql-uroot-p
Enter Password:
Welcome to the MariaDB Monitor. Commands End With; or \g.
Your MariaDB Connection ID is 4
Server VERSION:5.5.60-MARIADB MariaDB Server
Copyright (c), 2018, Oracle, MariaDB Corporation Ab and others.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
MariaDB [(None)]> create user ' username ' @ '% ' identified by ' password ';
Query OK, 0 rows Affected (0.00 sec)
MariaDB [(None)]> grant all on * * ' username ' @ '% ';
Error 1064 (42000): You have a error in your SQL syntax; Check the manual, corresponds to your MariaDB server version for the right syntax "@ '" @ '% ' @ Line 1
MariaDB [(None)]> grant all on * * to ' zhengwei ' @ '% ';
Query OK, 0 rows Affected (0.00 sec)
MariaDB [(None)]> flush privileges;
Query OK, 0 rows Affected (0.00 sec)
Then test the connection successfully locally!
CentOS 7 following version iptables command
To open the 80,22,8080 port, enter the following command
-I INPUT -p tcp --dport 80 -j ACCEPT2、/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT3、/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
Then Save:
/etc/rc.d/init.d/iptables save
To view open ports:
/etc/init.d/iptables status
Shutting down the firewall
1) Permanent, no recovery after reboot
Open: Chkconfig iptables on
OFF: Chkconfig iptables off
2) immediate effect, recovery after restart
Open: Service iptables start
Close: Service iptables stop
Navicat installing MySQL in a remote access VM