笔者参考以下两文在OpenResty
下装置luarocks
呈现了DNS净化的问题,特此记录一下排查过程及解决办法。
- openresty下装置luarocks
- Lua 包管理工具 Luarocks 详解
在下载luarocks
呈现如下谬误:
<code class="shell">[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.gz Resolving luarocks.org... 45.33.61.132 Connecting to luarocks.org|45.33.61.132|:80... connected. HTTP request sent, awaiting response... 302 Moved Temporarily Location: 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.gz Resolving luarocks.github.io... ::1, 127.0.0.1 Connecting 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
<code class="shell">[root@centos6102 ~]# ping luarocks.github.io PING 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 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.039 ms 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.029 ms
再ping
一下github.io
<code class="shell">[root@centos6102 ~]# ping luarocks.github.io PING 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 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.039 ms 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.029 ms
能够看到两个地址都被解析成127.0.0.1
。这时候咱们须要查看一下零碎的hosts
文件是否被篡改。
本机hosts
文件
<code class="shell">[root@centos6102 ~]# cat /etc/hosts 127.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.io 185.199.110.153 github.io
再去ping luarocks.github.io
和ping github.io
都能够看到域名的解析是正确
<code class="shell">[root@centos6102 ~]# ping luarocks.github.io PING 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 ms 64 bytes from luarocks.github.io (185.199.111.153): icmp_seq=2 ttl=53 time=218 ms 64 bytes from luarocks.github.io (185.199.111.153): icmp_seq=3 ttl=53 time=205 ms 64 bytes from luarocks.github.io (185.199.111.153): icmp_seq=4 ttl=53 time=196 ms
<code class="shell">[root@centos6102 ~]# ping github.io PING 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 ms 64 bytes from github.io (185.199.110.153): icmp_seq=3 ttl=53 time=288 ms 64 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
。格局如下:
<code class="shell">dig [domainname] @[nameserver ip]
咱们来实测一下应用8.8.8.8
解析github.io
<code class="shell">[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.1
,8.8.8.8
不能解析github.io
。很惋惜,笔者没有找到能够正确解析github.io
的DNS,因而只能采纳解决办法1:批改hosts
文件。如果找到了能够正确解析的,按上面的办法更改DNS(假如8.8.8.8
可用,读者可自行替换成本人找到的DNS)。
办法一:动态ip永恒批改DNS
服务器如果是动态ip地址的,那么批改以下文件
<code class="shell">vi /etc/resolv.conf
批改为(或是其余可用DNS服务器)
<code class="shell">nameserver 8.8.8.8 nameserver 8.8.4.4
这样批改即可,service network reload
重启依然无效
办法二:DHCP永恒批改DNS
如果服务器是DHCP的,批改/etc/resolv.conf
后,service network reload
重启网络后发现,/etc/resolv.conf
又复原了原样。这时须要批改以下文件。
<code class="shell">vi /etc/sysconfig/network-scripts/ifcfg-eth0
批改(或是其余可用DNS服务器)
<code class="shell">DNS1=8.8.8.8 DNS2=8.8.4.4
重启之后/etc/resolv.conf
也会改为对应的DNS服务器。
参考资料:
- linux查看域名解析
- DNS净化
- 什么是DNS净化?DNS净化怎么解决?