linux虚拟网络设备之vlan配置详解
https://www.jb51.net/article/130486.htm简介VLAN是网络栈的一个附加功能,且位于下两层。首先来学习Linux中网络栈下两层的实现,再去看如何把VLAN这个功能附加上去。下两层涉及到具体的硬件设备,日趋完善的Linux内核已经做到了很好的代码隔离,对网络设备驱动也是如此,如下图所示:这里要注意的是,Linux下的网络设备net_dev并不一定都对应实际的硬件设
https://www.jb51.net/article/130486.htm
注意VLAN方式达到了网络隔离,但是mac地址是相同的,意思就是基于同一个网卡出来的vlan mac地址相同。要想不通,可以用macvlan,macvtap等相关高级功能
简介
VLAN是网络栈的一个附加功能,且位于下两层。首先来学习Linux中网络栈下两层的实现,再去看如何把VLAN这个功能附加上去。下两层涉及到具体的硬件设备,日趋完善的Linux内核已经做到了很好的代码隔离,对网络设备驱动也是如此,如下图所示:
这里要注意的是,Linux下的网络设备net_dev并不一定都对应实际的硬件设备,只要注册一个struct net_device{}结构体(netdevice.h)到内核中,那么这个网络设备就存在了。该结构体很庞大,其中包含设备的协议地址(对于IP即IP地址),这样它就能被网络层识别,并参与路由系统,最有名的当数loopback设备。不同的设备(包括硬件和非硬件)的ops操作方法各不相同,由驱动自己实现。一些通用性的、与设备无关的操作流程(如设备锁定等)则被Linux提炼出来,我们称为驱动框架。
linux虚拟网络设备之vlan配置
我们通过一个网桥两个设备对,来连接两个网络名字空间,每个名字空间中创建两个vlan
借助vconfig来配置vlan:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
查看一下vlan配置:
1 2 3 4 5 |
|
现在,我们可以分别在两个名字空间来ping另外一个名字空间的两个IP,虽然两个IP都能ping通,但是使用的源IP是不同的,走的vlan也是不同的,我们可以在veth01/veth10/veth02/veth20/br-test-vlan 任意一个上抓包,会看到vlan信息:
1 2 3 4 5 6 7 8 9 |
|
如果试图从veth10.3001 去ping 172.16.30.22 是不能通的,因为是不同的vlan呀:
1 2 3 4 5 |
|
不适用vconfig的解法:
1 |
|
另: vlan 一般以 设备名.vlanid 来命名,不过并非强制,如下命名为 vlan3003也是没问题的
1 |
|
注意:一个主设备上相同vlan好的子设备最多只能有一个
1 2 |
|
所以,正常来讲,一般是这样的:
更多推荐
所有评论(0)