http://minitoo.blog.51cto.com/4201040/786011(转载)

在路由器上做单臂路由实现VLAN间路由,也就是设置子接口和封装协议。

实现环境如下图:

  1. 在交换机上建立VLAN,并将交换机的各端口按部门划分到各VLAN。

Switch>enable

Switch#config terminal

Switch(config)#vlan 2

Switch(config-vlan)#name shengchan

Switch(config-vlan)#exit

Switch(config)#vlan 3

Switch(config-vlan)#name xiaoshou

Switch(config-vlan)#exit

Switch(config)#vlan 4

Switch(config-vlan)#name xingzheng

Switch(config-vlan)#exit

Switch(config)#interface fastethernet 0/1

Switch(config-if)#switchport mode access

Switch(config-if)#switchport access vlan 2

Switch(config-if)#exit

Switch(config)#interface fastethernet 0/2

Switch(config-if)#switchport mode access

Switch(config-if)#switchport access vlan 3

Switch(config-if)#exit

Switch(config)#interface fastethernet 0/3

Switch(config-if)#switchport mode access

Switch(config-if)#switchport access vlan 4

Switch(config-if)#exit

  1. 在交换机连接路由器的接口上配置TRUNK,并使TRUNK传输所有的VLAN的数据包。

Switch(config)#interface fastethernet 0/4

Switch(config-if)#switchport mode trunk

Switch(config-if)#switchport trunk allow vlan all

Switch(config-if)#exit

  1. 在路由器连接交换机的端口上去掉IP地址,使之成为二层接口。

Router>enable

Router#config terminal

Router(config)#interface fastethernet 0/0

Router(config-if)#no ip address

Router(config-if)#exit

  1. 在路由器上开启连接交换机的端口(no shtudwon),设置子接口IP地址,此IP地址将自动成为各VLAN的网关。

Router(config)#interface fastethernet 0/0

Router(config-if)#no shutdown

Router(config)#interface fastethernet 0/0.2

Router(config-subif)#encapsulation dot1Q 2

Router(config-subif)#ip address 192.168.2.1 255.255.255.0

Router(config-subif)#no shutdown

Router(config-subif)#exit

Router(config)#interface fastethernet 0/0.3

Router(config-subif)#encapsulation dot1q 3

Router(config-subif)#ip address 192.168.3.1 255.255.255.0

Router(config-subif)#no shutdown

Router(config-subif)#exit

Router(config)#interface fastethernet 0/0.4

Router(config-subif)#encapsulation dot1Q 4

Router(config-subif)#ip address 192.168.4.1 255.255.255.0

Router(config-subif)#no shutdown

Router(config-subif)#exit

OK,配置完成,现在可以在VLAN2上ping一下VLAN3、VLAN4,测试连通性。

PC>ipconfig /all

Physical Address................: 0001.9751.4CB5

IP Address......................: 192.168.2.2

Subnet Mask.....................: 255.255.255.0

Default Gateway.................: 192.168.2.1

DNS Servers.....................: 0.0.0.0

PC>ping 192.168.3.2

Pinging 192.168.3.2 with 32 bytes of data:

Reply from 192.168.3.2: bytes=32 time=13ms TTL=127

Reply from 192.168.3.2: bytes=32 time=18ms TTL=127

Reply from 192.168.3.2: bytes=32 time=8ms TTL=127

Reply from 192.168.3.2: bytes=32 time=15ms TTL=127

Ping statistics for 192.168.3.2:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 8ms, Maximum = 18ms, Average = 13ms

PC>ping 192.168.4.2

Pinging 192.168.4.2 with 32 bytes of data:

Reply from 192.168.4.2: bytes=32 time=11ms TTL=127

Reply from 192.168.4.2: bytes=32 time=15ms TTL=127

Reply from 192.168.4.2: bytes=32 time=16ms TTL=127

Reply from 192.168.4.2: bytes=32 time=18ms TTL=127

Ping statistics for 192.168.4.2:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 11ms, Maximum = 18ms, Average = 15ms

建立简单的VLAN通信的更多相关文章

  1. Linux下简单的socket通信实例

    Linux下简单的socket通信实例 If you spend too much time thinking about a thing, you’ll never get it done. —Br ...

  2. 跨Vlan通信:单臂路由,三层交换机

    实验涉及命令以及知识补充(涉及Vlan通过的以太网口需要设置为Trunk口) 单臂路由 父接口 no ip address :删除实现单臂路由接口的IP no shutdown 虚拟子接口 R2(co ...

  3. php简单实现socket通信

    socket通信的原理在这里就不说了,它的用途还是比较广泛的,我们可以使用socket来做一个API接口出来,也可以使用socket来实现两个程序之间的通信,我们来研究一下在php里面如何实现sock ...

  4. C#--简单的串口通信程序

    前几天做毕业设计,其中要用到串口和下位机进行通信,于是自己捣鼓了一个简单的串口通信程序. 在做通信之前要先弄一个SerialPort组件出来,当然也可以通过程序来创建.本次设计中采用的是拖的winfo ...

  5. php建立简单的用户留言系统

    php建立简单的用户留言系统 样例 addMsg.php--添加留言页面 doAction.php--响应添加留言页面 . viewMsg.php--显示留言页面 目录结构 addMsg.php--添 ...

  6. C#实现简单的串口通信

    前言 本着学习研究的态度,用c#语言实现简单的串口通信工具. 一.串口通信原理 串口通信 串口通信(Serial Communications)的概念非常简单,串口按位(bit)发送和接收字节.尽管比 ...

  7. Android简单实现Socket通信,client连接server后,server向client发送文字数据

    案例实现的是简单的Socket通信,当client(Androidclient)连接到指定server以后,server向client发送一句话文字信息(你能够拓展其他的了) 先看一下服务端程序的实现 ...

  8. Trunk 实现跨交换机 VLAN 通信

    当网络中有多台交换机时,位于不同交换机上的相同VLAN的主机之间时如何通信的呢?我们使用Trunk实现跨交换机VLAN通信.还有以太网通道的操作哦. 实验拓扑 两台交换机直连,每台下面再连接两台VPC ...

  9. 在不同网段使用 VLAN 通信 - SVI,单臂路由

    在 VLAN 这篇文章中知道,设置 VLAN 目的是隔离大型的广播域,将其分成很小的广播域,从而更好的管理.但也就带来了一些问题:如流量不能在不同的 VLAN 间通信. 而为了解决这个问题,可以采用如 ...

随机推荐

  1. lintcode 中等题:Divide Two Integers 两个数的除法

    题目 两个整数相除 将两个整数相除,要求不使用乘法.除法和 mod 运算符. 如果溢出,返回 2147483647 . 样例 给定被除数 = 100 ,除数 = 9,返回 11 解题  15%的通过率 ...

  2. 欧拉工程第66题:Diophantine equation

    题目链接 脑补知识:佩尔方差 上面说的貌似很明白,最小的i,对应最小的解 然而我理解成,一个循环的解了,然后就是搞不对,后来,仔细看+手工推导发现了问题.i从0开始变量,知道第一个满足等式的解就是最小 ...

  3. eclipse配置jdk问题

    1.JDK安装成功,eclipse也安装成功,这时候实际上是可以不配置JDK,因为系统已经默认给你配置好了,

  4. C++:类模板与模板类

    6.3 类模板和模板类 所谓类模板,实际上是建立一个通用类,其数据成员.成员函数的返回值类型和形参类型不具体指定,用一个虚拟的类型来代表.使用类模板定义对象时,系统会实参的类型来取代类模板中虚拟类型从 ...

  5. 【Spring】如何在单个Boot应用中配置多数据库?

    原创 BOOT 为什么需要多数据库? 默认情况下,Spring Boot使用的是单数据库配置(通过spring.datasource.*配置具体数据库连接信息).对于绝大多数Spring Boot应用 ...

  6. PHP优化杂烩

    讲 PHP 优化的文章往往都是教大家如何编写高效的代码,本文打算从另一个角度来讨论问题,教大家如何配置高效的环境,如此同样能够达到优化的目的. pool 一个让人沮丧的消息是绝大多数 PHP 程序员都 ...

  7. httpRequest对象常用的方法

    IT程序员开发必备-各类资源下载清单,史上最全IT资源,个人收藏总结! 1. 获得客户机信息    getRequestURL方法返回客户端发出请求时的完整URL.    getRequestURI方 ...

  8. JDBC 事务控制

    一.简介: 前面一遍提到了jdbc事务相关的概念.从中了解到事务应具有ACID特性.所以对于javaweb开发来说,某一个service层的方法,应该是一个事务,应该是具有原子性的.特别是当一个ser ...

  9. bzoj3272 3638

    好题,这道题可以用线段树来快速模拟费用流寻找最长增广路 这样修改怎么做也很显然了 type node=record s,lx,rx,mx,lp,rp,pb,pe:longint; end; ..*,. ...

  10. bzoj1601: [Usaco2008 Oct]灌水

    经典延伸最小生成树问题... #include<cstdio> #include<cstring> #include<cctype> #include<alg ...