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

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

他们的不同

1.

centos 开启关闭 telent服务 centos7关闭telnet_java

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
重启防火墙firewall-cmd --reload
禁止开机启动启动防火墙systemctl   disable   firewalld.service
开放端口(开放后需要要重启防火墙才生效)
firewall-cmd --zone=public --add-port=3338/tcp --permanent
关闭端口(关闭后需要要重启防火墙才生效)
firewall-cmd --zone=public --remove-port=3338/tcp --permanent

 

(重启虚拟机后生效,永久)
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编辑,也可以直接把该文件下载到本地,用本地工具编辑。

4、CentOS7防火墙firewalld配置可访问端口

cd /etc/firewalld/zones

这个目录下有个public.xml文件,修改或添加:

<zone>
   <short>Public</short>
   <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
   <service name="ssh"/>
   <service name="dhcpv6-client"/>
   <service name="http"/>
   <port protocol="tcp" port="3306"/>
   <port protocol="tcp" port="8080"/>
   <port protocol="tcp" port="8088"/>
 </zone>

上面的端口号即是配置的可访问端口。

 

telnet 命令

CentOS中用 yum install telnet 来安装