• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

OpenResty安装Luarocks出现的DNS污染解决

linux 搞代码 3年前 (2022-03-04) 18次浏览 已收录 0个评论
文章目录[隐藏]

笔者参考以下两文在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.ioping 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.18.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净化怎么解决?

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:OpenResty安装Luarocks出现的DNS污染解决

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址