見出し画像

【Cisco】 VLANの設定

スイッチ

ルータと同様のIOSを使用しているため、モード移行やPW、ホスト名の設定などはルータと同じ方法で設定できるため以下を参考にする。

簡単な用語説明などはこちら


VLANの作成

番号の別れ方

1〜1000:標準範囲(VLANデータベースに保存)
1002〜1005::デフォルトVLAN(FDDI、トークンリング、FDDIおよびトークンリングの仮想リング)
1006〜4094:拡張範囲(running-configに保存)


データベースコンフィグレーションの場合

# 特権モードからVLANデータベースモードに移行する 
Switch#vlan database

# 新しいVLANを作成する(VLAN ID 100、名前:VLAN100) 名前は省略できる
Switch(vlan)#vlan 100 [#name VLAN100]

# VLANデータベースモードを終了する 
Switch(vlan)#exit 
Switch#exit
# または
Switch(vlan)#apply


# 設定の確認(特権EXECモードで行う)
Switch# exit
Switch> enable
Password: 
Switch# show vlan [brief]
Switch# show vlan id [VLAN ID]  # 指定したVLAN IDの詳細な情報
how interfaces [interface interface-id] switchport  # 指定したインターフェースに関連するVLAN設定の詳細を表示

表示例

Switch# show vlan

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Gi1/0/1, Gi1/0/2, Gi1/0/3
                                                Gi1/0/4, Gi1/0/5, Gi1/0/6
                                                Gi1/0/7, Gi1/0/8, Gi1/0/9
                                                Gi1/0/10, Gi1/0/11, Gi1/0/12
                                                Gi1/0/13, Gi1/0/14, Gi1/0/15
                                                Gi1/0/16, Gi1/0/17, Gi1/0/18
                                                Gi1/0/19, Gi1/0/20, Gi1/0/21
                                                Gi1/0/22, Gi1/0/23, Gi1/0/24
100  VLAN0100                         active    Gi1/0/25, Gi1/0/26
200  VLAN0200                         active
300  VLAN0300                         active
1002 fddi-default                     act/unsup
1003 token-ring-default               act/unsup
1004 fddinet-default                  act/unsup
1005 trnet-default                    act/unsup

VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1    enet  100001     1500  -      -      -        -    -        0      0
100  enet  100100     1500  -      -      -        -    -        0      0
200  enet  100200     1500  -      -      -        -    -        0      0
300  enet  100300     1500  -      -      -        -    -        0      0
1002 fddi  101002     1500  -      -      -        -    -        0      0
1003 tr    101003     1500  -      -      -        -    -        0      0
1004 fdnet 101004     1500  -      -      -        ieee -        0      0
1005 trnet 101005     1500  -      -      -        ibm  -        0      0

Remote SPAN VLANs
------------------------------------------------------------------------------

Primary Secondary Type              Ports
------- --------- ----------------- ------------------------------------------


グローバルコンフィグレーションの場合

Switch(config)#vlan 100  # VLANを作成する
Switch(config-vlan)#name VLAN100   # VLAN名を設定する
Switch(config-vlan)#exit  # VLANを有効にする

# 設定の確認(特権EXECモードで行う)
Switch# exit
Switch> enable
Password: 
Switch# show vlan [brief]
Switch# show vlan id [VLAN ID]  # 指定したVLAN IDの詳細な情報
how interfaces [interface interface-id] switchport  # 指定したインターフェースに関連するVLAN設定の詳細を表示


VLANの削除

VLANデータベースモード

Switch#no vlan <VLAN ID>

グローバルコンフィグレーションモード

Switch#configure terminal
Switch(config)#no vlan <VLAN ID>
Switch(config)#exit



IPアドレスの設定

管理VLAN

ネットワーク機器の管理用に割り当てられたVLANのこと。このVLANはデフォルトではVLAN1に設定される。またネットワーク管理者がアクセスするためのインターフェースが割り当てられており、機器の設定や監視、トラブルシューティングなどが行われる。
物理インターフェイスのスイッチポートにはIPアドレスが設定できないため、管理インターフェイスに設定を行う。

管理インターフェース
VLANの設定や管理を行うための仮想インターフェース


設定例

Switch(config)#interface vlan 1  # VLAN 1インターフェイス
Switch(config-if)#ip address 192.168.0.1 255.255.255.0
Switch(config-if)#no shutdown    # VLAN 1インターフェイスを有効
Switch(config)#ip default-gateway 192.168.0.254  # デフォルトゲートウェイ



ポートの設定

アクセスポートの設定

Switch(config)#interface GigabitEthernet0/1  # インターフェイスモード
Switch(config-if)#switchport mode access     # モードをアクセスに変更
Switch(config-if)#switchport access vlan 10  # VLANの指定


# 設定の確認
Switch# exit
Switch> enable
Password: 
Switch# show interfaces <interface名> <ポート番号> switchport
--------------------------------------------------------------
Switch#show interfaces gi0/1 switchport
Name: Gi0/1
Switchport: Enabled
Administrative Mode: dynamic auto
Operational Mode: static access
Administrative Trunking Encapsulation: negotiate
Operational Trunking Encapsulation: native
Negotiation of Trunking: On
Access Mode VLAN: 10 (VLAN0010)
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Enabled: ALL
Voice VLAN: none
Administrative private-vlan host-association: none
Administrative private-vlan mapping: none
Administrative private-vlan trunk native VLAN: none
Administrative private-vlan trunk Native VLAN tagging: enabled
Administrative private-vlan trunk encapsulation: dot1q
Administrative private-vlan trunk normal VLANs: none
Administrative private-vlan trunk associations: none
Administrative private-vlan trunk mappings: none
Operational private-vlan: none
Trunking FastEthernet0/1, FastEthernet0/2, FastEthernet0/3, FastEthernet0/4
--------------------------------------------------------------
# Operational Modeがstatic accessであることから、
# このポートがアクセスポートであることがわかります。
# また、Access Mode VLANが10に設定されているため、
# このポートからのパケットはVLAN10に所属する


トランクポートの設定

Switch(config)#interface GigabitEthernet0/1
Switch(config-if)#switchport trunk encapsulation [dot1q / isl]  # トランキングプロトコルの設定
Switch(config-if)#switchport mode trunk   # モードをトランクに変更
Switch(config-if)#switchport trunk allowed vlan 10,20,30  # 許可するVLANを指定
Switch(config-if)#switchport trunk native vlan 99        #(任意設定)
Switch(config-if)#end

# 設定の確認
Switch# exit
Switch> enable
Password: 
Switch# show interfaces trunk
--------------------------------------------------------------
Port        Mode             Encapsulation  Status        Native vlan
Fa0/1       desirable        802.1q         trunking      1
Fa0/2       auto             802.1q         trunking      1

Port        Vlans allowed on trunk
Fa0/1       1-1005

Port        Vlans allowed and active in management domain
Fa0/1       1,10,20

Port        Vlans in spanning tree forwarding state and not pruned
Fa0/1       1,10,20
--------------------------------------------------------------
#Fa0/1とFa0/2がトランクポートであること、Fa0/1がディサイアブルモードで、
#Fa0/2がオートモードであることがわかります。また、Fa0/1はVLAN 1-1005を許可し、
#管理ドメインでVLAN 1、10、20が有効であること、
 #VLAN 1、10、20がスパニングツリーの転送状態にあり、剪定されていない


DTPでのネゴシエーション設定

DTP (Dynamic Trunking Protocol) は、Cisco ネットワーク機器において、アクセスまたはトランク接続を設定するための自動化プロトコル。

Switch(config)# interface GigabitEthernet1/0/1
Switch(config-if)# switchport mode dynamic [auto / desirable]  # ネゴシエーションの設定
Switch(config-if)# switchport mode trunk

# DTPフレームの送信を止める
Switch(config-if)# switchport nonegotiate

※アクセス以外のモードでは、DTPによって定期的にネゴシエーションの送受信が行われているため、手動でトランクモードにすると二重で送受信していることになる。


各種確認の仕方

スイッチポートの確認

Switch# show interfaces interface-name switchport

Switch# show interfaces GigabitEthernet1/0/1 switchport
--------------------------------------------------------------
Name: GigabitEthernet1/0/1
Switchport: Enabled
Administrative Mode: dynamic auto
Operational Mode: static access
Administrative Trunking Encapsulation: negotiate
Operational Trunking Encapsulation: native
Negotiation of Trunking: On
Access Mode VLAN: 10 (VLAN0010)
Trunking Native Mode VLAN: 1 (default)
Administrative Native VLAN tagging: enabled
Voice VLAN: none
Administrative private-vlan host-association: none
Administrative private-vlan mapping: none
Administrative private-vlan trunk native VLAN: none
Administrative private-vlan trunk Native VLAN tagging: enabled
Administrative private-vlan trunk encapsulation: dot1q
Administrative private-vlan trunk normal VLANs: none
Administrative private-vlan trunk associations: none
Administrative private-vlan trunk mappings: none
Operational private-vlan: none
Trunking VLANs Enabled: ALL
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL
Protected: false
Unknown unicast blocked: disabled
Unknown multicast blocked: disabled
Appliance trust: none
--------------------------------------------------------------
# GigabitEthernet1/0/1ポートはアクセスモードであり、
# VLAN 10に割り当てられています。このポートはトランキングをサポートしておらず、
# VLAN 1がネイティブVLANであることが示されています。
# また、VLAN 2からVLAN 1001までのVLANがプルーニングされている


インターフェイスの状態確認

Switch# show interfaces <interface>

Switch# show interfaces GigabitEthernet1/0/1 switchport
--------------------------------------------------------------
Name: GigabitEthernet1/0/1
Switchport: Enabled
Administrative Mode: dynamic auto
Operational Mode: down
Administrative Trunking Encapsulation: negotiate
Negotiation of Trunking: On
Access Mode VLAN: 10 (VLAN0010)
Trunking Native Mode VLAN: 1 (default)
Administrative Native VLAN tagging: enabled
Voice VLAN: none
Administrative private-vlan host-association: none
Administrative private-vlan mapping: none
Administrative private-vlan trunk native VLAN: none
Administrative private-vlan trunk Native VLAN tagging: enabled
Administrative private-vlan trunk encapsulation: dot1q
Administrative private-vlan trunk normal VLANs: none
Administrative private-vlan trunk private VLANs: none
Operational private-vlan: none
Trunking VLANs Enabled: ALL
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL

Protected: false
Unknown unicast blocked: disabled
Unknown multicast blocked: disabled
Appliance trust: none
--------------------------------------------------------------
# インターフェイス「GigabitEthernet1/0/1」がスイッチポートとして
# 構成されていることが分かります。また、アクセスポートとしてVLAN 10が指定されており、
#トランクモードは「dynamic auto」であることが分かります。
# また、このインターフェイスはオペレーションモードが「down」であり、
# 現在のリンク状態は「operational mode: down」として表示される


MACアドレステーブルの確認

Switch# show mac address-table
--------------------------------------------------------------
          Mac Address Table
------------------------------
Vlan    Mac Address       Type    Ports
----    -----------       ----    -----
  10    0000.0c9f.f002    DYNAMIC    Fa0/1
  10    0000.0c9f.f003    DYNAMIC    Fa0/2
  20    0000.0c9f.f004    DYNAMIC    Fa0/3
  20    0000.0c9f.f005    DYNAMIC    Fa0/4
Total Mac Addresses for this criterion: 4
--------------------------------------------------------------
# VLAN10と20のMACアドレステーブルのエントリが表示されています。
# エントリには、それぞれのMACアドレス、タイプ(DYNAMIC)、
#およびポート(Fa0/1〜4)が含まれている


スイッチの初期化

以下の手順で行う
1、NVRAM上のstartupーconfigの消去
2、vlan.datを削除する
3、再起動

Switch# configure terminal
Switch(config)# no startup-config  # startup-configを削除
Switch(config)# exit
Switch# write erase  # 現在の設定を保存し、スタートアップ設定をクリア
Switch# delete (flash:)vlan.dat  # ()は機種によってはつける
Switch# reload


VTPの設定

VTPドメイン名の設定

特に指定がない限りグローバルコンフィグレーションで設定を行う。データベースコンフィグレーションでの設定は使われなくなってきている。

Switch(config)# vtp domain exampledomain
 Changing VTP domain name from NULL to exampledomain

Switch(config)# vtp password secretpassword

Switch(config)# vtp mode [server / client / transparent]  # 必要に応じて変える
 Setting device to VTP [server / client / transparent] mode.

モード

Serverモード
VLANの作成、変更、削除ができる。VTPドメインの管理者は、VTPサーバーモードを使用して、VLAN情報を他のVTPクライアントスイッチに配信したり、スイッチからVLAN情報を受信することができる。

Clientモード
VLANの作成、変更、削除ができない。VTPクライアントモードのスイッチは、VTPサーバーモードのスイッチからVLAN情報を受信することができる。

Transparentモード
VLANの作成、変更、削除ができるが、VLAN情報の配信は行わない。VTPトランスペアレントモードのスイッチは、VTPパケットを転送しますが、VLAN情報を他のスイッチに配信することはない。


VTPの設定の確認

Switch# show vtp status
--------------------------------------------------------------
VTP Version                     : 2
Configuration Revision          : 10
Maximum VLANs supported locally : 1005
Number of existing VLANs        : 10
VTP Operating Mode              : Server
VTP Domain Name                 : exampledomain
VTP Pruning Mode                : Enabled
VTP V2 Mode                     : Enabled
VTP Traps Generation            : Disabled
MD5 digest                      : 0xA1 0x39 0x8D 0x34 0x51 0x9E 0x02 0x91 
                                0xF7 0x8C 0x77 0xAB 0x61 0xBD 0x48 0x3E 
--------------------------------------------------------------
# VTPバージョン2が有効であり、ローカルでサポートされる最大VLAN数は1005で、
# 実際に存在するVLAN数は10です。VTPモードはServerモードであり、
# VTPドメイン名はexampledomainです。VTPプルーニングが有効になっており、
# VTP V2モードも有効になっています。また、VTPトラップの生成は無効になっています。
# MD5ダイジェストは、VTPパケットの整合性確認に使用される


VLAN間ルーティングの設定

スイッチとルータ両方で設定を行う必要がある

ルータ側の設定

# VLAN10とVLAN20のサブインターフェイスを作成する場合
Router(config)# interface GigabitEthernet0/0.10  # サブインターフェイスの作成
Router(config-if)# encapsulation dot1Q 10        # トランキングプロトコルの設定
Router(config-if)# ip address 192.168.10.1 255.255.255.0

Router(config)# interface GigabitEthernet0/0.20
Router(config-if)# encapsulation dot1Q 20
Router(config-if)# ip address 192.168.20.1 255.255.255.0

# 物理インターフェイスの有効化
Router(config)# interface GigabitEthernet1/0/1
Router(config-if)# no shutdown
Router(config-if)# end
Router# copy running-config startup-config

スイッチの設定

IPアドレスはルータ側で設定しているので不要

Switch(config)# interface GigabitEthernet1/0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10

Switch(config)# interface GigabitEthernet1/0/2
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 20


レイヤ3スイッチの設定

Switch(config)# ip routing  # ルーティングの有効

Switch(config)# interface vlan 10
Switch(config-if)# ip address 10.0.10.1 255.255.255.0
Switch(config-if)# no shutdown
Switch(config-if)# exit

Switch(config)# interface vlan 20
Switch(config-if)# ip address 10.0.20.1 255.255.255.0
Switch(config-if)# no shutdown
Switch(config-if)# exit

Switch(config)# interface gigabitethernet 1/0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10
Switch(config-if)# exit

Switch(config)# interface gigabitethernet 1/0/2
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 20
Switch(config-if)# exit

Switch(config)# interface gigabitethernet 1/0/3
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk allowed vlan 10,20
--------------------------------------------------------------
# VLAN10とVLAN20をそれぞれインターフェイスvlan10とvlan20に設定し、
# スイッチのインターフェイスgigabitethernet1/0/1と1/0/2を
# それぞれVLAN10とVLAN20にアクセスポートとして設定し、
# インターフェイスgigabitethernet1/0/3をトランクポートとして設定して
# VLAN10とVLAN20の通信を可能にしてい


ルーテッドポートの設定

この設定により、ポートはルーティングプロトコルによってVLAN間ルーティングを行うことができる。

Switch(config)# interface gigabitethernet1/0/1
Switch(config-if)# no switchport
Switch(config-if)# ip address 192.168.1.1 255.255.255.0
Switch(config-if)# no shutdown
--------------------------------------------------------------
# no switchportコマンドでインターフェイスをレイヤ3モードに切り替え、
# 次にip addressコマンドでIPアドレスを設定します。
# 最後に、no shutdownコマンドでポートを有効化

各種の確認コマンドはルータなどと同様

ルーテッドポートからスイッチポートへの戻し

# 削除するインターフェイス上で
Switch(config)# no ip address
Switch(config)# no shutdown
Switch(config)# no ip routing

Switch(config)# interface interface-id
Switch(config-if)# no ip address
Switch(config-if)# no shutdown
Switch(config-if)# switchport
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan vlan-id

よろしければサポートお願いします!よりいい情報を発信します。