我在 Virtualbox 中设置了一台 Ubuntu 16.04 服务器作为客户机。该服务器在网络设置中使用 3 个接口:仅主机、NAT、桥接
/etc/network/interfaces文件设置如下:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# Host-only interface
auto eth0
iface eth0 inet static
address 192.168.56.105
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255
# NAT interface
auto eth1
iface eth1 inet dhcp
# Bridged interface
auto eth2
iface eth2 inet static
address 192.168.0.105
netmask 255.255.255.0
gateway 192.168.0.255
dns-nameservers 8.8.8.8
我已在 grub 配置中禁用“可预测的网络接口名称”选项
GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=0"
重启期间我收到以下消息:
Failed to start Raise network interfaces
但是当我运行 ifconfig 时一切似乎正常:
eth0 Link encap:Ethernet HWaddr 08:00:27:37:e4:c4
inet addr:192.168.56.105 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe37:e4c4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:311 errors:0 dropped:0 overruns:0 frame:0
TX packets:39 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:35338 (35.3 KB) TX bytes:5530 (5.5 KB)
eth1 Link encap:Ethernet HWaddr 08:00:27:d6:8d:1a
inet addr:10.0.3.15 Bcast:10.0.3.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fed6:8d1a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:29 errors:0 dropped:0 overruns:0 frame:0
TX packets:37 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2970 (2.9 KB) TX bytes:3063 (3.0 KB)
eth2 Link encap:Ethernet HWaddr 08:00:27:6d:be:ad
inet addr:192.168.0.105 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe6d:bead/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:634 errors:0 dropped:0 overruns:0 frame:0
TX packets:29 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:55125 (55.1 KB) TX bytes:1988 (1.9 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:160 errors:0 dropped:0 overruns:0 frame:0
TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:11840 (11.8 KB) TX bytes:11840 (11.8 KB)
但是当我跑步时
sudo service networking restart
我收到此消息:
Job for networking.service failed because the control process exited with
error code. See "systemctl status networking.service" and "journalctl -xe"
for details.
以下是 journalctl -xe 的结果
-- Unit networking.service has begun starting up.
May 07 16:31:54 jakku ifup[2056]: RTNETLINK answers: File exists
May 07 16:31:54 jakku ifup[2056]: Failed to bring up eth2.
May 07 16:31:54 jakku systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
May 07 16:31:54 jakku systemd[1]: Failed to start Raise network interfaces.
-- Subject: Unit networking.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit networking.service has failed.
有人能帮我吗?
答案1
我猜你又掉进了一个老陷阱。根据几篇帖子例如 codeghar 的一个 sudo service networking restart
早已被弃用
因为它可能无法再次启用某些接口
豪尔赫·卡斯特罗这个答案
sudo ifdown --exclude=lo -a && sudo ifup --exclude=lo -a
因此networking restart
用替换ifdown... && ifup...
。
顺便说一句:ifconfig
也已经被弃用很长时间了 -ip
从包中使用iproute2
(另见我的问题/答案)