Linux服务器无法解析域名解决

最近把项目部署到Linux服务器上,发现本地调试好的微信扫码登录突然无法使用了,本地调试却正常!

查看项目日志,发现报错如下

java.net.UnknownHostException: api.weixin.qq.com
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
	at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
	at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
	at sun.net.www.protocol.https.HttpsClient.(HttpsClient.java:264)
	at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
	at cn.jagl.mryt.util.HttpRequestUtilImpl.sendGet(HttpRequestUtilImpl.java:87)
	at cn.jagl.mryt.action.EmployeeAction.wxLogin(EmployeeAction.java:193)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:892)
	at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1537)...还有很多就不截了


这个错误是因为服务器无法识别api.weixin.qq.com这个域名

然后尝试分别在windows和服务器上ping 了一下这个域名,果然windows上可以ping通,而linux上不行,又试了几个常用的域名,结果一样。。。

解决方法

编辑etc下的resoly.conf文件(如果没有就新建一个)
vi /etc/resolv.conf
添加一行
nameserver 8.8.8.8
保存后重启网络服务
service network restart
然后应该就可以了



你可能感兴趣的:(linux,域名,服务器,linux)