# 拓扑图
![](https://box.kancloud.cn/5578c007e789df1b37e68cc5e42e2b99_639x479.jpg)
# 基础配置
## R1:
~~~
Continue with configuration dialog? [yes/no]: no
Press RETURN to get started!
Router>enable
Router#configure terminal
Router(config)#hostname R1
R1(config)#interface gigabitEthernet 0/0
R1(config-if)#no shutdown
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up
R1(config-if)#interface gigabitEthernet 0/0.10
%LINK-5-CHANGED: Interface GigabitEthernet0/0.10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0.10, changed state to up
R1(config-subif)#encapsulation dot1Q 10
R1(config-subif)#ip address 192.168.1.254 255.255.255.0
R1(config-subif)#interface gigabitEthernet 0/0.20
%LINK-5-CHANGED: Interface GigabitEthernet0/0.20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0.20, changed state to up
R1(config-subif)#encapsulation dot1Q 20
R1(config-subif)#ip address 172.16.1.254 255.255.255.0
~~~
## SW1:
~~~
Switch>enable //进入特权模式
Switch#configure terminal //进入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname SW1 //修改主机名为 SW1
SW1(config)#vlan 10
SW1(config-vlan)#vlan 20
SW1(config-vlan)#interface fastEthernet 0/1
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 10
SW1(config-if)#interface fastEthernet 0/2
SW1(config-if)#switchport mode access
SW1(config-if)#switchport access vlan 20
SW1(config-if)#interface fastEthernet 0/3
SW1(config-if)#switchport mode trunk
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to up
~~~
# 实验测试
通过 ping 测试连通性
* PC 0 与 PC 1 之间可以通信(不同 vlan)