今天在CentOS7虛擬機上安裝了mysql,想要在宿主機上遠程連接,結果一直報錯,就百度了原因,這裏分享一篇博客以及自己的一點知識。
引用:
問題描述:
以上是博主分享的各種問題,我經過了上邊所有排查,結果依然連接不上。突然靈機一動就想到了系統防火牆,這麼重要的細節自己竟然忘掉了,centOS上的防火牆還開着呢,怎麼能遠程連接。然後關閉防火牆就實現了完美連接。
這裏附上centos有關防火牆的操作:
CentOS6.5查看防火牆的狀態:
1 | [linuxidc@localhost ~]$service iptable status |
顯示結果:
1 2 3 4 5 | [linuxidc@localhost ~]$service iptable status Redirecting to /bin/systemctl status iptable.service ● iptable.service Loaded: not -found (Reason: No such file or directory) Active: inactive (dead) --表示防火牆已經關閉 |
CentOS 6.5關閉防火牆
1 2 | [root@localhost ~]#servcie iptables stop --臨時關閉防火牆 [root@localhost ~]#chkconfig iptables off --永久關閉防火牆 |
CentOS 7.2關閉防火牆
CentOS 7.0默認使用的是firewall作爲防火牆,這裏改爲iptables防火牆步驟。
firewall-cmd --state #查看默認防火牆狀態(關閉後顯示notrunning,開啓後顯示running)
1 2 | [root@localhost ~]#firewall-cmd --state not running |
檢查防火牆的狀態:
從centos7開始使用systemctl來管理服務和程序,包括了service和chkconfig。
1 2 | [root@localhost ~]#systemctl list-unit-files|grep firewalld.service --防火牆處於關閉狀態 firewalld.service disabled |
或者
1 2 3 4 | [root@localhost ~]#systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) |
關閉防火牆:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啓動
1 2 | [root@localhost ~]#systemctl stop firewalld.service [root@localhost ~]#systemctl disable firewalld.service |
1 2 3 4 5 6 7 8 | 啓動一個服務:systemctl start firewalld.service 關閉一個服務:systemctl stop firewalld.service 重啓一個服務:systemctl restart firewalld.service 顯示一個服務的狀態:systemctl status firewalld.service 在開機時啓用一個服務:systemctl enable firewalld.service 在開機時禁用一個服務:systemctl disable firewalld.service 查看服務是否開機啓動:systemctl is -enabled firewalld.service;echo $? 查看已啓動的服務列表:systemctl list-unit-files|grep enabled |
CentOS6.5查看防火牆的狀態:
1 | [linuxidc@localhost ~]$service iptable status |
顯示結果:
1 2 3 4 5 | [linuxidc@localhost ~]$service iptable status Redirecting to /bin/systemctl status iptable.service ● iptable.service Loaded: not -found (Reason: No such file or directory) Active: inactive (dead) --表示防火牆已經關閉 |
CentOS 6.5關閉防火牆
1 2 | [root@localhost ~]#servcie iptables stop --臨時關閉防火牆 [root@localhost ~]#chkconfig iptables off --永久關閉防火牆 |
CentOS 7.2關閉防火牆
CentOS 7.0默認使用的是firewall作爲防火牆,這裏改爲iptables防火牆步驟。
firewall-cmd --state #查看默認防火牆狀態(關閉後顯示notrunning,開啓後顯示running)
1 2 | [root@localhost ~]#firewall-cmd --state not running |
檢查防火牆的狀態:
從centos7開始使用systemctl來管理服務和程序,包括了service和chkconfig。
1 2 | [root@localhost ~]#systemctl list-unit-files|grep firewalld.service --防火牆處於關閉狀態 firewalld.service disabled |
或者
1 2 3 4 | [root@localhost ~]#systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) |
關閉防火牆:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啓動
1 2 | [root@localhost ~]#systemctl stop firewalld.service [root@localhost ~]#systemctl disable firewalld.service |
1 2 3 4 5 6 7 8 | 啓動一個服務:systemctl start firewalld.service 關閉一個服務:systemctl stop firewalld.service 重啓一個服務:systemctl restart firewalld.service 顯示一個服務的狀態:systemctl status firewalld.service 在開機時啓用一個服務:systemctl enable firewalld.service 在開機時禁用一個服務:systemctl disable firewalld.service 查看服務是否開機啓動:systemctl is -enabled firewalld.service;echo $? 查看已啓動的服務列表:systemctl list-unit-files|grep enabled |
CentOS6.5查看防火牆的狀態:
1 | [linuxidc@localhost ~]$service iptable status |
顯示結果:
1 2 3 4 5 | [linuxidc@localhost ~]$service iptable status Redirecting to /bin/systemctl status iptable.service ● iptable.service Loaded: not -found (Reason: No such file or directory) Active: inactive (dead) --表示防火牆已經關閉 |
CentOS 6.5關閉防火牆
1 2 | [root@localhost ~]#servcie iptables stop --臨時關閉防火牆 [root@localhost ~]#chkconfig iptables off --永久關閉防火牆 |
CentOS 7.2關閉防火牆
CentOS 7.0默認使用的是firewall作爲防火牆,這裏改爲iptables防火牆步驟。
firewall-cmd --state #查看默認防火牆狀態(關閉後顯示notrunning,開啓後顯示running)
1 2 | [root@localhost ~]#firewall-cmd --state not running |
檢查防火牆的狀態:
從centos7開始使用systemctl來管理服務和程序,包括了service和chkconfig。
1 2 | [root@localhost ~]#systemctl list-unit-files|grep firewalld.service --防火牆處於關閉狀態 firewalld.service disabled |
或者
1 2 3 4 | [root@localhost ~]#systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) |
關閉防火牆:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啓動
1 2 | [root@localhost ~]#systemctl stop firewalld.service [root@localhost ~]#systemctl disable firewalld.service |
1 2 3 4 5 6 7 8 | 啓動一個服務:systemctl start firewalld.service 關閉一個服務:systemctl stop firewalld.service 重啓一個服務:systemctl restart firewalld.service 顯示一個服務的狀態:systemctl status firewalld.service 在開機時啓用一個服務:systemctl enable firewalld.service 在開機時禁用一個服務:systemctl disable firewalld.service 查看服務是否開機啓動:systemctl is -enabled firewalld.service;echo $? 查看已啓動的服務列表:systemctl list-unit-files|grep enabled |