我有一个虚拟盒子(6.1),最小化的是ubuntu。在网络部分的虚拟机设置中,选择“桥接适配器”。
root@ubuntu:/home/mista# dmesg -T|head -1
[Sun Oct 24 10:56:10 2021] Linux version 5.4.0-89-generic (buildd@lgw01-amd64-044) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #100-Ubuntu SMP Fri Sep 24 14:50:10 UTC 2021 (Ubuntu 5.4.0-89.100-generic 5.4.143)
root@ubuntu:/home/mista# 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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:1e:5b:6d brd ff:ff:ff:ff:ff:ff
inet 192.168.88.236/24 brd 192.168.88.255 scope global dynamic enp0s3
valid_lft 473sec preferred_lft 473sec
inet6 fe80::a00:27ff:fe1e:5b6d/64 scope link
valid_lft forever preferred_lft forever
root@ubuntu:/home/mista# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto enp0s3
iface enp0s3 inet static
address 192.168.88.236
netmask 255.255.255.0
gateway 192.168.88.1
root@ubuntu:/home/mista# ifdown enp0s3
ifdown: interface enp0s3 not configured
root@ubuntu:/home/mista# ifup enp0s3
RTNETLINK answers: File exists
ifup: failed to bring up enp0s3
root@ubuntu:/home/mista# systemctl status networking
● networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2021-10-24 11:24:35 MSK; 1min 39s ago
Docs: man:interfaces(5)
Process: 826 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
Main PID: 826 (code=exited, status=1/FAILURE)
Oct 24 11:24:35 ubuntu systemd[1]: Starting Raise network interfaces...
Oct 24 11:24:35 ubuntu ifup[844]: RTNETLINK answers: File exists
Oct 24 11:24:35 ubuntu ifup[826]: ifup: failed to bring up enp0s3
Oct 24 11:24:35 ubuntu systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Oct 24 11:24:35 ubuntu systemd[1]: networking.service: Failed with result 'exit-code'.
Oct 24 11:24:35 ubuntu systemd[1]: Failed to start Raise network interfaces.
root@ubuntu:/home/mista# cat /run/network/ifstate
lo=lo
我尝试将字符串“enp0s3=enp0s3”添加到 /run/network/ifstate 但它不起作用。但是 /run - 它是一个虚拟文件系统,并且带有 enp0s3 的字符串将在重新加载守护程序或重新启动服务器后被删除。有人说所有配置的接口都应该显示在/run/network/ifstate中。但是,如果在 config 中注册了 enp0s3 接口,为什么它不会显示在 /run/network/ifstate 中呢?
也许我的配置文件有一些错误?
重启后,地址192.168.88.236/24上升,但这些命令不起作用:
ifup enp0s3
ifdown enp0s3
我不明白为什么会出现错误:
root@ubuntu:/home/mista# ifdown enp0s3
ifdown: interface enp0s3 not configured
root@ubuntu:/home/mista# ifup enp0s3
RTNETLINK answers: File exists
ifup: failed to bring up enp0s3
除了文件 /etc/network/interfaces 之外,ifup 和 ifdown 可以在哪里获取与接口一起使用的配置?
文件 /etc/networks 为空。
答案1
我发现 dhcpv4 在此conf文件中启用 -/etc/netplan/01-netcfg.yaml。重新启动后 DHCP 被禁用。
当虚拟机打开时,网络守护进程从/etc/网络/接口(静态地址)配置和来自/etc/netplan/01-netcfg.yaml(DHCP)。
因此,当系统启动时,操作系统尝试通过静态和 DHCP 从不同的配置中获取地址 192.168.88.236/24。冲突也因此产生。
在/etc/netplan/01-netcfg.yaml我变了“dhcpv4:是”为了enp0s3到“dhcpv4:否”。重启后 dhcpclient 就消失了。