vmware虚拟机ubuntu20.04网络网卡检测失败,ifconfig的ip错误,且网络连接不了

sstap
vmware虚拟机ubuntu20.04网络网卡检测失败,ifconfig的ip错误,且网络连接不了_第1张图片
可以看出,我的第二网卡没有检测出来。

root@jitsi:/home/ubuntu/Desktop# ifconfig
lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (本地环回)
        RX packets 194  bytes 16018 (16.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 194  bytes 16018 (16.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

发现重点线索一:systemd-resolved.service被屏蔽

root@jitsi:/home/ubuntu/Desktop# sudo /sbin/dhclient
Failed to reload-or-try-restart systemd-resolved.service: Unit systemd-resolved.service is masked.

通过查看,/lib/systemd/system/systemd-resolved.service文件存在

root@jitsi:/lib/systemd/system# cat systemd-resolved.service
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Network Name Resolution
Documentation=man:systemd-resolved.service(8)
Documentation=https://www.freedesktop.org/wiki/Software/systemd/resolved
Documentation=https://www.freedesktop.org/wiki/Software/systemd/writing-network-configuration-managers
Documentation=https://www.freedesktop.org/wiki/Software/systemd/writing-resolver-clients
DefaultDependencies=no
After=systemd-sysusers.service systemd-networkd.service
Before=network.target nss-lookup.target shutdown.target
Conflicts=shutdown.target
Wants=nss-lookup.target

[Service]
AmbientCapabilities=CAP_SETPCAP CAP_NET_RAW CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_SETPCAP CAP_NET_RAW CAP_NET_BIND_SERVICE
ExecStart=!!/lib/systemd/systemd-resolved
LockPersonality=yes
MemoryDenyWriteExecute=yes
NoNewPrivileges=yes
PrivateDevices=yes
PrivateTmp=yes
ProtectControlGroups=yes
ProtectHome=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
ProtectKernelLogs=yes
ProtectSystem=strict
Restart=always
RestartSec=0
RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
RuntimeDirectory=systemd/resolve
RuntimeDirectoryPreserve=yes
SystemCallArchitectures=native
SystemCallErrorNumber=EPERM
SystemCallFilter=@system-service
Type=notify
User=systemd-resolve
WatchdogSec=3min

[Install]
WantedBy=multi-user.target
Alias=dbus-org.freedesktop.resolve1.service

查看 systemd-resolved.service服务状态,确认systemd-resolved.service被屏蔽。

root@jitsi:/lib/systemd/system# systemctl status systemd-resolved.service
● systemd-resolved.service
     Loaded: masked (Reason: Unit systemd-resolved.service is masked.)
     Active: inactive (dead)
root@jitsi:/lib/systemd/system# systemctl restart systemd-resolved.service
Failed to restart systemd-resolved.service: Unit systemd-resolved.service is masked.

解除屏蔽,并重新启动systemd-resolved.service服务。

root@jitsi:/lib/systemd/system# systemctl unmask systemd-resolved
Removed /etc/systemd/system/systemd-resolved.service.
root@jitsi:/lib/systemd/system# systemctl restart systemd-resolved.service
root@jitsi:/lib/systemd/system# systemctl status systemd-resolved.service
● systemd-resolved.service - Network Name Resolution
     Loaded: loaded (/lib/systemd/system/systemd-resolved.service; disabled; ve>
     Active: active (running) since Mon 2021-04-12 16:55:51 CST; 3s ago
       Docs: man:systemd-resolved.service(8)
             https://www.freedesktop.org/wiki/Software/systemd/resolved
             https://www.freedesktop.org/wiki/Software/systemd/writing-network->
             https://www.freedesktop.org/wiki/Software/systemd/writing-resolver>
   Main PID: 2282 (systemd-resolve)
     Status: "Processing requests..."
      Tasks: 1 (limit: 4618)
     Memory: 4.8M
     CGroup: /system.slice/systemd-resolved.service
             └─2282 /lib/systemd/systemd-resolved

Apr 12 16:55:50 jitsi.example.com systemd[1]: Starting Network Name Resolution...
Apr 12 16:55:51 jitsi.example.com systemd-resolved[2282]: Positive Trust Anchors:
Apr 12 16:55:51 jitsi.example.com systemd-resolved[2282]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Apr 12 16:55:51 jitsi.example.com systemd-resolved[2282]: Negative trust anchors: 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-a>
Apr 12 16:55:51 jitsi.example.com systemd-resolved[2282]: Using system hostname 'jitsi.example.com'.
Apr 12 16:55:51 jitsi.example.com systemd-resolved[2282]: Another process is already listening on TCP socket 127.0.0.53:53.
Apr 12 16:55:51 jitsi.example.com systemd-resolved[2282]: Turning off local DNS stub support.
Apr 12 16:55:51 jitsi.example.com systemd[1]: Started Network Name Resolution.

此时,网络可以正常访问了。但是与我想要的静态ip地址192.168.107.3地址不符。

root@jitsi:/lib/systemd/system# ifconfig
ens33: flags=4163  mtu 1500
        inet 192.168.107.130  netmask 255.255.255.0  broadcast 192.168.107.255
        inet6 fe80::20c:29ff:fe6e:c31b  prefixlen 64  scopeid 0x20
        ether 00:0c:29:6e:c3:1b  txqueuelen 1000  (以太网)
        RX packets 315  bytes 22287 (22.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 484  bytes 32877 (32.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (本地环回)
        RX packets 467  bytes 40027 (40.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 467  bytes 40027 (40.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

查看/etc/netplan/下的网卡配置文件

root@jitsi:/etc/netplan# cat 01-network-manager-all.yaml 
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    ens33:
      dhcp4: no
      addresses: [192.168.107.3/24]
      gateway4: 192.168.107.1
      nameservers:
        addresses: [114.114.114.114,8.8.8.8]

使网卡配置文件立刻生效,此时,网络又连接不上了。

root@jitsi:/etc/netplan# sudo netplan apply
root@jitsi:/etc/netplan# ifconfig
ens33: flags=4163  mtu 1500
        ether 00:0c:29:6e:c3:1b  txqueuelen 1000  (以太网)
        RX packets 2939  bytes 2419000 (2.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2654  bytes 306315 (306.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (本地环回)
        RX packets 671  bytes 57931 (57.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 671  bytes 57931 (57.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

dhclient命令可以使用网络接口名称作为参数,通过DHCP方式为指定的网络接口申请新的IP地址等参数。当不指定任何参数时,dhclient命令将会尝试为回环接口(lo)以外的所有网络接口申请新的IP地址。通过执行sudo /sbin/dhclient,网络重新得以连接,但仍不是我要的静态ip192.168.107.3

root@jitsi:/etc/netplan# sudo /sbin/dhclient
root@jitsi:/etc/netplan# ifconfig
ens33: flags=4163  mtu 1500
        inet 192.168.107.130  netmask 255.255.255.0  broadcast 192.168.107.255
        ether 00:0c:29:6e:c3:1b  txqueuelen 1000  (以太网)
        RX packets 3000  bytes 2428932 (2.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2715  bytes 313529 (313.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (本地环回)
        RX packets 674  bytes 58195 (58.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 674  bytes 58195 (58.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

对/etc/netplan的网卡配置文件作出修改

root@jitsi:/etc/netplan# cat 01-network-manager-all.yaml 
# Let NetworkManager manage all devices on this system
network:
  version: 2
  ethernets:
    ens33:
      dhcp4: no
      optional: true
      addresses: [192.168.107.3/24]
      gateway4: 192.168.107.1
      nameservers:
        addresses: [114.114.114.114,8.8.8.8]

去掉了

renderer: NetworkManager

使网卡配置文件立刻生效,此时,网络静态地址配置成功并可正常访问网站。

root@jitsi:/etc/netplan# sudo netplan apply
root@jitsi:/etc/netplan# ifconfig
ens33: flags=4163  mtu 1500
        inet 192.168.107.3  netmask 255.255.255.0  broadcast 192.168.107.255
        ether 00:0c:29:6e:c3:1b  txqueuelen 1000  (以太网)
        RX packets 3960  bytes 2780231 (2.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3864  bytes 443472 (443.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (本地环回)
        RX packets 948  bytes 96365 (96.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 948  bytes 96365 (96.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


vmware虚拟机ubuntu20.04网络网卡检测失败,ifconfig的ip错误,且网络连接不了_第2张图片

你可能感兴趣的:(工作总结,vmware,linux,ubuntu)