如何在与以太网相同的子网中设置 VLAN?

如何在与以太网相同的子网中设置 VLAN?

我有一个物理网卡,开发名称为 eth0,ip 为 192.168.1.2,网关为 192.168.1.1,我想设置一个 VLAN,ip 为 192.168.1.x,网关与 eth0 相同。

设置 VLAN 运行顺利,我为 VLAN 指定了 iface 名称 eth0.10 和 IP 192.168.1.69。现在,当尝试建立连接时出现错误:

holmen@filserver:~$ sudo ifup eth0.10
Set name-type for VLAN subsystem. Should be visible in /proc/net/vlan/config
RTNETLINK answers: File exists
Failed to bring up eth0.10.

那么如何让 VLAN 连接到互联网以及错误消息的含义是什么?我的猜测是,这与广播有关。

设置:/etc/网络/接口

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp
        address 192.168.1.2
        netmask 255.255.255.0
        network 192.168.1.0
        gateway 192.168.1.1

iface eth0.10 inet static
        address 192.168.1.69
        netmask 255.255.255.0
        gateway 192.168.1.1

我已经删除了 auto eth0.10 因为我不想在启动时建立它

设置:如果配置

holmen@filserver:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:1a:4d:5b:02:5c
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21a:4dff:fe5b:25c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11670807 errors:0 dropped:0 overruns:0 frame:0
          TX packets:22363842 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:833725090 (833.7 MB)  TX bytes:31876321312 (31.8 GB)
          Interrupt:44 Base address:0x4000

eth0.10   Link encap:Ethernet  HWaddr 00:1a:4d:5b:02:5c
          inet addr:192.168.1.69  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21a:4dff:fe5b:25c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:432 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:41501 (41.5 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:16436  Metric:1
          RX packets:4899 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4899 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:697405 (697.4 KB)  TX bytes:697405 (697.4 KB)

设置:网络统计输出

holmen@filserver:~$ netstat -anr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0.10

测试:ping 输出域名

holmen@filserver:~$ ping -I eth0.10 www.dn.se
PING a1910.g1.akamai.net (23.60.69.161) from 192.168.1.2 eth0.10: 56(84) bytes of data.
From filserver.local (192.168.1.69) icmp_seq=1 Destination Host Unreachable
From filserver.local (192.168.1.69) icmp_seq=2 Destination Host Unreachable
From filserver.local (192.168.1.69) icmp_seq=3 Destination Host Unreachable
^C
--- a1910.g1.akamai.net ping statistics ---
5 packets transmitted, 0 received, +3 errors, 100% packet loss, time 4025ms
pipe 3

测试:ping输出ip地址

holmen@filserver:~$ ping -I eth0.10 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.1.2 eth0.10: 56(84) bytes of data.
From 192.168.1.69 icmp_seq=1 Destination Host Unreachable
From 192.168.1.69 icmp_seq=2 Destination Host Unreachable
From 192.168.1.69 icmp_seq=3 Destination Host Unreachable
^C
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 0 received, +3 errors, 100% packet loss, time 4023ms
pipe 3

答案1

您似乎正在尝试在不同的接口上设置重叠的子网。这会破坏你的路由表并使很多事情无法工作。其次,您尚未在配置中设置 VLAN,因此当您引用eth0.10它时缺少一些先决步骤。如果您确实需要一个 VLAN(我不相信您需要)请参阅Debian 的 wiki 了解如何正确设置 VLAN

就网络堆栈而言,在第 1 层之上,VLAN 接口也可能是物理接口,因此您需要将其视为物理接口。

如果您想要一个接口上具有重叠子网的附加 IP,则需要将其设置为辅助(也称为别名)IP。改为eth0.10in然后。eth0:10/etc/interfacesifup eth0:10

答案2

RTNETLINK answers: File exists这可能没有多大帮助,但我在 VPN 实验室工作时也遇到了同样的情况。

事实证明,我的路由表中仍然有一些来自上次运行客户端的旧条目,但我已经删除了以太网适配器。当我再次添加它时,它给了我,RTNETLINK answers: File exists直到我删除了路由表中使用该以太网适配器的旧条目。我不知道这是否是设计使然,但这是我在 Ubuntu 11.04 Natty Narwhal VM 上注意到的。

相关内容