ubuntu 实现三层交换机的VLAN功能

来源:互联网 发布:iphone导入视频到mac 编辑:程序博客网 时间:2024/06/05 11:18
本文来源:http://home.lupaworld.com/home.php?mod=space&uid=24775&do=blog&id=64389
一、首先,安装vlan支持软件包
#apt-get install vlan


二、加载 802.1q 模块
#modprobe 8021q


三、建立两个vlan,可以在一个网络 接口建立,以做单臂路由,也可以分开两个网络接口建立。
#vconfig add eth0 2
#vconfig add eth0 3 
在eth0上建立vlan2 和 vlan3 
或者
#vconfig add eth0 2
#vconfig add eth1 3
在eth0 上建立vlan2,在eth1 上建立vlan3


四、为网络端口设置IP
#ifconfig eth0 0.0.0.0 up
#ifconfig eth2.222 192.168.0.1 broadcast 192.168.0.255 netmask 255.255.255.0 up
#ifconfig eth0.3 192.168.1.1 broadcast 192.168.1.255 netmask 255.255.255.0 up
or
#ifconfig eth0 192.168.0.1 broadcast 192.168.0.255 netmask 255.255.255.0 up
#ifconfig eth1 192.168.1.1 broadcast 192.168.1.255 netmask 255.255.255.0 up
五、开启路由功能
#echo 1 > /proc/sys/net/ipv4/ip_forward
#vim /etc/sysctl.conf
#net.ipv4.conf.default.forwarding=1
#sysctl -p


六、 将交换机端口划分VLAN,再接入LINUX网络接口就OK了!


七、检查路由正确与否,没有自动生成的手动加上


#route add -net 192.168.0.0 netmask 255.255.255.0 gw eth0.2
#route add -net 192.168.1.0 netmask 255.255.255.0 gw eth0.3
or
#route add -net 192.168.0.0 netmask 255.255.255.0 gw eth0
#route add -net 192.168.1.0 netmask 255.255.255.0 gw eth1
OK!ALL THING IS ALL RIGHT!






 在eth0接口配置两个vlan  如果没有加载模块会自动加载8021q模块
1.添加vlan
vconfig add eth0 11
vconfig add eth0 21


2.设置参数 REORDER_HDR (默认就是)
vconfig set_flag eth0.11 1 1
vconfig set_flag eth0.21 1 1


2.查看一下
cat /proc/net/vlan/eth0.11
cat /proc/net/vlan/eth0.21




3.手工切换 这时需要更改交换机配置
ifdown eth0;ifup eth0;ifup eth0.11;ifup eth0.21
4.设置下次启动自动加载 8021q 模块
echo VLAN=yes >> /etc/sysconfig/network


5.删除VLAN
vconfig rem eth2.2


6.set_flag [VLAN的设备] 0 | 1
1时,以太网报头重新排序已打开。 转储设备将显示为一个没有共同的VLAN的以太网设备。 当0(默认),然而,以太网标题不重新排序,从而导致在VLAN标签的数据包时,倾倒装置。 通常的过失,没有问题,但一些包过滤程序可能有它的问题。
set_egress_map [VLAN的设备] [新光优先] [VLAN和QoS的] 这标志出站优先级数据包与一个特定的skb的,应当将与特定的VLAN优先权VLAN的服务质量。 缺省VLAN优先级为0。
set_ingress_map [VLAN的设备] [新光优先] [VLAN和QoS的] 这标志,QoS的入站数据包与特定的VLAN优先级排队的VLAN应该与特定的skb的优先级。 默认新光优先级为0。
set_name_type VLAN_PLUS_VID | VLAN_PLUS_VID_NO_PAD | DEV_PLUS_VID | DEV_PLUS_VID_NO_PAD 创建方式设置VLAN的设备名称。 不带参数使用vconfig的看到不同的格式。
7.
Expecting argc to be 3-5, inclusive.  Was: 1


Usage: add             [interface-name] [vlan_id]
       rem             [vlan-name]
       set_flag        [interface-name] [flag-num]       [0 | 1]
       set_egress_map  [vlan-name]      [skb_priority]   [vlan_qos]
       set_ingress_map [vlan-name]      [skb_priority]   [vlan_qos]
       set_name_type   [name-type]


* The [interface-name] is the name of the ethernet card that hosts
  the VLAN you are talking about.
* The vlan_id is the identifier (0-4095) of the VLAN you are operating on.
* skb_priority is the priority in the socket buffer (sk_buff).
* vlan_qos is the 3 bit priority in the VLAN header
* name-type:  VLAN_PLUS_VID (vlan0005), VLAN_PLUS_VID_NO_PAD (vlan5),
              DEV_PLUS_VID (eth0.0005), DEV_PLUS_VID_NO_PAD (eth0.5)
* FLAGS:  1 REORDER_HDR  When this is set, the VLAN device will move the
            ethernet header around to make it look exactly like a real
            ethernet device.  This may help programs such as DHCPd which
            read the raw ethernet packet and make assumptions about the
            location of bytes.  If you don't need it, don't turn it on, because
            there will be at least a small performan
其中,TCI是Tag Control Info的缩写,2字节。当设置为“8100”(hex)时,表明这一帧使用802.1p和802.1q标记;P是Priority,指示802.1p的优先级别(0~7),占用3位;C是Canonical Indicator,指示以太网格式是否规范,规范用0表示,否则用1表示,占用1位;VLAN是VLAN Identifier(VID),表明这一帧属于哪一个VLAN(0~4095),占用12位。它们加在一起共4个字节以上为一些Vconfig 的用用法,在linux 移植时,只要在LINUX config 时,在网络配置时,加载一下8021Q模块就OK了
0 0
原创粉丝点击