1. 程式人生 > >linux VLAN劃分與配置

linux VLAN劃分與配置

linux vlan劃分與配置

什麽是 VLAN ?

VLAN ( Virtual Local Area Network )又稱虛擬局域網,是指在交換局域網的基礎上,采用網絡管理軟件構建的可跨越不同網段、不同網絡的端到端的邏輯網絡。一個 VLAN 組成 一個邏輯子網, 即一個邏輯廣播域,它可以覆蓋多個網絡設備,允許處於不同地理位置的網 絡用戶加入到一個邏輯子網中。

使用 VLAN 優點?

1 、控制廣播風暴

一個 VLAN 就是一個邏輯廣播域,通過對VLAN的創建,隔離了廣播,縮小了廣播範圍,可以控制廣播風暴的產生。

2 、提高網絡整體安全性

通過路由訪問列表和 MAC 地址分配等VLAN劃分原則,可以控制用戶訪問權限和邏輯網段大小,將不同用戶群劃分在不同VLAN從而提高交換式網絡的整體性能和安全性。

3 、網絡管理簡單、直觀

對於交換式以太網, 如果對某些用戶重新進行網段分配, 需要網絡管理員對網絡系統的 物理結構重新進行調整,甚至需要追加網絡設備,增大網絡管理的工作量。而對於采用VLAN 技術的網絡來說,一個 VLAN 可以根據部門職能、對象組或者應用將不同地理位置的網絡用 戶劃分為一個邏輯網段。在不改動網絡物理連接的情況下可以任意地將工作站在工作組或子 網之間移動。利用虛擬網絡技術,大大減輕了網絡管理和維護工作的負擔,降低了網絡維護 費用。在一個交換網絡中,VLAN 提供了網段和機構的彈性組合機制

物理網卡、子網卡、虛擬 VLAN 網卡的關系:

1. 物理網卡:服務器上物理網絡接口設備,也就是要配置 trunk 的具體接口。

2. 子網卡:子網卡並不是網絡接口設備,但是可以作為網絡接口在系統中出現,如 eth0:1 、 eth1:2 這種網絡接口。必須要依賴於物理網卡,可以與物理網卡同時在系統中存 在並使用不同的 IP 地址,而且也擁有它們自己的網絡接口配置文件。但是所依賴的物理網 卡 down 掉時子網卡也不能工作。

3. 虛擬 VLAN 網卡:虛擬 VLAN 網卡也不是物理網絡接口設備,可以作為網絡接口在系統 中出現,與子網卡不同的是,沒有自己的配置文件。是通過將物理網加入不同的 VLAN 而生 成的 VLAN 虛擬網卡。如果將一個物理網卡添加到多個 VLAN 當中去的話,就會有多個 VLAN 虛擬網卡出現,相關的 VLAN 信息都是保存在/proc/net/vlan/config 這文件中的, 以 eth0.1、eth1.2 命名

[[email protected] ~]#modinfo 8021q // 查看是否有 vlan 模塊

[[email protected] ~]#modprobe 8021q //沒有添加

[[email protected] ~]# vconfig add eth0 10

Added VLAN with VID == 10 to IF -:eth0:-

[[email protected] ~]# vconfig add eth0 20

Added VLAN with VID == 20 to IF -:eth0:-

在eth0接口上配置兩個VLAN

[[email protected] ~]# vconfig set_flag eth0.10 1 1

[[email protected] ~]# vconfig set_flag eth0.20 1 1

設置VLAN的REORDER_HDR參數,默認就行了。
可以使用cat /proc/net/vlan/eth0.10查看eth0.10參數

[[email protected] ~]# cat /proc/net/vlan/eth0.10

eth0.10 VID: 10 REORDER_HDR: 1 dev->priv_flags: 81

total frames received 1

total bytes received 68

Broadcast/Multicast Rcvd 1

total frames transmitted 3

total bytes transmitted 270

total headroom inc 0

total encap on xmit 3

Device: eth0

INGRESS priority mappings: 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0


EGRESSS priority Mappings:

[[email protected] ~]# ifconfig eth0 0.0.0.0

[[email protected] ~]# ifconfig eth0.10 192.168.10.10 netmask 255.255.255.0 up

[[email protected] ~]# ifconfig eth0.20 192.168.20.10 netmask 255.255.255.0 up

eth0.10 Link encap:Ethernet HWaddr 00:0C:29:27:D6:74

inet addr:192.168.10.10 Bcast:192.168.10.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fe27:d674/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:1 errors:0 dropped:0 overruns:0 frame:0

TX packets:3 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:68 (68.0 b) TX bytes:270 (270.0 b)

eth0.20 Link encap:Ethernet HWaddr 00:0C:29:27:D6:74

inet addr:192.168.20.10 Bcast:192.168.20.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fe27:d674/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:1 errors:0 dropped:0 overruns:0 frame:0

TX packets:2 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:68 (68.0 b) TX bytes:176 (176.0 b)

[[email protected] ~]# brctl addbr br0 //創建一個網橋

[[email protected] ~]# brctl addif br0 eth0.10 //把vlan eth0.10加到網橋上

[[email protected] ~]# brctl addif br0 eth0.20 //把vlan eth0.20加到網橋上

[[email protected] ~]# brctl show

bridge name bridge id STP enabled interfaces

br0 8000.000c29f59487 no eth0.10

eth0.20

#############################################

如果想改eth0.10網卡名稱,可以這樣,

[[email protected] ~]#ifconfig eth0.10 down

[[email protected] ~]#ip link set eth0.10 name eth10

[[email protected] ~]#ifconfig eth10 up

[[email protected] ~]#ifconfig

就可以看到eth10的網卡了 。

#############################################

[[email protected] ~]# vconfig rem eth0.10 //刪除vlan

Removed VLAN -:eth0.10:-

[[email protected] ~]# vconfig rem eth0.20

Removed VLAN -:eth0.20:-

[[email protected] ~]# ifconfig br0 down

[[email protected] ~]# brctl delbr br0 //刪除網橋

參考文章:http://blog.chinaunix.net/uid-22166872-id-4311344.html


本文出自 “Linux_woniu” 博客,請務必保留此出處http://llu1314.blog.51cto.com/5925801/1965304

linux VLAN劃分與配置