centos 配置vlan端口

centos 配置vlan端口

  • 安装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
    #IPADDR=60.10.118.19
    #NETMASK=255.255.255.240
    #GATEWAY=X.X.X.X

    说明:

    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命令控制。

猜你喜欢

转载自blog.51cto.com/mengyao/2116091