ubuntu networking disabled 的解决方法

本文提供了一套详细的步骤来解决Ubuntu系统中的网络连接问题。包括重启网络服务、激活网络接口、检查网络服务状态、验证设备是否被内核识别及测试网络连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

根据网络上的查找,大多是重启服务


命令如下


1:sudo service network-manager stop

2:sudo rm /var/lib/NetworkManager/NetworkManager.state

3:sudo service network-manager start



英文判断方法

来自 http://www.ehow.com/info_12058752_networking-disabled-ubuntu.html

ifconfig

  • Right-click the desktop and choose the "Open in Terminal" option to open a terminal window. Type "ifconfig -a" to view the status of the network interfaces. The ifconfig command is used to configure the network interfaces and to show the status of the interfaces. There should at least be an entry for the "lo," or loopback interface in the output of the command. There should also be an entry for "eth0", the Ethernet interface and "wlan0", the wireless card, if you have one. On some systems, the wireless may be called "eth1," rather than "wlan0." The string "inet addr" followed by the IP address of the interface is visible in the second line of the output for any connected interfaces.

Starting an Interface

  • If the interface is shown in the output of the ifconfig command, it may need to be activated manually. The command to activate an Ethernet interface is "sudo ifconfig eth0 up". The command to activate a wireless interface is "sudo iwconfig wlan0 essid "network"". Replace "network" with the name of the wireless network you want to connect to. Type "ifconfig -a" again to make sure that the interface was activated correctly. If the interface wasn't given an IP address, type "sudo dhclient eth0" or "sudo dhclient wlan0" to request one from the router or DHCP server.

Networking Service

  • If the ifconfig output doesn't show the loopback (lo) interface or any other network interface, it's likely that the networking service was never started during the boot process or was stopped manually. Type the command "sudo service --status-all" and look for the "networking" line. The "-" character at the beginning of the line means that the service isn't running. Type the command "sudo service networking start" to start the service.

dmesg

  • If the loopback device is visible, but one of the other interfaces isn't shown, the kernel may not recognize the device. Type the command "dmesg | grep "eth0"" or "dmesg | grep wlan0"" to see the kernel messages for the device. If there's no output from the command, the device wasn't recognized by the kernel during the boot process. If the device was never recognized, it may require a third-party driver. If the device was working, then stopped, the problem is probably hardware-based, or the kernel module for that device was disabled.

Ping

  • When everything looks as if it's working correctly, test it with the ping command. Type "ping google.com" or "ping yahoo.com" to test your connection. The ping command transmits a request to the address given and waits for a response. If the output indicates "unknown host" or if you get no response from the server, your router is probably the source of the problem. Ping the router directly by typing the command "ping 192.168.1.1". Replace "192.168.1.1" with the IP address of the router. If the router has no response, the Ethernet cable is bad or the router is no longer online.



Read more: Networking Is Disabled in Ubuntu | eHow.com http://www.ehow.com/info_12058752_networking-disabled-ubuntu.html#ixzz2SCvFXYW2

<think>我们正在解决Ubuntu系统中"network.servicenotfound"的问题。根据用户提供的系统信息,我们看到用户尝试使用`systemctl`命令时遇到了问题。实际上,在Ubuntu18.04及更高版本中,传统的`network.service`已经被`netplan`和`NetworkManager`或`systemd-networkd`所取代。从用户之前的命令输出中,我们可以看到:```networkd-dispatcher.serviceenabledenabledNetworkManager-dispatcher.serviceenabledenabledNetworkManager-wait-online.serviceenabledenabledNetworkManager.serviceenabledenabledsystemd-network-generator.servicedisabledenabledsystemd-networkd-wait-online.servicedisableddisabledsystemd-networkd.servicedisabledenabledsystemd-networkd.socketdisabledenablednetwork-online.targetstatic-network-pre.targetstatic-network.targetstatic-```注意:`systemd-networkd.service`是禁用状态(disabled),而`NetworkManager.service`是启用状态(enabled)。这意味着系统当前使用NetworkManager作为网络管理工具,而不是传统的network.service。因此,当用户尝试使用`sudosystemctlrestartnetwork.service`时,会收到"Unitnetwork.servicenotfound"的错误,因为该服务在系统中不存在。解决方案:1.确认当前网络管理服务是NetworkManager,并使用NetworkManager的命令行工具`nmcli`来管理网络。2.或者,如果用户希望使用systemd-networkd,则需要启用它并禁用NetworkManager。步骤:方案一:使用NetworkManager(当前已启用)1.重启NetworkManager服务:```bashsudosystemctlrestartNetworkManager```2.使用`nmcli`命令检查网络连接:```bashnmcliconnectionshow```3.重新连接网络(如果需要):```bashnmcliconnectiondown<connection-name>&&nmcliconnectionup<connection-name>```方案二:切换到systemd-networkd(如果用户希望使用)1.禁用NetworkManager:```bashsudosystemctldisable--nowNetworkManager```2.启用systemd-networkd:```bashsudosystemctlenable--nowsystemd-networkd```3.启用systemd-resolved(DNS解析服务):```bashsudosystemctlenable--nowsystemd-resolved```4.配置Netplan:编辑`/etc/netplan/`目录下的YAML配置文件(例如01-netcfg.yaml),并应用配置:```bashsudonetplanapply```注意:在Ubuntu中,网络配置现在由Netplan统一管理,无论后端是NetworkManager还是systemd-networkd。因此,建议用户通过Netplan配置文件来管理网络设置。如果用户需要配置静态IP地址,可以修改Netplan配置文件。例如:打开配置文件:```bashsudonano/etc/netplan/01-netcfg.yaml```示例配置(使用NetworkManager作为后端):```yamlnetwork:version:2renderer:NetworkManagerethernets:enp0s3:dhcp4:noaddresses:[192.168.1.10/24]gateway4:192.168.1.1nameservers:addresses:[8.8.8.8,8.8.4.4]```或者使用systemd-networkd作为后端:```yamlnetwork:version:2renderer:networkdethernets:enp0s3:dhcp4:noaddresses:[192.168.1.10/24]gateway4:192.168.1.1nameservers:addresses:[8.8.8.8,8.8.4.4]```保存后应用配置:```bashsudonetplanapply```因此,用户不需要使用`network.service`,而是通过Netplan和相应的后端服务(NetworkManager或systemd-networkd)来管理网络。如果用户仍然遇到网络问题,可以检查服务状态:```bashsudosystemctlstatusNetworkManager#或者systemd-networkdjournalctl-uNetworkManager-b#查看日志```总结:在Ubuntu新版本中,传统的`network.service`已被废弃,取而代之的是Netplan和两个可选的后端服务(NetworkManager或systemd-networkd)。用户应根据当前启用的服务使用对应的管理方式。相关问题:1.如何配置Netplan的静态IP地址?2.如何切换NetworkManager和systemd-networkd?3.如何解决NetworkManager和systemd-networkd的冲突?4.如何调试Netplan配置问题?</think>### 解决 Ubuntu 中 "network.service not found" 问题 在 Ubuntu 18.04 及更高版本中,传统的 `network.service` 已被弃用,取而代之的是 **Netplan****systemd-networkd****NetworkManager**。以下是完整的解决方案: #### 1. 确认当前网络服务状态 ```bash sudo systemctl status NetworkManager systemd-networkd ``` - 若输出显示 `NetworkManager active (running)` → 使用 NetworkManager - 若显示 `systemd-networkd active (running)` → 使用 systemd-networkd #### 2. 恢复网络功能的两种方案 ##### 方案一:使用 NetworkManager(推荐) ```bash # 启用并启动服务 sudo systemctl enable --now NetworkManager # 重启网络连接 sudo nmcli networking off && sudo nmcli networking on # 检查连接 nmcli connection show ``` ##### 方案二:切换到 systemd-networkd ```bash # 禁用 NetworkManager sudo systemctl disable --now NetworkManager # 启用 systemd-networkd sudo systemctl enable --now systemd-networkd systemd-resolved # 配置 Netplan sudo nano /etc/netplan/*.yaml ``` 示例配置: ```yaml network: version: 2 renderer: networkd # 使用 systemd-networkd ethernets: eth0: dhcp4: true optional: true ``` 应用配置: ```bash sudo netplan apply ``` #### 3. 关键问题排查 - **服务冲突检测**: ```bash systemctl list-dependencies network.target ``` - **日志分析**: ```bash journalctl -u NetworkManager -u systemd-networkd --since "5 minutes ago" ``` - **网络接口检查**: ```bash ip a # 查看接口状态 ip route # 检查路由 ``` #### 4. 常见错误解决 - **502 Bad Gateway 错误**: ```bash # 检查防火墙和代理设置 sudo ufw status env | grep -i proxy ``` - **服务启动失败**: ```bash # 重置服务配置 sudo apt install --reinstall network-manager sudo systemctl daemon-reload ``` > **重要提示**Ubuntu 18.04+ 默认使用 Netplan 配置网络,所有网络设置应通过 `/etc/netplan/` 目录下的 YAML 文件完成[^1]。传统 `/etc/network/interfaces` 文件已不再生效。 #### 5. 验证网络功能 ```bash ping -c4 8.8.8.8 # 测试基础连接 curl -I https://ubuntu.com # 测试HTTPS ip addr show eth0 # 检查IP分配 ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值