3 个网卡,一个连接到 GW,另外两个分别连接到 1 个主机。如何连接主机?

3 个网卡,一个连接到 GW,另外两个分别连接到 1 个主机。如何连接主机?

我正在为我的班级做一些测试,我有一个 Ubuntu Server 16.04,完全原装。

该服务器有 3 个以太网网卡,其中一个连接到我的网关 192.168.1.1,另外两个分别连接到一台主机。

是否可以将这些主机放在单独的网络中,并且仍然能够连接到我的主网关并访问互联网?

这是我的接口文件:

# 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

allow-hotplug enp2s3
iface enp2s3 inet static
    address 192.168.1.200
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.1
    dns-nameservers 192.168.1.1

allow-hotplug enp2s2
iface enp2s2 inet static
    address 192.168.100.1
    netmask 255.255.255.0
    network 192.168.100.0
    broadcast 192.168.100.255
    gateway 192.168.1.200
    dns-nameservers 192.168.1.200

allow-hotplug enp2s1
iface enp2s1 inet static
    address 192.168.101.1
    netmask 255.255.255.0
    network 192.168.101.0
    broadcast 192.168.101.255
    gateway 192.168.1.200
    dns-nameservers 192.168.1.200

答案1

当然可以。网关应该与接口位于同一网络上,并且在典型设置中你应该只有一个网关在通往互联网的接口上。​​这是最后的手段,即将所有不在我直接连接的网络上的内容发送到这里。名称服务器也是如此,它对于计算机来说是全局的。

因此您已经设置了 3 个网络。从 enp2s1 和 enp2s2 中 取出gateway 192.168.1.200和行是该特定计算机的配置。因此,您告诉自己的计算机使用来自另一个网络的自己的 IP 作为网关和 DNS 服务器。(广播和网络不会造成影响,但实际上并不需要,因为您的 PC 在计算这些方面比您强得多)。dns-nameservers 192.168.1.200/etc/network/interfaces

现在在 192.168.100.0 255.255.255.0 网络上的 PC 上使用 IP 配置,并告诉另一台 PC 使用您的服务器作为192.168.100.1其网关,与 192.168.101.0 255.255.255.0 上的 PC 一样,为其配置 IP,并使用您的服务器 192.168.101.1 作为其网关。

然后通过取消注释来告诉你的服务器进行路由网.ipv4.ip_forward=1在你的 /etc/sysctl.conf 中

就这些了,但很可能您的互联网仍然无法在您的“主机”上运行。原因在于您的路由器。它只知道一个内部网络,即 192.168.1.0/24,并将所有其他信息发送到其默认网关,该网关可能是您的 ISP。例如,它不知道如何处理发送到 192.168 的数据包。100.X 和 192.168.101.0,因此它会将它们转发回互联网,而您的 ISP 会丢弃这些数据包。要解决此问题,您需要登录路由器并添加静态/手动路由,告诉它转发所有发往 192.168.100.0/24 和 192.168.101.0/24 到你的服务器 192.168.1.200

相关内容