有没有 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 或把他移到后面,则完全连不上外网(内网是可以)!
1
ysc3839 262 天前 via Android
出问题时试试用 dig 直接请求 192.168.2.1 看看吧
|
4
perfectlife 262 天前
写个脚本循环 dig 并打印时间 ,然后 dns 出问题了 去查看
|
5
littleylv 262 天前
|
6
littleylv 261 天前
@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 |