centos 配置vlan端口

centos 配置vlan端口

vconfig 在epel源中:

  • 安裝vlan(vconfig)和加載8021q模塊
    [root@test0001~]#yum install vconfig
    [root@test0001~]#modprobe 8021q
    [root@test0001~]#lsmod |grep -i 8021q

  • 在eth0接口上配置兩個VLAN
    [root@test0001~]#vconfig add eth0 100
    Added VLAN with VID == 100 to IF -:eth0:-
    [root@test0001~]#vconfig add eth0 200
    Added VLAN with VID == 200 to IF -:eth0:-

  • 設置VLAN的REORDER_HDR參數,默認就行了
    可以使用cat /proc/net/vlan/eth0.100查看eth0.100 參數
    [root@test0001~]#vconfig set_flag eth0.100 1 1
    Set flag on device -:eth0.100:- Should be visible in /proc/net/vlan/eth0.100
    [root@test0001~]#vconfig set_flag eth0.200 1 1
    Set flag on device -:eth0.200:- Should be visible in /proc/net/vlan/eth0.200

  • 配置網絡信息
    [root@test0001~]#ifconfig eth0 0.0.0.0
    [root@test0001~]#ifconfig eth0.100 172.16.1.8 netmask 255.255.255.0 up
    [root@test0001~]#ifconfig eth0.200 172.16.2.8 netmask 255.255.255.0 up

  • 刪除VLAN命令
    [root@test0001~]#vconfig rem eth0.100
    Removed VLAN -:eth0.100:-
    [root@test0001~]#vconfig rem eth0.200
    Removed VLAN -:eth0.200:-

#將VLAN信息寫入配置文件(/etc/rc.local)中,下次隨機啓動。
#也可以寫入vlan接口的配置文件,指定要橋接的邏輯網橋
例如:

  • #cat ifcfg-em2.12
    DEVICE=em2.12 
    TYPE=ethernet
    BOOTPROTO=static
    ONBOOT=yes 
    VLAN=yes 
    BRIDGE=br12 

  • #cat /etc/sysconfig/network-scripts/ifcfg-br12
    DEVICE=br12
    TYPE=bridge
    BOOTPROTO=static
    ONBOOT=yes

說明:這裏生成vlan接口只爲解決單網卡物理機,創建三網卡虛擬機之目的 (vlan接口 ----- 橋接到對應的br# 下, -----kvm虛擬機生成時指定橋接到不通的虛擬網橋)

POST--->ramfs---->內核--->/etc/inittab--->/etc/rc.d/rc.sysinit--->/etc/rc.d/rc#.d
linux啓動時,先加載內核,然後加載inittab文件,inittab文件中有個條目si::sysinit:/etc/rc.d/rc.sysinit指定了下一個要加載的文件rc.sysinit,這個文件加載完之後,加載/etc/rc.d/rc.RUNLEVEL.d目錄中的啓動腳本,最載/etc/rc.d/rc.local文件。
在rc.RUNLEVEL.d文件夾裏,所存的都是軟鏈接,鏈接到 /etc/rc.d/init.d中的腳本文件,而/etc/rc.d/init.d文件夾和/etc/init.d文件夾是一樣的,/etc/init.d其實是軟鏈接到/etc/rc.d/init.d文件夾中。
假設你有一個腳本,你需要它開機啓動,有2個方法,
第一,就是把它註冊爲系統服務,也就是把它放到/etc/init.d目錄下,並且在腳本中,加一行# chkconfig: 345 85 35,然後就可以用chkconfig命令讓其開機啓動。因爲在/etc/init.d目錄下,所以也可以用service命令控制該腳本。
第二,就是在/etc/rc.d/rc.local文件中,直接把該腳本的路徑寫進去,在開機加載rc.local文件的時候,自然會啓動這個腳本。這個腳本就不能用chkconfig和service命令控制。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章