从我看过的其他帖子来看,这似乎是 Ubuntu 的一个常见问题,但我一直找不到解决我的问题的方法。我正在办公室(我在当地一所大学工作)运行一个全新的 Ubuntu 18 安装,它经常断开连接。该机器通过墙上的 CAT6 插入以太网端口,该端口连接到本地网络交换机机架。该机器还有一个 wifi 卡,目前连接到大学的 wifi 网络。我们的网络管理员注意到他们那边没有发现任何奇怪的东西。我没有安装任何特定的以太网驱动程序,网络接口开箱即用。这是一台戴尔 Inspiron 3880 台式机。
该建筑已有 3-7 年历史,因此可能是布线问题,但我怀疑不是。不幸的是,我对 Ubunbtu(和网络调试)还很陌生,但我真的不知道下一步该尝试什么。我可以访问同一房间内联网的 Windows 机器,它确实会断开固定电话连接,但只是每隔几天,这让我怀疑是我遗漏了 Ubuntu 设置。我不太确定什么是匿名信息,所以如果我忽略了任何对调试至关重要的信息,请告诉我。
似乎每 5-20 分钟就会断开一次,然后几分钟后又会恢复。有趣的是,我的以太网和 wifi 似乎经常同时断开连接。这些超时导致我的 SSH 断开连接。
jfslin@pc001:~$ journalctl -u NetworkManager | grep 'timed out'
Dec 15 08:03:49 pc001 NetworkManager[966]: <info> [1608037429.4490] connectivity: (enp1s0) timed out
Dec 15 08:23:49 pc001 NetworkManager[966]: <info> [1608038629.4494] connectivity: (wlp2s0) timed out
Dec 15 08:38:49 pc001 NetworkManager[966]: <info> [1608039529.4497] connectivity: (enp1s0) timed out
Dec 15 08:53:49 pc001 NetworkManager[966]: <info> [1608040429.4493] connectivity: (wlp2s0) timed out
Dec 15 08:53:49 pc001 NetworkManager[966]: <info> [1608040429.4497] connectivity: (enp1s0) timed out
Dec 15 09:03:49 pc001 NetworkManager[966]: <info> [1608041029.4498] connectivity: (enp1s0) timed out
Dec 15 09:08:49 pc001 NetworkManager[966]: <info> [1608041329.4490] connectivity: (wlp2s0) timed out
Dec 15 09:08:49 pc001 NetworkManager[966]: <info> [1608041329.4497] connectivity: (enp1s0) timed out
Dec 15 09:13:49 pc001 NetworkManager[966]: <info> [1608041629.4496] connectivity: (enp1s0) timed out
Dec 15 09:23:49 pc001 NetworkManager[966]: <info> [1608042229.4491] connectivity: (wlp2s0) timed out
Dec 15 09:23:49 pc001 NetworkManager[966]: <info> [1608042229.4497] connectivity: (enp1s0) timed out
Dec 15 09:28:49 pc001 NetworkManager[966]: <info> [1608042529.4493] connectivity: (enp1s0) timed out
Dec 15 09:33:49 pc001 NetworkManager[966]: <info> [1608042829.4490] connectivity: (wlp2s0) timed out
Dec 15 09:33:49 pc001 NetworkManager[966]: <info> [1608042829.4499] connectivity: (enp1s0) timed out
Dec 15 09:38:49 pc001 NetworkManager[966]: <info> [1608043129.4493] connectivity: (wlp2s0) timed out
Dec 15 09:38:49 pc001 NetworkManager[966]: <info> [1608043129.4493] connectivity: (enp1s0) timed out
Dec 15 09:48:49 pc001 NetworkManager[966]: <info> [1608043729.4497] connectivity: (wlp2s0) timed out
Dec 15 09:53:49 pc001 NetworkManager[966]: <info> [1608044029.4490] connectivity: (wlp2s0) timed out
Dec 15 09:53:49 pc001 NetworkManager[966]: <info> [1608044029.4491] connectivity: (enp1s0) timed out
Dec 15 10:03:49 pc001 NetworkManager[966]: <info> [1608044629.4494] connectivity: (enp1s0) timed out
Dec 15 10:08:49 pc001 NetworkManager[966]: <info> [1608044929.4492] connectivity: (wlp2s0) timed out
Dec 15 10:08:49 pc001 NetworkManager[966]: <info> [1608044929.4504] connectivity: (enp1s0) timed out
Dec 15 10:23:49 pc001 NetworkManager[966]: <info> [1608045829.4489] connectivity: (enp1s0) timed out
Dec 15 10:28:49 pc001 NetworkManager[966]: <info> [1608046129.4491] connectivity: (enp1s0) timed out
Dec 15 10:33:49 pc001 NetworkManager[966]: <info> [1608046429.4490] connectivity: (wlp2s0) timed out
我们的网络管理员为我分配了一个静态 IP,DHCP 可以正确获取该 IP。我尝试从 DHCP 切换到静态 IP,但问题仍然存在。目前,它已恢复为 DHCP,正如我的管理员所建议的那样。
jfslin@pc001:~$ ifconfig
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet [wired ip] netmask 255.255.255.0 broadcast [wired gateway ip]
ether [wired mac] txqueuelen 1000 (Ethernet)
RX packets 837084 bytes 174008495 (174.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 83911 bytes 37182161 (37.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
loop txqueuelen 1000 (Local Loopback)
RX packets 2964483 bytes 15855066293 (15.8 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2964483 bytes 15855066293 (15.8 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
wlp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet [wifi ip] netmask 255.255.128.0 broadcast [wifi gateway ip]
ether [wifi mac] txqueuelen 1000 (Ethernet)
RX packets 11453 bytes 3674081 (3.6 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 13309 bytes 2171764 (2.1 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
jfslin@pc001:~$ ip -c 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
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether [wired mac] brd ff:ff:ff:ff:ff:ff
inet [wired ip]/24 brd [wired gateway ip] scope global dynamic noprefixroute enp1s0
valid_lft 134294sec preferred_lft 134294sec
3: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether [wifi mac] brd ff:ff:ff:ff:ff:ff
inet [wifi ip]/17 brd [wifi gateway ip] scope global dynamic noprefixroute wlp2s0
valid_lft 19484sec preferred_lft 19484sec
我读到的一个常见主题是 IPv6 可能是问题所在,因此我通过 GRUB 禁用了它,因为我注意到从 GUI 的网络有线设置中关闭它没有任何作用。这台机器上只有 Ubuntu。我还从 dhclient.config 中提取了 dhcp6 所有内容
jfslin@pc001:~$ more /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash ipv6.disable=1"
GRUB_CMDLINE_LINUX="ipv6.disable=1"
jfslin@pc001:~$ more /etc/dhcp/dhclient.conf
option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;
send host-name = gethostname();
request subnet-mask, broadcast-address, time-offset, routers,
domain-name, domain-name-servers, domain-search, host-name,
netbios-name-servers, netbios-scope, interface-mtu,
rfc3442-classless-static-routes, ntp-servers;
timeout 300;
一些其他常见的设置:
jfslin@pc001:~$ sudo lshw -C network
*-network
description: Ethernet interface
product: RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller
vendor: Realtek Semiconductor Co., Ltd.
physical id: 0
bus info: pci@0000:01:00.0
logical name: enp1s0
version: 15
serial: [wired mac]
size: 1Gbit/s
capacity: 1Gbit/s
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress msix bus_master cap_list ethernet physical tp mii 10bt 10bt-fd 100bt 100bt-fd 1000bt-fd autonegotiation
configuration: autonegotiation=on broadcast=yes driver=r8169 duplex=full firmware=rtl8168h-2_0.0.2 02/26/15 ip=[wired ip] latency=0 link=yes multicast=yes port=MII speed=1Gbit/s
resources: irq:16 ioport:3000(size=256) memory:d1104000-d1104fff memory:d1100000-d1103fff
*-network
description: Wireless interface
product: Wireless 3165
vendor: Intel Corporation
physical id: 0
bus info: pci@0000:02:00.0
logical name: wlp2s0
version: 79
serial: [wifi mac]
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress bus_master cap_list ethernet physical wireless
configuration: broadcast=yes driver=iwlwifi driverversion=5.4.0-56-generic firmware=29.1044073957.0 ip=[wifi ip] latency=0 link=yes multicast=yes wireless=IEEE 802.11
resources: irq:129 memory:d1000000-d1001fff
jfslin@pc001:~$ dpkg -l *dnsmasq*
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-=========================================-=========================-=========================-=======================================================================================
un dnsmasq <none> <none> (no description available)
ii dnsmasq-base 2.79-1 amd64 Small caching DNS proxy and DHCP/TFTP server
un dnsmasq-base-lua <none> <none> (no description available)
jfslin@pc001:~$ ls -al /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Nov 30 15:01 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
jfslin@pc001:~$ lspci -nnk | grep 0200 -A2
01:00.0 Ethernet controller [0200]: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller [10ec:8168] (rev 15)
Subsystem: Dell RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller [1028:09b6]
Kernel driver in use: r8169
jfslin@pc001:~$ dmesg | grep r8169
[no content]
jfslin@pc001:~$ systemctl status NetworkManager.service --no-pager -l
● NetworkManager.service - Network Manager
Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-12-15 10:50:40 EST; 16min ago
Docs: man:NetworkManager(8)
Main PID: 2543 (NetworkManager)
Tasks: 6 (limit: 4915)
CGroup: /system.slice/NetworkManager.service
├─2543 /usr/sbin/NetworkManager --no-daemon
├─2567 /sbin/dhclient -d -q -sf /usr/lib/NetworkManager/nm-dhcp-helper -pf /run/dhclient-enp1s0.pid -lf /var/lib/NetworkManager/dhclient-a9da0b86-eff3-30c4-acd5-dd333e4b87c4-enp1s0.lease -cf /var/lib/NetworkManager/dhclient-enp1s0.conf enp1s0
└─2691 /sbin/dhclient -d -q -sf /usr/lib/NetworkManager/nm-dhcp-helper -pf /run/dhclient-wlp2s0.pid -lf /var/lib/NetworkManager/dhclient-dc91afb3-030f-4cd3-9363-7b24d499b3e1-wlp2s0.lease -cf /var/lib/NetworkManager/dhclient-wlp2s0.conf wlp2s0
Dec 15 10:50:44 pc001 NetworkManager[2543]: <info> [1608047444.9669] dhcp (wlp2s0): domain search '[uni].ca.'
Dec 15 10:50:44 pc001 NetworkManager[2543]: <info> [1608047444.9669] dhcp (wlp2s0): domain search '[sub1.uni].ca.'
Dec 15 10:50:44 pc001 NetworkManager[2543]: <info> [1608047444.9669] dhcp (wlp2s0): domain search '[sub2.uni].ca.'
Dec 15 10:50:44 pc001 NetworkManager[2543]: <info> [1608047444.9669] dhcp4 (wlp2s0): state changed unknown -> bound
Dec 15 10:50:44 pc001 NetworkManager[2543]: <info> [1608047444.9706] device (wlp2s0): state change: ip-config -> ip-check (reason 'none', sys-iface-state: 'managed')
Dec 15 10:50:44 pc001 NetworkManager[2543]: <info> [1608047444.9723] device (wlp2s0): state change: ip-check -> secondaries (reason 'none', sys-iface-state: 'managed')
Dec 15 10:50:44 pc001 dhclient[2691]: bound to [wifi ip] -- renewal in 10196 seconds.
Dec 15 10:50:44 pc001 NetworkManager[2543]: <info> [1608047444.9729] device (wlp2s0): state change: secondaries -> activated (reason 'none', sys-iface-state: 'managed')
Dec 15 10:50:44 pc001 NetworkManager[2543]: <info> [1608047444.9808] device (wlp2s0): Activation: successful, device activated.
Dec 15 10:50:44 pc001 NetworkManager[2543]: <info> [1608047444.9826] manager: startup complete
jfslin@pc001:~$ cat /etc/resolv.conf
nameserver 127.0.0.53
options edns0
search [uni].ca [sub1.uni].ca [sub2.uni].ca
我看到有人遇到了一个问题,当计算机关闭时,他们的 IP 被另一台机器占用。当我失去连接时 ping 我的静态 IP 无法解决,这表明这不是问题所在。(https://unix.stackexchange.com/questions/211931/intermittent-network-disconnection-ubuntu-troubshooting)
我尝试过的事情总结:
- 设置静态 IP 而不是 DHCP -> 似乎没用。目前使用 DHCP
- 禁用 IPv6,如上所述Ubuntu 18.04 LTS 上的 WiFi 随机断开连接
- 禁用 wifi -> 似乎没用。目前
- 禁用蓝牙 -> 似乎没用。目前已关闭
- 尝试了不同的端口和电缆 -> 但是,如果这是建筑问题,我能做的事情就有限了
- /etc/NetworkManager/NetworkManager.conf,managed=false -> managed=true,如上所述即使已连接,也显示“有线网络已断开”——无法连接以太网
- 计算机设置为永不自动挂起,所以我不认为这是此处描述的问题:Ubuntu 18.04-挂起后以太网断开连接
谢谢。
编辑1:
我在 journalctl 中找到了这些条目。也许是 UFW 防火墙问题,导致我从 CONNECT_GLOBAL(互联网)降级到 CONNECT_SITE(仅限本地网络连接?)
Dec 16 08:25:16 pc001 NetworkManager[990]: <info> [1608125116.8809] connectivity: (enp1s0) timed out
Dec 16 08:25:16 pc001 NetworkManager[990]: <info> [1608125116.8810] manager: NetworkManager state is now CONNECTED_SITE
Dec 16 08:25:16 pc001 dbus-daemon[977]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' requested by ':1.14' (uid=0 pid=990 comm="/usr/sbin/NetworkMan
Dec 16 08:25:16 pc001 whoopsie[1706]: [08:25:16] offline
Dec 16 08:25:16 pc001 systemd[1]: Starting Network Manager Script Dispatcher Service...
Dec 16 08:25:16 pc001 dbus-daemon[977]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Dec 16 08:25:16 pc001 systemd[1]: Started Network Manager Script Dispatcher Service.
Dec 16 08:25:16 pc001 nm-dispatcher[25655]: req:1 'connectivity-change': new request (1 scripts)
Dec 16 08:25:16 pc001 nm-dispatcher[25655]: req:1 'connectivity-change': start running ordered scripts...
Dec 16 08:25:53 pc001 kernel: [UFW BLOCK] IN=enp1s0 OUT= MAC=[some mac] SRC=[gateway ip] DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0xC0 TTL=1 ID=24289 PROTO=2
Dec 16 08:26:53 pc001 kernel: [UFW BLOCK] IN=enp1s0 OUT= MAC=[some mac] SRC=[gateway ip] DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0xC0 TTL=1 ID=24527 PROTO=2
Dec 16 08:27:53 pc001 kernel: [UFW BLOCK] IN=enp1s0 OUT= MAC=[some mac] SRC=[gateway ip] DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0xC0 TTL=1 ID=24852 PROTO=2
Dec 16 08:28:53 pc001 kernel: [UFW BLOCK] IN=enp1s0 OUT= MAC=[some mac] SRC=[gateway ip] DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0xC0 TTL=1 ID=25091 PROTO=2
Dec 16 08:29:51 pc001 NetworkManager[990]: <info> [1608125391.2623] manager: NetworkManager state is now CONNECTED_GLOBAL
Dec 16 08:29:51 pc001 dbus-daemon[977]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service' requested by ':1.14' (uid=0 pid=990 comm="/usr/sbin/NetworkMan
Dec 16 08:29:51 pc001 systemd[1]: Starting Network Manager Script Dispatcher Service...
Dec 16 08:29:51 pc001 whoopsie[1706]: [08:29:51] The default IPv4 route is: /org/freedesktop/NetworkManager/ActiveConnection/1
Dec 16 08:29:51 pc001 whoopsie[1706]: [08:29:51] Not a paid data plan: /org/freedesktop/NetworkManager/ActiveConnection/1
Dec 16 08:29:51 pc001 whoopsie[1706]: [08:29:51] Found usable connection: /org/freedesktop/NetworkManager/ActiveConnection/1
Dec 16 08:29:51 pc001 dbus-daemon[977]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Dec 16 08:29:51 pc001 systemd[1]: Started Network Manager Script Dispatcher Service.
Dec 16 08:29:51 pc001 nm-dispatcher[30766]: req:1 'connectivity-change': new request (1 scripts)
Dec 16 08:29:51 pc001 nm-dispatcher[30766]: req:1 'connectivity-change': start running ordered scripts...
[...snip some long log message aboug gdm3...]
Dec 16 08:29:52 pc001 whoopsie[1706]: [08:29:52] online
Dec 16 08:29:53 pc001 kernel: [UFW BLOCK] IN=enp1s0 OUT= MAC=[some mac] SRC=[gateway ip] DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0xC0 TTL=1 ID=25365 PROTO=2
Dec 16 08:30:53 pc001 kernel: [UFW BLOCK] IN=enp1s0 OUT= MAC=[some mac] SRC=[gateway ip] DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0xC0 TTL=1 ID=26415 PROTO=2
Dec 16 08:31:53 pc001 kernel: [UFW BLOCK] IN=enp1s0 OUT= MAC=[some mac] SRC=[gateway ip] DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0xC0 TTL=1 ID=26829 PROTO=2
Dec 16 08:32:53 pc001 kernel: [UFW BLOCK] IN=enp1s0 OUT= MAC=[some mac] SRC=[gateway ip] DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0xC0 TTL=1 ID=27101 PROTO=2
Dec 16 08:33:53 pc001 kernel: [UFW BLOCK] IN=enp1s0 OUT= MAC=[some mac] SRC=[gateway ip] DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0xC0 TTL=1 ID=27381 PROTO=2
Dec 16 08:34:53 pc001 kernel: [UFW BLOCK] IN=enp1s0 OUT= MAC=[some mac] SRC=[gateway ip] DST=224.0.0.1 LEN=32 TOS=0x00 PREC=0xC0 TTL=1 ID=27660 PROTO=2
Dec 16 08:35:16 pc001 NetworkManager[990]: <info> [1608125716.9100] connectivity: (enp1s0) timed out
Dec 16 08:35:16 hcrmiserv001 NetworkManager[990]: <info> [1608125716.9101] manager: NetworkManager state is now CONNECTED_SITE
jfslin@pc001:~$ sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22/tcp ALLOW IN Anywhere
80/tcp ALLOW IN Anywhere
443/tcp ALLOW IN Anywhere
答案1
仍然不确定是什么原因导致断开连接,但升级到 Ubuntu 20.04 似乎解决了这个断开连接问题。自升级以来,我在 24 小时内没有看到断开连接事件。