V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
YaoYaooo
V2EX  ›  问与答

CentOS Stream 9 经常无法解析域名

  •  
  •   YaoYaooo · 51 天前 · 633 次点击
    这是一个创建于 51 天前的主题,其中的信息可能已经有所发展或是发生改变。

    有没有 linux 服务器大佬帮忙看看问题:

    我有一台电脑装的 CentOS Stream 9 服务器无 GUI 版,网线直连的路由器,设置了固定 ip 。

    网络好的,可以内网连接,也可以访问外网。搭了 PHP 和 Apache 运行着。

    但问题是,时不时的就网络错误,表现为:

    [PDOException] SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

    cURL Error (6) Could not resolve host: xx.xx.com (此处我改了域名 xx )

    他也不是一直不行,就是偶尔,大概 10 分钟左右就会出现一次错误

    # cat /etc/NetworkManager/system-connections/enp4s0.nmconnection
    [connection]
    id=enp4s0
    uuid=(UUID here)
    type=ethernet
    interface-name=enp4s0
    timestamp=1712230701
    
    [ethernet]
    
    [ipv4]
    address1=192.168.2.120/24,192.168.2.1
    dns=192.168.2.1;114.114.114.114;8.8.8.8;
    method=manual
    
    [ipv6]
    addr-gen-mode=eui64
    method=auto
    
    [proxy]
    
    # cat /etc/resolv.conf
    # Generated by NetworkManager
    nameserver 192.168.2.1
    nameserver 114.114.114.114
    nameserver 8.8.8.8
    
    # cat /etc/nsswitch.conf | grep 'hosts'
    #     hosts: files dns
    #     hosts: files dns  # from user file
    # Valid databases are: aliases, ethers, group, gshadow, hosts,
    hosts:      files dns myhostname
    
    # ip a
    1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host
           valid_lft forever preferred_lft forever
    2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
        link/ether 58:11:22:bd:ae:31 brd ff:ff:ff:ff:ff:ff
        inet 192.168.2.120/24 brd 192.168.2.255 scope global noprefixroute enp4s0
           valid_lft forever preferred_lft forever
        inet6 fe80::5a11:22ff:febd:ae31/64 scope link noprefixroute
           valid_lft forever preferred_lft forever
    3: wlo1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
        link/ether f4:26:79:f6:9d:43 brd ff:ff:ff:ff:ff:ff
        altname wlp0s20f3
    

    另外一个情况是:dns=192.168.2.1;114.114.114.114;8.8.8.8; 这里如果我不填 192.168.2.1 或把他移到后面,则完全连不上外网(内网是可以)!

    6 条回复    2024-04-08 11:37:06 +08:00
    ysc3839
        1
    ysc3839  
       51 天前 via Android
    出问题时试试用 dig 直接请求 192.168.2.1 看看吧
    littleylv
        2
    littleylv  
       51 天前
    @ysc3839
    你好,我是问问题的本人。你说的这个方法好像不大好实现,因为出问题的时候是“偶然”的,很难把握那个瞬间马上去 dig
    ysc3839
        3
    ysc3839  
       51 天前 via Android
    @littleylv 那建议加重试机制,这个感觉是 192.168.2.1 服务偶然超时导致的
    perfectlife
        4
    perfectlife  
       51 天前
    写个脚本循环 dig 并打印时间 ,然后 dns 出问题了 去查看
    littleylv
        5
    littleylv  
       51 天前
    @perfectlife
    ```
    #!/bin/bash
    while true
    do
    sleep 1
    date
    dig 192.168.2.1
    done
    ```
    有道理,准备跑看看
    littleylv
        6
    littleylv  
       50 天前
    @ysc3839
    @perfectlife
    老哥们,我执行
    dig 192.168.2.1
    dig www.baidu.com
    的结果,麻烦帮忙看看

    N 次的正常返回结果如下:
    ; <<>> DiG 9.16.23-RH <<>> 192.168.2.1
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 12297
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 1232
    ;; QUESTION SECTION:
    ;192.168.2.1. IN A

    ;; AUTHORITY SECTION:
    . 199 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2024040701 1800 900 604800 86400

    ;; Query time: 13 msec
    ;; SERVER: 192.168.2.1#53(192.168.2.1)
    ;; WHEN: Mon Apr 08 11:31:04 CST 2024
    ;; MSG SIZE rcvd: 115


    ; <<>> DiG 9.16.23-RH <<>> www.baidu.com
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 33348
    ;; flags: qr aa ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
    ;; WARNING: Message has 23 extra bytes at end

    ;; QUESTION SECTION:
    ;www.baidu.com. IN A

    ;; ANSWER SECTION:
    www.baidu.com. 202 IN A 180.101.50.242
    www.baidu.com. 202 IN A 180.101.50.188

    ;; Query time: 2 msec
    ;; SERVER: 192.168.2.1#53(192.168.2.1)
    ;; WHEN: Mon Apr 08 11:31:04 CST 2024
    ;; MSG SIZE rcvd: 86

    其中某一次出问题的结果:
    ; <<>> DiG 9.16.23-RH <<>> 192.168.2.1
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 16660
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 1232
    ;; QUESTION SECTION:
    ;192.168.2.1. IN A

    ;; AUTHORITY SECTION:
    . 198 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2024040701 1800 900 604800 86400

    ;; Query time: 20 msec
    ;; SERVER: 192.168.2.1#53(192.168.2.1)
    ;; WHEN: Mon Apr 08 11:31:05 CST 2024
    ;; MSG SIZE rcvd: 115

    ;; Warning: Message parser reports malformed message packet.
    ;; ;; Question section mismatch: got www.b\000idu.com/A/IN
    ;; ;; Question section mismatch: got www.b\000idu.com/A/IN
    ;; reply from unexpected source: 192.168.2.1#37994, expected 223.5.5.5#53

    ;; reply from unexpected source: 192.168.2.1#19320, expected 223.6.6.6#53

    ;; Warning: Message parser reports malformed message packet.
    ;; ;; Question section mismatch: got www.b\000idu.com/A/IN
    ;; ;; Question section mismatch: got www.b\000idu.com/A/IN
    ;; reply from unexpected source: 192.168.2.1#37994, expected 223.5.5.5#53

    ;; reply from unexpected source: 192.168.2.1#19320, expected 223.6.6.6#53

    ;; Warning: Message parser reports malformed message packet.
    ;; ;; Question section mismatch: got www.b\000idu.com/A/IN
    ;; ;; Question section mismatch: got www.b\000idu.com/A/IN
    ;; reply from unexpected source: 192.168.2.1#37994, expected 223.5.5.5#53

    ;; reply from unexpected source: 192.168.2.1#19320, expected 223.6.6.6#53


    ; <<>> DiG 9.16.23-RH <<>> www.baidu.com
    ;; global options: +cmd
    ;; connection timed out; no servers could be reached
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5746 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 02:08 · PVG 10:08 · LAX 19:08 · JFK 22:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.