ccna取得に向けてCiscoPacketTracerで構築練習　~VLAN~

## はじめに
CCNAを受験するにあたって、実際にコマンドを打って構築をすることが大切らしい。
Cisco Packet Tracerを使用して構築の練習とその流れ、結果を示して、気づいたことなどをまとめていこうと思う。

## 目標
+ catalyst上にVLANを作成
+ VTPで複数の複数のswitchを使ったVLANネットワークを構築
+ ルータを使用したVLAN間ルーティングを実装
+ L3スイッチを使用したVLANネットワークを構築

## 実践
### 1.catalystでVLANを作る
catalyst一台のシンプルな構成を作る。
![VLAN-1-1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2998315/49b098b7-0e41-9045-089e-84161beed3de.png)

```terminal:Switch0
Switch0(config)#vlan 2
Switch0(config-vlan)#exit
Switch0(config)#vlan 3
Switch0(config-vlan)#exit

Switch0(config)#interface range fa 0/1-2
Switch0(config-if-range)#switchport mode access 
Switch0(config-if-range)#switchport access vlan 2
Switch0(config-if-range)#exit
Switch0(config)#interface range fa 0/3-4
Switch0(config-if-range)#switchport mode access 
Switch0(config-if-range)#switchport access vlan 3
Switch0(config-if-range)#exit
Switch0(config)#end

Switch0#show vlan brief 

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/5, Fa0/6, Fa0/7, Fa0/8
                                                Fa0/9, Fa0/10, Fa0/11, Fa0/12
                                                Fa0/13, Fa0/14, Fa0/15, Fa0/16
                                                Fa0/17, Fa0/18, Fa0/19, Fa0/20
                                                Fa0/21, Fa0/22, Fa0/23, Fa0/24
                                                Gig0/1, Gig0/2
2    VLAN0002                         active    Fa0/1, Fa0/2
3    VLAN0003                         active    Fa0/3, Fa0/4
1002 fddi-default                     active    
1003 token-ring-default               active    
1004 fddinet-default                  active    
1005 trnet-default                    active 
```

+ 疎通確認をする
PC0からPC1にPingを打つ

![Cisco Packet Tracer - E__Cisco Packet Tracer 8.2.2_saves_vlanSwitching-qiita.pkt 2024-05-20 21-28-00.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2998315/0116f536-6870-8f59-d78a-b47850c41928.gif)

### 2. VTPの設定をしてもう一台switchをつなぐ

![VLAN-2-1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2998315/af7108cc-8d1e-2111-546e-a838e06a5766.png)


```terminal:Switch0
//VTP設定
Switch0(config)#vtp domain ccna
Changing VTP domain name from NULL to ccna
Switch0(config)#vtp mode ser
Switch0(config)#vtp mode server 
Device mode already VTP SERVER.
Switch0(config)#

//VLAN4作成
Switch0(config)#vlan 4
Switch0(config-vlan)#end

//VTP確認
Switch0#show vtp status 
VTP Version capable             : 1 to 2
VTP version running             : 1
VTP Domain Name                 : ccna
VTP Pruning Mode                : Disabled
VTP Traps Generation            : Disabled
Device ID                       : 0006.2ABB.C300
Configuration last modified by 0.0.0.0 at 3-1-93 02:11:27
Local updater ID is 0.0.0.0 (no valid interface found)

Feature VLAN : 
--------------
VTP Operating Mode                : Server
Maximum VLANs supported locally   : 255
Number of existing VLANs          : 8
Configuration Revision            : 1 //revisonが1になっている
MD5 digest                        : 0xD8 0xAC 0xCC 0x58 0xDE 0x74 0xE9 0x64 
                                    0xA6 0x88 0xAF 0x71 0x58 0xDE 0x59 0x70

//トランクポート作成
Switch0#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch0(config)#interface fa 0/24
Switch0(config-if)#switchport mode trunk 
```

```terminal:Switch1
//VTP設定
Switch1(config)#vtp domain ccna
Changing VTP domain name from NULL to ccna
Switch1(config)#vtp mode client 
Setting device to VTP CLIENT mode.
Switch1(config)#end

Switch1#show vtp status 
VTP Version capable             : 1 to 2
VTP version running             : 1
VTP Domain Name                 : ccna
VTP Pruning Mode                : Disabled
VTP Traps Generation            : Disabled
Device ID                       : 0001.9738.0100
Configuration last modified by 0.0.0.0 at 3-1-93 02:11:27

Feature VLAN : 
--------------
VTP Operating Mode                : Client
Maximum VLANs supported locally   : 255
Number of existing VLANs          : 8
Configuration Revision            : 1 //revisonが同期している
MD5 digest                        : 0xD8 0xAC 0xCC 0x58 0xDE 0x74 0xE9 0x64 
                                    0xA6 0x88 0xAF 0x71 0x58 0xDE 0x59 0x70 

//インターフェースの設定
Switch1#conf t
Switch1(config)#interface fa 0/1
Switch1(config-if)#switchport mode access 
Switch1(config-if)#switchport access vlan 2
Switch1(config-if)#exit 
Switch1(config)#interface fa 0/2
Switch1(config-if)#switchport mode access 
Switch1(config-if)#switchport access vlan 3
Switch1(config-if)#exit 
Switch1(config)#interface fa 0/3
Switch1(config-if)#switchport mode access 
Switch1(config-if)#switchport access vlan 4
Switch1(config-if)#exit 
```

+ 疎通確認をする
PC2からPC5にPingを打つ

![Cisco Packet Tracer - E__Cisco Packet Tracer 8.2.2_saves_vlanSwitching-qiita.pkt 2024-05-20 21-53-30.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2998315/a6b13b27-94b1-273c-ba50-8aebbac0b476.gif)

### 3. ルータを使ったVLAN間ルーティング
Switch0にルータを繋いでVLAN間ルーティングができるようにする。
![VLAN-3-1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2998315/fd55dfaa-ebe9-bfe1-b2b6-e63fa0a0257c.png)

```terminal:Router0
//sub interfaceの作成
Router0(config)#interface gi 0/1.2
Router0(config-subif)#encapsulation dot1Q 2
Router0(config-subif)#ip address 192.168.2.254 255.255.255.0
Router0(config-subif)#exit
Router0(config)#interface gi 0/1.3
Router0(config-subif)#encapsulation dot1Q 3
Router0(config-subif)#ip address 192.168.3.254 255.255.255.0
Router0(config-subif)#exit
Router0(config)#interface gi 0/1.4
Router0(config-subif)#encapsulation dot1Q 4
Router0(config-subif)#ip address 192.168.4.254 255.255.255.0
Router0(config-subif)#exit
Router0(config)#interface gi 0/1
Router0(config-if)#no shutdown
Router0(config)#end

Router0#show ip interface brief 
Interface              IP-Address      OK? Method Status                Protocol 
GigabitEthernet0/0     unassigned      YES unset  administratively down down 
GigabitEthernet0/1     unassigned      YES unset  up                    up 
GigabitEthernet0/1.2   192.168.2.254   YES manual up                    up 
GigabitEthernet0/1.3   192.168.3.254   YES manual up                    up 
GigabitEthernet0/1.4   192.168.4.254   YES manual up                    up 
GigabitEthernet0/2     unassigned      YES unset  administratively down down 
Vlan1                  unassigned      YES unset  administratively down down
```

```terminal:Switch0
//トランクポートの設定
Switch0(config)#interface gi 0/1
Switch0(config-if)#switchport mode trunk
Switch0(config-if)#switchport trunk encapsulation dot1Q
Switch0(config-if)#end

Switch0#show interfaces trunk
Port        Mode         Encapsulation  Status        Native vlan
Fa0/24      on           802.1q         trunking      1
Gig0/1      on           802.1q         trunking      1

Port        Vlans allowed on trunk
Fa0/24      1-1005
Gig0/1      1-1005

Port        Vlans allowed and active in management domain
Fa0/24      1,2,3,4
Gig0/1      1,2,3,4

Port        Vlans in spanning tree forwarding state and not pruned
Fa0/24      1,2,3,4
Gig0/1      1,2,3,4
```

+ 疎通確認をする
PC2からPC3にPingを打つ
![Cisco Packet Tracer - E__Cisco Packet Tracer 8.2.2_saves_vlanSwitching-qiita.pkt 2024-05-20 22-28-07.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2998315/88e2ddb9-c06d-ddc4-84ec-44d7c86587ac.gif)
PC2からPC6にPingを打つ
![Cisco Packet Tracer - E__Cisco Packet Tracer 8.2.2_saves_vlanSwitching-qiita.pkt 2024-05-20 22-29-54.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2998315/1578bc8b-4dee-d2fd-3fcb-1a6ffd976318.gif)

### 4. L3スイッチを使ったVLAN間ルーティング
![VLAN-4-1.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2998315/7eb3271f-3ea6-de70-0d77-3d0e6b94f9fe.png)

 ```terminal:L3Switch0
 //VLAN作成
L3Switch0(config)#interface vlan 2
L3Switch0(config-if)#ip address 192.168.2.254 255.255.255.0
L3Switch0(config-if)#no shutdown 
L3Switch0(config-if)#exit
L3Switch0(config)#interface vlan 3
L3Switch0(config-if)#ip address 192.168.3.254 255.255.255.0
L3Switch0(config-if)#no shutdown 
L3Switch0(config-if)#exit
L3Switch0(config)#interface vlan 4
L3Switch0(config-if)#ip address 192.168.4.254 255.255.255.0
L3Switch0(config-if)#no shutdown 
L3Switch0(config-if)#exit
L3Switch0(config)#ip routing

//インターフェース設定
L3Switch0(config)#interface fa 0/1
L3Switch0(config-if)#switchport trunk encapsulation dot1q 
L3Switch0(config-if)#switchport trunk allowed vlan 2-4
L3Switch0(config-if)#switchport mode trunk
L3Switch0(config-if)#exit
L3Switch0(config)#interface fa 0/2
L3Switch0(config-if)#switchport trunk encapsulation dot1q 
L3Switch0(config-if)#switchport trunk allowed vlan 2-4
L3Switch0(config-if)#switchport mode trunk 
L3Switch0(config-if)#exit
L3Switch0(config)#
L3Switch0(config)#interface fa 0/10
L3Switch0(config-if)#switchport access vlan 4
L3Switch0(config-if)#switchport mode access 
L3Switch0(config-if)#exit
 ```
+ 疎通確認をする
PC4からPC7へPing
![Cisco Packet Tracer - E__Cisco Packet Tracer 8.2.2_saves_vlanSwitching-L3-qiita.pkt 2024-05-20 23-11-57.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2998315/b2d04820-0536-f5f0-1e2f-0dd9b22226f8.gif)

PC5からPC0へPing
![Cisco Packet Tracer - E__Cisco Packet Tracer 8.2.2_saves_vlanSwitching-L3-qiita.pkt 2024-05-20 23-13-35.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2998315/4f7cccfd-5dd1-ae58-d539-d59b32d31bec.gif)

PC0からPC1へPing
![Cisco Packet Tracer - E__Cisco Packet Tracer 8.2.2_saves_vlanSwitching-L3-qiita.pkt 2024-05-20 23-15-11.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/2998315/7c4a0dfb-be27-1fb4-e425-b0f79dcd1848.gif)


 ## 気になったこと,覚えておきたいこと
 + L2スイッチ、ルータ、L3スイッチのコマンドと設定の仕方の違いを覚える
     + VLAN
     ```
     L2: (config)#vlan <vlan No.>
     L3: (config)#interface vlan <vlan No.>
     Router: (config-subif)# encapsuration dot1Q <vlan No.>
     ```
     + VLANをインターフェースに割り当てる
     L2,L3: interfaceにaccess,trunkポートの設定とvlanを割り当てる。
     Router: サブインターフェースに割り当てる

+ L3デバイス(router,L3switch)は`no shutdown`と`ip address`を忘れない
+ ネットワークを超えない通信はswitchで処理される(基本的すぎるけど改めて確かめて理解した)。