笔者参考以下两文在OpenResty下装置luarocks呈现了DNS净化的问题,特此记录一下排查过程及解决办法。

  • openresty下装置luarocks
  • Lua 包管理工具 Luarocks 详解

在下载luarocks呈现如下谬误:

[root@centos6102 ~]# wget http://luarocks.org/releases/luarocks-2.4.2.tar.gz--2021-01-26 11:09:31--  http://luarocks.org/releases/luarocks-2.4.2.tar.gzResolving luarocks.org... 45.33.61.132Connecting to luarocks.org|45.33.61.132|:80... connected.HTTP request sent, awaiting response... 302 Moved TemporarilyLocation: https://luarocks.github.io/luarocks/releases/luarocks-2.4.2.tar.gz [following]--2021-01-26 11:09:31--  https://luarocks.github.io/luarocks/releases/luarocks-2.4.2.tar.gzResolving luarocks.github.io... ::1, 127.0.0.1Connecting to luarocks.github.io|::1|:443... failed: Connection refused.Connecting to luarocks.github.io|127.0.0.1|:443... failed: Connection refused.

从谬误提醒中能够看到申请http://luarocks.org/releases/luarocks-2.4.2.tar.gz,被302重定向到https://luarocks.github.io/luarocks/releases/luarocks-2.4.2.tar.gz,继尔呈现了failed: Connection refused

应用ping进行排查

为了排查谬误,咱们从远到近,先ping一下luarocks.github.io

[root@centos6102 ~]# ping luarocks.github.ioPING luarocks.github.io (127.0.0.1) 56(84) bytes of data.64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.032 ms64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.039 ms64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.029 ms

ping一下github.io

[root@centos6102 ~]# ping luarocks.github.ioPING luarocks.github.io (127.0.0.1) 56(84) bytes of data.64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.032 ms64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.039 ms64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.029 ms

能够看到两个地址都被解析成127.0.0.1。这时候咱们须要查看一下零碎的hosts文件是否被篡改。

本机hosts文件

[root@centos6102 ~]# cat /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

能够看到本机的hosts文件是失常的,咱们能够思考是近程的DNS解析受到到净化。(DNS净化)。

解决办法1:批改hosts文件

/etc/hosts文件中减少对github.io的解析(github.io的ip能够去站长中国查问)

185.199.111.153     luarocks.github.io185.199.110.153     github.io

再去ping luarocks.github.ioping github.io都能够看到域名的解析是正确

[root@centos6102 ~]# ping luarocks.github.ioPING luarocks.github.io (185.199.111.153) 56(84) bytes of data.64 bytes from luarocks.github.io (185.199.111.153): icmp_seq=1 ttl=53 time=206 ms64 bytes from luarocks.github.io (185.199.111.153): icmp_seq=2 ttl=53 time=218 ms64 bytes from luarocks.github.io (185.199.111.153): icmp_seq=3 ttl=53 time=205 ms64 bytes from luarocks.github.io (185.199.111.153): icmp_seq=4 ttl=53 time=196 ms
[root@centos6102 ~]# ping github.ioPING github.io (185.199.110.153) 56(84) bytes of data.64 bytes from github.io (185.199.110.153): icmp_seq=2 ttl=53 time=236 ms64 bytes from github.io (185.199.110.153): icmp_seq=3 ttl=53 time=288 ms64 bytes from github.io (185.199.110.153): icmp_seq=4 ttl=53 time=236 ms

此时再运行wget http://luarocks.org/releases/luarocks-2.4.2.tar.gz就能够失常下载了。

解决办法2:更换DNS服务器

应用dig测试可用的DNS服务器

网上提供的DNS服务器很多,例如罕用的144.144.144.144以及8.8.8.8。咱们能够应用dig命令去测试这些服务器是否能够正确解析github.io。格局如下:

dig [domainname] @[nameserver ip]

咱们来实测一下应用8.8.8.8解析github.io

[root@centos6102 lua]# dig github.io @8.8.8.8; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.68.rc1.el6_10.8 <<>> github.io @8.8.8.8;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57042;; flags: qr; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0;; QUESTION SECTION:;github.io.            IN    A;; ANSWER SECTION:github.io.        868    IN    A    127.0.0.1;; Query time: 163 msec;; SERVER: 8.8.8.8#53(8.8.8.8);; WHEN: Tue Jan 26 12:15:12 2021;; MSG SIZE  rcvd: 43

能够看到github.io. 868 IN A 127.0.0.18.8.8.8不能解析github.io。很惋惜,笔者没有找到能够正确解析github.io的DNS,因而只能采纳解决办法1:批改hosts文件。如果找到了能够正确解析的,按上面的办法更改DNS(假如8.8.8.8可用,读者可自行替换成本人找到的DNS)。

办法一:动态ip永恒批改DNS

服务器如果是动态ip地址的,那么批改以下文件

vi /etc/resolv.conf

批改为(或是其余可用DNS服务器)

nameserver 8.8.8.8nameserver 8.8.4.4

这样批改即可,service network reload重启依然无效

办法二:DHCP永恒批改DNS

如果服务器是DHCP的,批改/etc/resolv.conf后,service network reload重启网络后发现,/etc/resolv.conf又复原了原样。这时须要批改以下文件。

vi /etc/sysconfig/network-scripts/ifcfg-eth0

批改(或是其余可用DNS服务器)

DNS1=8.8.8.8DNS2=8.8.4.4

重启之后/etc/resolv.conf也会改为对应的DNS服务器。

参考资料:

  • linux查看域名解析
  • DNS净化
  • 什么是DNS净化?DNS净化怎么解决?