能够ping通Centos 7.4,但telnet无法访问


先用ping ip是否能ping通
ping通以后看telnet服务是否能连接ip 
如果不能连接则查看虚拟机中的防火墙是否关闭

CentOS中防火墙程序主要是firewall和iptables,CentOS7中firewall服务已经默认安装好了,而iptables服务需要自己用yum  install  iptabes-services来安装

他们的不同https://blog.csdn.net/weixin_40658000/article/details/78708375

1.

能够ping通Centos 7.4,但telnet无法访问

2.

iptables通过控制端口来控制服务,而firewalld则是通过控制协议来控制端口 

 

 

查看端口命令为

1.service iptables status

2.firewall-cmd --list-port

3.netstat -ntlp

4.sudo netstat -apn|grep :端口号


关闭防火墙命令为service iptables stop
开启防火墙命令为 service iptables start
重启防火墙命令为 service iptables restart

 

查看防火墙状态firewall-cmd    --state

关闭防火墙systemctl  stop   firewalld.service

开启防火墙systemctl  start   firewalld.service

禁止开机启动启动防火墙systemctl   disable   firewalld.service

 

(重启虚拟机后生效,永久)
1.开启: chkconfig iptables on 
2.关闭: chkconfig iptables off

 

防火墙没有关闭,CentOS 7的防火墙默认是firewall而不是之前的iptables,所以需要确定 ,防火墙是否已经关闭,如果没有安装iptables的话,只需要通过systemctl stop firewalld.service 和systemctl disable firewalld.service关闭,前者是关闭firewall防火墙,后者是禁止开机启动, 然后通过firewall-cmd –state可以查看防火墙状态(关闭显示notrunning,开启显示running)。 可以使用systemctl stop iptables.service关闭iptables防火墙。这里我把firewall关闭了, 但是,还是不行!发现端口还是telnet不通,最后我突然想起来,我使用的是云主机,并不是普通的虚拟机,所以端口能不能访问除了上述 因素控制以外,还有在云平台上的安全组控制,果然一看,云主机绑定的安全组并没有打开这个端口,在将这个端口下行权限加入到安全组之后,果然成功

 

解决办法
1、增加一个持久访问端口:

​firewall-cmd --zone=public  --permanent --add-port=22122/tcp​

2、重启防火墙

​firewall-cmd --reload ​

3、需改配置文件

编辑/etc/sysconfig/iptables文件,编辑方法很多,可以使用vim编辑,也可以直接把该文件下载到本地,用本地工具编辑。

 

博主强烈推荐:https://blog.csdn.net/persistencegoing/article/details/84376427

希望大家关注我一波,防止以后迷路,有需要的可以加群讨论互相学习java ,学习路线探讨,经验分享与java求职  

群号:721 515 304