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

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

  6. Linux 创建网卡子接口

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

  7. 剥开比原看代码10:比原是如何通过/create-key接口创建密钥的

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

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

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

  9. [原]Jenkins(十一)---jenkins使用管理员admin创建用户和分配权限

    /** * lihaibo * 文章内容都是根据自己工作情况实践得出. * 版权声明:本博客欢迎转发,但请保留原作者信息! http://www.cnblogs.com/horizonli/p/533 ...

随机推荐

  1. java maven打包jar 方法参数名变var1,var2之类的无意义参数名怎么办

    这是idea 对.class反编译的结果.要想看完整源码,可以使用maven-source-plugin,在pom.xml里配置: <plugin> <groupId>org. ...

  2. 微软BI 之SSIS 系列 - 通过 OLE DB 连接访问 Excel 2013 以及对不同 Sheet 页的数据处理

    文章更新历史 2014年9月7日 - 加入了部分更新内容,在文章最后提到了关于不同 Office Excel 版本间的连接问题. 开篇介绍 这篇文章主要总结在 SSIS 中访问和处理 Excel 数据 ...

  3. windows性能监控

    see also:http://www.cnblogs.com/upDOoGIS/archive/2010/11/19/1881970.html CPU Processor : % Processor ...

  4. Android数据库大批量数据插入优化

    对比在android中批量插入数据的3中方式对比(各插入1W条数据所花费的时间): 1. 一个一个插入 public static boolean insert(SQLiteOpenHelper op ...

  5. 正则匹配报文中的XML(HTML)标签,替换重新输出

    调用返回报文标签中的存在中划线“-”,不符合规范,需要统一进行转换,但不能替换标签内的内容,利用正则匹配重新输出 /** * 正则匹配报文中的xml标签,将其中的"-"转换为&qu ...

  6. 【Windows】cmd条件判断

    1.判断驱动器.文件或文件夹是否存在,用 if exist 语句: 2.判断某两个字符串是否相等,用 if "字符串1"=="字符串2" 语句: 3.判断某两个 ...

  7. 【Vegas原创】查询SQL Server更改记录的语句

    指定数据库,然后: select Name,Create_date,Modify_Date from sys.objects where type in ('U','P', 'V','F', 'TR' ...

  8. request.GetResponse()超时的解决办法

    var request = (HttpWebRequest)WebRequest.Create(url); request.Timeout = Timeout.Infinite; request.Ke ...

  9. Vivado开发工具熟悉之工具使用杂记

    这两天基本完成了实验室工程从ISE向vivado的移植,包括了两片FPGA的两个工程,这两个工程还算是比较大的工程,包括了内存,接口,embedded system,算法模块等,在这过程中也很好的熟悉 ...

  10. vue项目使用webpack loader把px转换为rem

    下载lib-flexible https://github.com/amfe/lib-flexible npm i lib-flexible --save 在main.js中引入lib-flexibl ...