Ubuntu 16.04 LTS 和虚拟接口

Ubuntu 16.04 LTS 和虚拟接口

您好,尝试了不同的选项,通过谷歌搜索建议。

就今天而言,我有:

描述:Ubuntu 16.04.6 LTS 发布:16.04 代号:xenial

已更新至昨天

试图制作:

sudo ip address add 192.168.0.7/24 dev enz3   ;  
sudo ip address add 192.168.0.8/24 dev enz3

永恒的

我修改了 etc/network/interfaces 文件如下:

 # interfaces(5) file used by ifup(8) and ifdown(8)
auto lo 
iface lo inet loopback


iface enz3 inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1


auto enz3:1
allow-hotplug enz3:1
iface enz3:1 inet static
address 192.168.0.7
netmask 255.255.255.0
gateway 192.168.0.1

auto enz3:2
allow-hotplug enz3:2
iface enz3:2 inet static
address 192.168.0.8
netmask 255.255.255.0
gateway 192.168.0.1

然后我重新启动网络服务

systemctl restart networking

我收到一个错误:

xx@xx-VBox:~$ systemctl status  networking.service
networking.service - Raise network interfaces
   Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)

Drop-In: /run/systemd/generator/networking.service.d
           └─50-insserv.conf-$network.conf
 Active: failed (Result: exit-code) since mer 2019-06-05 12:15:39 CEST; 5s ago
     Docs: man:interfaces(5)
Process: 4423 ExecStop=/sbin/ifdown -a --read-environment --exclude=lo (code=exited, status=0/SUCCESS)
Process: 4963 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
Process: 4959 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environment --list --exclu
Main PID: 4963 (code=exited, status=1/FAILURE)

giu 05 12:15:38 xx-VBox systemd[1]: Starting Raise network interfaces...
giu 05 12:15:38 xx-VBox ifup[4963]: RTNETLINK answers: File exists
giu 05 12:15:38 xx-VBox ifup[4963]: Failed to bring up enz3:2.
giu 05 12:15:39 xx-VBox systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
giu 05 12:15:39 xx-VBox systemd[1]: Failed to start Raise network interfaces.
giu 05 12:15:39 xx-VBox systemd[1]: networking.service: Unit entered failed state.
giu 05 12:15:39 xx-VBox systemd[1]: networking.service: Failed with result 'exit-code'.

但尽管如此

ip addr

节目

 enz3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    inet 192.168.0.2/24 brd 192.168.0.255 scope global enz3
       valid_lft forever preferred_lft forever
    inet 192.168.0.7/24 brd 192.168.0.255 scope global secondary enz3:1
       valid_lft forever preferred_lft forever
    inet 192.168.0.8/24 brd 192.168.0.255 scope global secondary enz3:2
       valid_lft forever preferred_lft forever
    inet6 XXXXXXXXXXXXXXXXXXXXXXXXXX scope link 
       valid_lft forever preferred_lft forever

ifconfig

节目

  enz3

  enz3:1

  enz3:2

我可以连接并可视化 apache2 index.html

从 oustide 获取 192.168.0.2 地址默认 Web 服务器

以及两个虚拟主机网络服务器 192.168.0.7 和 192.168.0.8

我遗漏了什么?为什么会出现错误?还有其他东西无法与此设置配合使用吗?

编辑

该系统仅适用于访问 apache2 网络服务器:从外部我可以访问:192.168.0.02 192.168.0.07 192.168.0.08

从内部(192.168.0.2)我可以访问:localhost 192.168.0.7 192.168.0.8

但我无法从外部 (192.168.0.3) ping 192.168.0.2 或从内部 (192.168.0.2) 上网。我可以从虚拟机内部 ping 主机 192.168.0.3 (192.168.0.2 是 VirtualBox 上的虚拟机)

nslookup 在虚拟机内部不起作用(192.168.0.2)

答案1

debian 手册说

    iproute2 method

Also, ifupdown supports specifying multiple interfaces by repeating iface sections with the same interface name. The key difference from the method described above is that all such sections are treated by ifupdown as just one interface, so user can't add or remove them individually. However, up/down commands, as well as scripts, are called for every section as it used to be.

Note however that this method is dangerous! Certain driver/hardware combinations may sometimes fail to bring the link up if no labels are assigned to the alias interfaces. (Seen this on Debian Wheezy and Jessie with RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 01) auto-negotiating to 10/full. A similar warning from another person exists in the history of this page.)

This /etc/network/interfaces text assigns three IP addresses to eth0.

auto eth0
allow-hotplug eth0
iface eth0 inet static
    address 192.168.1.42/24
    gateway 192.168.1.1

iface eth0 inet static
    address 192.168.1.43/24

iface eth0 inet static
    address 192.168.1.44/24

# adding IP addresses from different subnets is also possible
iface eth0 inet static
    address 10.10.10.14/24

但即使使用标签(或者至少我认为我正在使用它们):

    auto enz3
allow-hotplug enz3
iface enz3 inet static
    address 192.168.0.2
    netmask 255.255.255.0
    gateway 192.168.0.1


iface enz3:1 inet static
    address 192.168.0.7
    netmask 255.255.255.0



iface enz3:2 inet static
    address 192.168.0.8
    netmask 255.255.255.0

我仍然收到错误:

giu 05 17:38:43 dv-VBox systemd[1]: Stopped Raise network interfaces.
giu 05 17:38:43 xx-VBox systemd[1]: Starting Raise network interfaces...
giu 05 17:38:43 xx-VBox ifup[5004]: RTNETLINK answers: File exists
giu 05 17:38:43 xx-VBox ifup[5004]: Failed to bring up enz3.
giu 05 17:38:43 xx-VBox systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
giu 05 17:38:43 xx-VBox systemd[1]: Failed to start Raise network interfaces.
giu 05 17:38:43 xx-VBox systemd[1]: networking.service: Unit entered failed state.
giu 05 17:38:43 xx-VBox systemd[1]: networking.service: Failed with result 'exit-code'.

下一步我应该尝试什么?

答案2

也许这就是答案?

如何使用 /etc/network/interfaces 代替 network-manager

不确定是否对 16.04 也有效?

没有

 [ifupdown] 
managed=false

已经存在

相关内容