OS:CentOS 7
在linux上创建vlan需要加载802.1q模块:
1.检测OS是否已经加载802.1q模块
  

[root@controller ~]# modinfo 8021q
filename: /lib/modules/3.10.0-229.14.1.el7.x86_64/kernel/net/8021q/8021q.ko
version: 1.8
license: GPL
alias: rtnl-link-vlan
rhelversion: 7.1
srcversion: 2C3C3989B54002FAEC13FFD
depends: mrp,garp
intree: Y
vermagic: 3.10.0-229.14.1.el7.x86_64 SMP mod_unload modversions
signer: CentOS Linux kernel signing key
sig_key: E9:9F:C4:37:BD:9C:BF:B4:F1:B1:DA:87:C1:57:FF:66:56:9B:EE:66
sig_hashalgo: sha256 或者: [root@controller ~]# modinfo -F filename 8021q

/lib/modules/3.10.0-229.14.1.el7.x86_64/kernel/net/8021q/8021q.ko

或者:

  

[root@controller ~]# modprobe --first-time 8021q
modprobe: ERROR: could not insert '8021q': Module already in kernel

2.如果没有加载802.1q模块怎么加载? 

##加载8021q模块
[root@controller ~]# modprobe 8021q
##查看是否正常加载

  [root@controller ~]# lsmod |grep 8021q
  8021q 28808 0
  garp 14384 1 8021q
  mrp 18542 1 8021q

3.在父接口创建vlan子接口

  3.1在父接口/etc/sysconfig/network-scripts/ifcfg-ethX  中设置 

DEVICE=ethX
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes

  3.2复制父接口并修改接口名称 

cp /etc/sysconfig/network-scripts/ifcfg-ethX /etc/sysconfig/network-scripts/ifcfg-ethX.125     ## X后面的125为vlan号

  3.3配置/etc/sysconfig/network-scripts/ifcfg-ethX.125

DEVICE=ethX.192
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.1.1
PREFIX=24
NETWORK=192.168.1.0
VLAN=yes ##开启vlan,表明此子接口为vlan接口

 4.重启网络

systemctl restart network

  

================================================
CONFIGURE 802.1Q VLAN TAGGING USING THE COMMAND LINE
In Red Hat Enterprise Linux 7, the 8021q module is loaded by default. If necessary, you can make sure that the module is loaded by issuing the following command as root:

~]# modprobe --first-time 8021q
modprobe: ERROR: could not insert '8021q': Module already in kernel

To display information about the module, issue the following command:

~]$ modinfo 8021q

See the modprobe(8) man page for more command options.

7.4.1. Setting Up 802.1Q VLAN Tagging Using ifcfg Files

  1. Configure the parent interface in /etc/sysconfig/network-scripts/ifcfg-ethX, whereX is a unique number corresponding to a specific interface, as follows:
    DEVICE=ethX
    TYPE=Ethernet
    BOOTPROTO=none
    ONBOOT=yes
  2. Configure the VLAN interface configuration in the /etc/sysconfig/network-scripts/directory. The configuration file name should be the parent interface plus a . character plus the VLAN ID number. For example, if the VLAN ID is 192, and the parent interface is eth0, then the configuration file name should be ifcfg-eth0.192:
    DEVICE=ethX.192
    BOOTPROTO=none
    ONBOOT=yes
    IPADDR=192.168.1.1
    PREFIX=24
    NETWORK=192.168.1.0
    VLAN=yes
    If there is a need to configure a second VLAN, with for example, VLAN ID 193, on the same interface, eth0, add a new file with the name eth0.193 with the VLAN configuration details.
  3. Restart the networking service in order for the changes to take effect. As root issue the following command:
    ~]# systemctl restart network

7.4.2. Configure 802.1Q VLAN Tagging Using ip Commands

To create an 802.1Q VLAN interface on Ethernet interface eth0, with name VLAN8 and ID 8, issue a command as root as follows:

~]# ip link add link eth0 name eth0.8 type vlan id 8

To view the VLAN, issue the following command:

~]$ ip -d link show eth0.8
4: eth0.8@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
link/ether 52:54:00:ce:5f:6c brd ff:ff:ff:ff:ff:ff promiscuity 0
vlan protocol 802.1Q id 8 <REORDER_HDR>
Note that the ip utility interprets the VLAN ID as a hexadecimal value if it is preceded by 0x and as an octal value if it has a leading 0. This means that in order to assign a VLAN ID with a decimal value of 22, you must not add any leading zeros.
To remove the VLAN, issue a command as root as follows:

~]# ip link delete eth0.8
================
总结:修改父接口的BOOTPROTO=manual
复制父接口,
清空内容
注入下面的内容:

DEVICE=${SECONF_ETH}.${EXTERNAL_TENANT_NETWORK_VLAN_ID}
BOOTPROTO=none
ONBOOT=yes
IPADDR=${SECOND_SUB_INTERFACE_IP}
PREFIX=24
NETWORK=${SECOND_SUB_INTERFACE_NET}
VLAN=yes

CentOS 7 网卡子接口的创建的更多相关文章

  1. [原]CentOS 7 网卡子接口的创建

    OS:CentOS 7 在linux上创建vlan需要加载802.1q模块: 1.检测OS是否已经加载802.1q模块 [root@controller ~]# modinfo 8021q filen ...

  2. Centos配置网卡子接口

    1.检查OS是否加载802.1q模块: 方法一: [root@rs2 ~]# modinfo 8021q 方法二: [root@rs2 ~]# modinfo -F filename 8021q 方法 ...

  3. centos 7 增加网卡子接口配置

    centos 7 增加网卡子接口配置 http://www.mamicode.com/info-detail-1351950.html

  4. CentOS、Ubuntu配置网卡子接口

    CentOS # ip addr add dev eth0 lable eth0: 以上为临时配置,重启失效.若需永久保存,增加网络配置文件 # vim /etc/sysconfig/network- ...

  5. Linux 创建网卡子接口

    创建网卡子接口,添加IP别名 ifconfig eth0:0  2.2.2.2/24 或 ip addr add 2.2.2.2/24 dev eth0 label eth0:0 清除网卡子接口,删除 ...

  6. java 访问 太平洋网ip接口,解决前端js 跨域访问失败问题

    前端 js访问太平洋网IP接口地址,返回结果是403 服务器拒绝处理异常, 于是,想到了使用 服务器端访问,然后再将查询结果返回的前端 这是Java的测试源码,[具体的contronller端源码懒得 ...

  7. 剥开比原看代码11:比原是如何通过接口/create-account创建帐户的

    作者:freewind 比原项目仓库: Github地址:https://github.com/Bytom/bytom Gitee地址:https://gitee.com/BytomBlockchai ...

  8. json-lib-2.4-jdk15.jar所需全部JAR包.rar java jsoup解析开彩网api接口json数据实例

    json-lib-2.4-jdk15.jar所需全部JAR包.rar  java jsoup解析开彩网api接口json数据实例 json-lib-2.4-jdk15.jar所需全部JAR包.rar  ...

  9. 从CentOS官网下载系统镜像详细教程

      很多新手小白鼠想学习CentOS系统,但是不知道镜像去哪里搞,随便去个第三方发现要么要注册,要么各种广告病毒,或者好不容易找到官网,点进去一看却一脸懵逼,不仅全英文,有些专业术语也不懂啊,不要担心 ...

随机推荐

  1. SQL vs NoSQL 没有硝烟的战争!

    声明:本文译自SQL vs NoSQL The Differences,如需转载请注明出处. SQL(结构化查询语言)数据库作为一个主要的数据存储机制已经超过40个年头了.随着web应用和像MySQL ...

  2. C++静态库和动态库的区别

    转自http://www.cnblogs.com/skynet/p/3372855.html 什么是库? 库是写好的现有的,成熟的,可以复用的代码.现实中每个程序都要依赖很多基础的底层库,不可能每个人 ...

  3. jmeter使用IP欺骗进行压力测试

    loadrunner的IP欺骗功能很强大,耐心研究jmeter官方文档,发现在jmeter2.5以上的版本有此功能的实现~ 准备工作: 1.window7一台,安装jdk1.6环境.   2.下载最新 ...

  4. JQuery读取XML文件

    <?xml version="1.0" encoding="utf-8" ?> <taxrates> <taxrate id=&q ...

  5. Koala – 开源的前端预处理器语言图形编译工具

    koala 是一个前端预处理器语言图形编译工具,支持 Less.Sass.Compass.CoffeeScript,帮助 Web 开发者更高效地使用它们进行开发.跨平台运行,完美兼容 Windows. ...

  6. 在你设计中可能用到的20个杂志 PSD 原型

    你是否正在为您的印刷产品找一些现成的原型素材?在这里,我们收集了一组免费的杂志 PSD 素材,必将派上用场.这些原型将给你和你的客户一个先睹为快的产品,在现实生活中看起来如何.所有这些原型提供了可以免 ...

  7. webkit中获取用户选择文本和编程设定选择文本

    一.需求背景 在 Android 应用中,内嵌一个 WebView,希望捕获用户点击事件,通过 javascript 判断用户点击的是否英文单词,如果是则将被点击单词发给应用做进一步处理,并实用 ja ...

  8. C语言 指针例解

    在计算机科学中,指针(Pointer)是编程语言中的一个对象,利用地址,它的值直接指向(points to)存在电脑存储器中另一个地方的值.由于通过地址能找到所需的变量单元,可以说,地址指向该变量单元 ...

  9. 8款超实用JavaScript框架

    下面盘点了8款实用的JavaScript框架: 1. Hammer.js Hammer.js是被广泛使用的轻量级JavaScript框架,它提供了常用触摸操作的规范,比如收缩.拖放.双击和删除等等.它 ...

  10. SPS中使用JSOM发邮件

    直接上代码了: function ShowMailDialog() { $.ajax({ url: siteurl + "/_api/contextinfo", method: & ...