sstap
可以看出,我的第二网卡没有检测出来。
root@jitsi:/home/ubuntu/Desktop# ifconfiglo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1000 (本地环回)RX packets 194 bytes 16018 (16.0 KB)RX errors 0 dropped 0 overruns 0 frame 0TX 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/dhclientFailed 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 ResolutionDocumentation=man:systemd-resolved.service(8)Documentation=/wiki/Software/systemd/resolvedDocumentation=/wiki/Software/systemd/writing-network-configuration-managersDocumentation=/wiki/Software/systemd/writing-resolver-clientsDefaultDependencies=noAfter=systemd-sysusers.service systemd-networkd.serviceBefore=network.target nss-lookup.target shutdown.targetConflicts=shutdown.targetWants=nss-lookup.target[Service]AmbientCapabilities=CAP_SETPCAP CAP_NET_RAW CAP_NET_BIND_SERVICECapabilityBoundingSet=CAP_SETPCAP CAP_NET_RAW CAP_NET_BIND_SERVICEExecStart=!!/lib/systemd/systemd-resolvedLockPersonality=yesMemoryDenyWriteExecute=yesNoNewPrivileges=yesPrivateDevices=yesPrivateTmp=yesProtectControlGroups=yesProtectHome=yesProtectKernelModules=yesProtectKernelTunables=yesProtectKernelLogs=yesProtectSystem=strictRestart=alwaysRestartSec=0RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6RestrictNamespaces=yesRestrictRealtime=yesRestrictSUIDSGID=yesRuntimeDirectory=systemd/resolveRuntimeDirectoryPreserve=yesSystemCallArchitectures=nativeSystemCallErrorNumber=EPERMSystemCallFilter=@system-serviceType=notifyUser=systemd-resolveWatchdogSec=3min[Install]WantedBy=multi-user.targetAlias=dbus-org.freedesktop.resolve1.service
查看 systemd-resolved.service服务状态,确认systemd-resolved.service被屏蔽。
root@jitsi:/lib/systemd/system# systemctl status systemd-resolved.service● systemd-resolved.serviceLoaded: masked (Reason: Unit systemd-resolved.service is masked.)Active: inactive (dead)root@jitsi:/lib/systemd/system# systemctl restart systemd-resolved.serviceFailed to restart systemd-resolved.service: Unit systemd-resolved.service is masked.
解除屏蔽,并重新启动systemd-resolved.service服务。
root@jitsi:/lib/systemd/system# systemctl unmask systemd-resolvedRemoved /etc/systemd/system/systemd-resolved.service.root@jitsi:/lib/systemd/system# systemctl restart systemd-resolved.serviceroot@jitsi:/lib/systemd/system# systemctl status systemd-resolved.service● systemd-resolved.service - Network Name ResolutionLoaded: loaded (/lib/systemd/system/systemd-resolved.service; disabled; ve>Active: active (running) since Mon -04-12 16:55:51 CST; 3s agoDocs: man:systemd-resolved.service(8)/wiki/Software/systemd/resolved/wiki/Software/systemd/writing-network->/wiki/Software/systemd/writing-resolver>Main PID: 2282 (systemd-resolve)Status: "Processing requests..."Tasks: 1 (limit: 4618)Memory: 4.8MCGroup: /system.slice/systemd-resolved.service└─2282 /lib/systemd/systemd-resolvedApr 12 16:55:50 systemd[1]: Starting Network Name Resolution...Apr 12 16:55:51 systemd-resolved[2282]: Positive Trust Anchors:Apr 12 16:55:51 systemd-resolved[2282]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8dApr 12 16:55:51 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 systemd-resolved[2282]: Using system hostname ''.Apr 12 16:55:51 systemd-resolved[2282]: Another process is already listening on TCP socket 127.0.0.53:53.Apr 12 16:55:51 systemd-resolved[2282]: Turning off local DNS stub support.Apr 12 16:55:51 systemd[1]: Started Network Name Resolution.
此时,网络可以正常访问了。但是与我想要的静态ip地址192.168.107.3地址不符。
root@jitsi:/lib/systemd/system# ifconfigens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.107.130 netmask 255.255.255.0 broadcast 192.168.107.255inet6 fe80::20c:29ff:fe6e:c31b prefixlen 64 scopeid 0x20<link>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 0TX packets 484 bytes 32877 (32.8 KB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1000 (本地环回)RX packets 467 bytes 40027 (40.0 KB)RX errors 0 dropped 0 overruns 0 frame 0TX 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 systemnetwork:version: 2renderer: NetworkManagerethernets:ens33:dhcp4: noaddresses: [192.168.107.3/24]gateway4: 192.168.107.1nameservers:addresses: [114.114.114.114,8.8.8.8]
使网卡配置文件立刻生效,此时,网络又连接不上了。
root@jitsi:/etc/netplan# sudo netplan applyroot@jitsi:/etc/netplan# ifconfigens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500ether 00:0c:29:6e:c3:1b txqueuelen 1000 (以太网)RX packets 2939 bytes 2419000 (2.4 MB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 2654 bytes 306315 (306.3 KB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1000 (本地环回)RX packets 671 bytes 57931 (57.9 KB)RX errors 0 dropped 0 overruns 0 frame 0TX 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/dhclientroot@jitsi:/etc/netplan# ifconfigens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.107.130 netmask 255.255.255.0 broadcast 192.168.107.255ether 00:0c:29:6e:c3:1b txqueuelen 1000 (以太网)RX packets 3000 bytes 2428932 (2.4 MB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 2715 bytes 313529 (313.5 KB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1000 (本地环回)RX packets 674 bytes 58195 (58.1 KB)RX errors 0 dropped 0 overruns 0 frame 0TX 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 systemnetwork:version: 2ethernets:ens33:dhcp4: nooptional: trueaddresses: [192.168.107.3/24]gateway4: 192.168.107.1nameservers:addresses: [114.114.114.114,8.8.8.8]
去掉了
renderer: NetworkManager
使网卡配置文件立刻生效,此时,网络静态地址配置成功并可正常访问网站。
root@jitsi:/etc/netplan# sudo netplan applyroot@jitsi:/etc/netplan# ifconfigens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.107.3 netmask 255.255.255.0 broadcast 192.168.107.255ether 00:0c:29:6e:c3:1b txqueuelen 1000 (以太网)RX packets 3960 bytes 2780231 (2.7 MB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 3864 bytes 443472 (443.4 KB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1000 (本地环回)RX packets 948 bytes 96365 (96.3 KB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 948 bytes 96365 (96.3 KB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0