How to create vlan on Linux (with Cisco Catalyst Switch)
In this article I want to share to you on how to create and configure vlan on Linux through Cisco Catalyst Switch.
Requirements:
1. Linux installed on a PC with one or more NICs (Network Interface Card). I use Centos 5.4 using 2.6.18-164.11.1.el5PAE kernel. It should be applicable on other Linux distros such as Slackware, Ubuntu, Fedora, Debian, etc.
2. Cisco Catalyst Switch 2950
3. 2 PC/Laptop running Windows/Linux/BSD/MacOSX
4. 3 straight cables
This tutorial is based-on network diagram below:

Here are the full steps.
1. Load 802.1q module into the system
By default the 802.1q module is not loaded so we firstly have to load it. You can check whether it is already loaded or not by using ‘lsmod’ command.
lsmod |grep 802
If there is nothing shown by lsmod command, it means the module has not been loaded yet. Run ‘modprobe’ to load it.
modprobe 8021q
Make sure the module was successfully loaded by running the ‘lsmod’ again
lsmod |grep 802
8021q 24649 0
If you see something similar like above, the 8021q has been successfully loaded.
2. Create vlan interface
We will use eth1 interface in the Linux box. We have to bring the interface up without IP address assigned to it before we can use it.
ifconfig eth1 0.0.0.0 up
We will create interface vlan 11 and vlan 12 on this eth1 interface. To create a vlan interface, use ‘vconfig add’ command as below:
vconfig add eth1 11
Added VLAN with VID == 11 to IF -:eth1:- vconfig add eth1 12
Added VLAN with VID == 12 to IF -:eth1:-
These commands above will create devices eth1.11 and eth1.12 to your system. Linux will consider these as another network devices so you can configure and assign IP address like other.
You also see the vlan interfaces by typing ‘ifconfig -a’ command.
ifconfig -a eth1.11 Link encap:Ethernet HWaddr 00:30:48:BF:4E:BD
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) eth1.12 Link encap:Ethernet HWaddr 00:30:48:BF:4E:BD
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
3. Assign IP address to the vlan interfaces
The vlan interfaces were successfully created on the previous step. Now we assign IP address on those interfaces using ifconfig command as below:
ifconfig eth1.11 192.168.11.254 netmask 255.255.255.0 up
ifconfig eth1.12 192.168.12.254 netmask 255.255.255.0 up
Make sure that the IP addresses were assigned successfully on the interfaces.
ifconfig eth1.11
eth1.11 Link encap:Ethernet HWaddr 00:30:48:BF:4E:BD
inet addr:192.168.11.254 Bcast:192.168.11.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) ifconfig eth1.12
eth1.12 Link encap:Ethernet HWaddr 00:30:48:BF:4E:BD
inet addr:192.168.12.254 Bcast:192.168.12.255 Mask:255.255.255.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Until this step, creating and configuring vlans have been done on the Linux box. Now we are going to configure vlan and trunk on the Cisco Catalyst switch.
4. Configure cisco catalyst switch, add vlan database, configure interface access vlan and trunk
As said before, we use vlan 11 and vlan 12 on this tutorial. So those vlan must be added into the vlan database of the switch.
switch#conf terminal
Enter configuration commands, one per line. End with CNTL/Z.
switch(config)#vlan 11
switch(config-vlan)#name test-vlan11
switch(config-vlan)#exit
switch(config)#vlan 12
switch(config-vlan)#name test-vlan12
switch(config-vlan)#exit
switch(config)#exit
switch#wr mem
Building configuration...
[OK] switch#show vlan | include test-vlan
11 test-vlan11 active
12 test-vlan12 active
Vlan 11 and 12 have been successfully added to the database and active.
Now we have to configure 3 ports in the cisco catalyst switch. 1 port is for trunk between the switch and Linux box and 2 ports are for PC-A and PC-B.
We will use port Fa0/16 as trunk port and Fa0/14 and Fa0/15 as vlan access port connected to PC-A and PC-B respectively. Below are the commands:
switch#conf terminal
Enter configuration commands, one per line. End with CNTL/Z.
switch(config)#int f0/14
switch(config-if)#description To_PC-A
switch(config-if)#swi acc vlan 11
switch(config-if)#no shutdown
switch(config-if)#exit
switch(config)#int f0/15
switch(config-if)#description To_PC-B
switch(config-if)#swi acc vlan 12
switch(config-if)#no shutdown
switch(config-if)#exit
switch(config)#int f0/16
switch(config-if)#description Trunk_To_Linux_Router
switch(config-if)#switchport trunk allowed vlan 11,12
switch(config-if)#switchport mode trunk
switch(config-if)#no shutdown
switch(config-if)#exit
switch(config)#exit
switch#wr mem
Building configuration...
[OK]
switch# switch#show running-config interface f0/14
Building configuration... Current configuration : 82 bytes
!
interface FastEthernet0/14
description To_PC-A
switchport access vlan 11
end switch#show running-config interface f0/15
Building configuration... Current configuration : 82 bytes
!
interface FastEthernet0/15
description To_PC-B
switchport access vlan 12
end switch#show running-config interface f0/16
Building configuration... Current configuration : 129 bytes
!
interface FastEthernet0/16
description Trunk_To_Linux_Router
switchport trunk allowed vlan 11,12
switchport mode trunk
end switch#
The configurations on both Linux box and Switch have completed.
Now it is the time to test whether PC-A and PC-B can ping to the same network on the Linux box. Make sure the cables are connected properly to each ports on the devices.
5. Test ping to Linux box using vlan ip address
Test from PC-A:
C:\Users\Fuad NAHDI>ping 192.168.11.254 Pinging 192.168.11.254 with 32 bytes of data:
Reply from 192.168.11.254: bytes=32 time=1ms TTL=64
Reply from 192.168.11.254: bytes=32 time
Test from PC-B:
C:\Users\Fuad NAHDI>ping 192.168.12.254 Pinging 192.168.12.254 with 32 bytes of data:
Reply from 192.168.12.254: bytes=32 time=2ms TTL=64
Reply from 192.168.12.254: bytes=32 time
6. Make everything active at boot
Everything we have done above is temporary configuration, meaning that it will be cleared from configuration when we reboot or shutdown the linux box.
To make it permanent or active at boot, simply add the following lines into the rc.local file (e.g Centos: /etc/rc.local ; Slackware: /etc/rc.d/rc.local):
modprobe 8021q
ifconfig eth1 0.0.0.0 up
vconfig add eth1 11
vconfig add eth1 12
ifconfig eth1.11 192.168.11.254 netmask 255.255.255.0 up
ifconfig eth1.12 192.168.12.254 netmask 255.255.255.0 up 转自:http://www.techonia.com/1227/create-vlan-on-linux-with-cisco-catalyst-switch
How to create vlan on Linux (with Cisco Catalyst Switch)的更多相关文章
- vlan 以及 Linux实现的IEEE 802.1Q VLAN
vlan 以及 Linux实现的IEEE 802.1Q VLAN Vlan的概念 VLAN技术介绍 VLANVLAN概述 以太网是一种基于CSMA/CD(Carrier Sense Multiple ...
- Cisco Catalyst 9800-CL Wireless Controller for Cloud
面向云的思科 Catalyst 9800-CL 无线控制器,专为基于意图的网络全新打造. 版本: C9800-CL-universalk9.17.04.01 (29-Nov-2020) C9800-C ...
- Linux和Cisco命令行通用快捷键。
Ctrl a e 行首,行尾(ahead,end)Esc f b 单词首,单词尾Ctrl f b 移动光标(forward,backwards) Ctrl u k 剪切光标前所有,剪切光标后所有Ctr ...
- 重新定位svn地址的方法(windows和linux),svn switch(sw)的帮助信息
今天公司的路由器出现问题,服务器的IP地址也跟着变了,但是原来的svn已经设置好了,现在需要更换地址 查询原地址的方法: root@jack-desktop:codes# svn info 路径: . ...
- Brocade,Cisco SAN Switch命令对比
- Linux下svn命令switch用法
# svn info /data/www/49you/api.49you.com Path: /data/www/49you/api.49you.comURL: svn://192.168.10.81 ...
- 在Cisco Catalyst 3750端口做策略限速 QOS
今天任务是在3750上限制端口的速率,本来以为是很简单的事,speed命令搞定,敲进去才知道speed命令只能叫端口速率改成10M或100M,也就是说只能起到端口高低速率的切换功能,不能自定义速率,后 ...
- Linux实现的IEEE 802.q VLAN
本文转载自: http://blog.chinaunix.net/uid-20786208-id-4291059.html Technorati 标签: Linux VLAN ---------- ...
- Cisco配置VLAN+DHCP中继代理+NAT转发上网
实验环境: 路由器 使得TP-link 设置NAT转发使用,tp-link路由器网关设置成 192.168.30.254 (核心层)Cisco 3550三层交换机(型号C3550-I5Q3L2-M)配 ...
随机推荐
- 搭建一个Mongodb (Windows) 版本
因为有项目需要借助nosql 做一个中间层,所以选择了Mongodb 来搞,其实之前呢已经搭建过这部分的环境,这次再次搭建也是记录一下,当时给自己的一个扫盲123教程 借助Mongodb 其实也是缓存 ...
- 安装Ubuntu的那些事儿(续)
由于我的第一篇Blog并没有给出完全解决进Ubuntu系统时显卡所造成的问题,至于那个装显卡驱动的方法本人也没有去做,感兴趣的朋友可以在网上教程试一试. 至于我的那个在高系选项中进行配置也不是好的方法 ...
- Java读写文本文件操作
package com.test; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; ...
- Centos7中systemctl命令详解
Linux Systemctl是一个系统管理守护进程.工具和库的集合,用于取代System V.service和chkconfig命令,初始进程主要负责控制systemd系统和服务管理器.通过Syst ...
- java请求https地址如何绕过证书验证?
原文http://www.blogjava.net/hector/archive/2012/10/23/390073.html 第一种方法,适用于httpclient4.X 里边有get和post两种 ...
- Linux下5种IO模型的小结
概述 接触网络编程,我们时常会与各种与IO相关的概念打交道:同步(Synchronous).异步(ASynchronous).阻塞(blocking)和非阻塞(non-blocking).关于概念的区 ...
- 如何使用 Entity Framework 构造动态查询表达式
一般的程序员做上几年以后, 或多或少的都有些代码的积累, 我也不例外. 作为微软技术程序员, 自从Linq和EF出来之后, 就基本上爱不释手了, 且不说执行效率的问题, 单单就开发效率和代码的可移植性 ...
- Excel自文本导入内容时如何做到单元格内换行
前言:今天在处理数据的时候,在数据库中用到了\n换行符号,目的是在同表格内做到数据多行显示,比如 字段名1 字段名2 字段名3 1 数据一行 数据二行 数据三行 例子是在sql查询后的结果 ...
- MMORPG大型游戏设计与开发(服务器 游戏场景 地图和区域)
地图的数据以及区域的信息是场景的重要组成部分,这些数据同时存在客户端和服务器,而且都是由编辑器生成的.那么保存的文件数据结构是怎样的?一张3D的场景地图又是怎样处理这些数据的?同时告诉大家这里同样只是 ...
- 我觉得有意思的JavaScript题目(01-05更新中)
对于以下js题目均来至于网络中.有的来至于文章之中,有的也许来至于问答题型中.如果您有更好的问题解释,请留言交流! 1.相关问题描述:到底该怎么去理解闭包? 代码片段A !function(){ va ...