Cisco(思科)路由器端口的配置
小编都是喜欢借助实验写博客
一、拓扑图
结合图可以知道我们一共有四个网段(四个vlan)
1.vlan 1 ip:192.168.1.0网段 自带的vlan不需要在路由器添加的
2.vlan 2 ip:192.168.2.0网段 需要在交换机添加划分
3.vlan 3 ip:192.168.3.0网段 需要在交换机添加划分
4.vlan 6 ip:192.168.168.0网段 需要在交换机添加划分
划分vlan具体操作:
//下面这里我们具体操作一个接口的划分其他都是一样的操作
Switch(config)#ena
Switch(config)#enable password 123
Switch(config)#interface vlan1
Switch(config-if)#ip address 192.168.1.253 255.255.255.0 //vlan1配ip
Switch(config-if)#no shutdown
%LINK-5-CHANGED: Interface Vlan1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to up
Switch(config-if)#exit
Switch(config)#ip default-gateway 192.168.1.254 //交换机设置网关
Switch(config)#exit
Switch#vlan database // 进入VLAN数据库模式
Switch(vlan)#vlan 2 name v2 // 新建一个名字叫v2的vlan2
Switch(config)#interface f0/1 // 进入交换机的f0/1接口
Switch(config-if)#switchport mode access //将交换机的端口模式设置为access
Switch(config-if)#switchport access vlan 2 //将当前端口绑定到vlan 2中
这样我们就把vlan划分啦
//交换机模式
Switch(config)#interface f0/24 //进入交换机的f0/1接口
Switch(config-if)#switchport mode trunk //将交换机的端口模式设置为trunk
路由器端口的配置:
我们可以从路由器的f0/0端口分出分多个子端口如f0/0.1、f0/0.2、f0/0.3、f0/0.4,将不同网段的封装在子端口就可以实现不同的vlan互联操作,具体如下操作
首先我们得进入f0/0这个端口进行no shutdown的激活端口操作
子端口后面就不用no shutdown
f0/0.1的ip设为192.168.1.254 255.255.255.0的网关
f0/0.2的ip设为192.168.2.254 255.255.255.0的网关
f0/0.3的ip设为192.168.3.254 255.255.255.0的网关
f0/0.2的ip设为192.168.168.254 255.255.255.0的网关
具体操作如下:
//这里就写一个啦,都是一样的,最下面会有详细的操作
Router(config)#interface f0/0 //进入f0/0端口
Router(config-if)#no shutdown //激活端口
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#
Router(config-if)#exit
Router(config)#interface f0/0.1 //进入f0/0.1子端口
Router(config-subif)#
%LINK-5-CHANGED: Interface FastEthernet0/0.1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.1, changed state to up
Router(config-subif)#encapsulation dot1Q 1 //将f0/0.1子端口封装到vlan1里面
Router(config-subif)#ip address 192.168.1.254 255.255.255.0 //给端口配置地址
Router(config-subif)#exit
注意注意:在封装vlan2和vlan3的时候我们要他在添加ip地址操作后面添加一句
Router(config-subif)#ip helper-address 192.168.168.1
DHCP操作:
交换机的详细操作
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#ena
Switch(config)#enable pass
Switch(config)#enable password 123
Switch(config)#interface vlan 1
Switch(config-if)#ip add
Switch(config-if)#ip address 192.168.1.253 255.255.255.0
Switch(config-if)#no shutdown
%LINK-5-CHANGED: Interface Vlan1, changed state to up
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to up
Switch(config-if)#exit
Switch(config)#ip de
Switch(config)#ip default-gateway 192.168.1.254
Switch(config-if)#exit
Switch(config)#line vty 0 15
Switch(config-line)#pas
Switch(config-line)#password aaa
Switch(config-line)#login
Switch(config-line)#exit
Switch(config)#exit
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#vlan database
% Warning: It is recommended to configure VLAN from config mode,
as VLAN database mode is being deprecated. Please consult user
documentation for configuring VTP/VLAN in config mode.
Switch(vlan)#vlan 2 name v2
VLAN 2 added:
Name: v2
Switch(vlan)#vlan 3 name v3
VLAN 3 added:
Name: v3
Switch(vlan)#vlan 6 name v6
VLAN 6 added:
Name: v6
Switch(vlan)#exit
APPLY completed.
Exiting....
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#int
Switch(config)#interface range f0/1-5
Switch(config-if-range)#swi
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#swi
Switch(config-if-range)#switchport access vlan 6
Switch(config-if-range)#exit
Switch(config)#interface range f0/6-10
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 2
Switch(config-if-range)#exit
Switch(config)#interface range f0/11-15
Switch(config-if-range)#switchport mode access
Switch(config-if-range)#switchport access vlan 3
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to downSwitch(config-if-range)#
Switch(config-if-range)#exit
Switch(config)#inter
Switch(config)#interface f0/24
Switch(config-if)#switchport mode trunk
Switch(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/24, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/24, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to up
Switch(config-if)#exit
路由器的详细操作:
Router>
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#line vty 0 15
Router(config-line)#passw
Router(config-line)#password 123
Router(config-line)#login
Router(config-line)#exit
Router(config)#int
Router(config)#interface f0/0
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#
Router(config-if)#interface f0/0.1
Router(config-subif)#
%LINK-5-CHANGED: Interface FastEthernet0/0.1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.1, changed state to up
Router(config-subif)#enc
Router(config-subif)#encapsulation dot1Q 1
Router(config-subif)#ip add
Router(config-subif)#ip address 192.168.1.254 255.255.255.0
Router(config-subif)#exit
Router(config)#interface f0/0.2
Router(config-subif)#
%LINK-5-CHANGED: Interface FastEthernet0/0.2, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.2, changed state to up
Router(config-subif)#encapsulation dot1Q 2
Router(config-subif)#ip address 192.168.2.254 255.255.255.0
Router(config-subif)#ip help
Router(config-subif)#ip helper-address 192.168.168.1
Router(config-subif)#exit
Router(config)#interface f0/0.3
Router(config-subif)#
%LINK-5-CHANGED: Interface FastEthernet0/0.3, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.3, changed state to up
Router(config-subif)#encapsulation dot1Q 3
Router(config-subif)#ip address 192.168.3.254 255.255.255.0
Router(config-subif)#ip helper-address 192.168.168.1
Router(config-subif)#exit
Router(config)#interface f0/0.4
Router(config-subif)#
%LINK-5-CHANGED: Interface FastEthernet0/0.4, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.4, changed state to up
Router(config-subif)#encapsulation dot1Q 6
Router(config-subif)#ip address 192.168.168.254 255.255.255.0
Router(config-subif)#