デバイス設定のための必須 Cisco コマンド チートシート
はじめに
Cisco IOS(Internetwork Operating System)は、管理者が Cisco デバイスを管理し設定するための手段を提供します。Cisco のコマンド構造は独自仕様ですが、さまざまなベンダーに共通して適用できるネットワークデバイス管理の基本概念を示しています。Aruba、Juniper、Broadcom など他の主要ネットワーク企業のシステムでも、同様のコマンドラインインターフェイス(CLI)や設定の考え方が見られ、ネットワーク担当者は多少の適応を行うことで、異なるプラットフォームに対してスキルを活用できます。
この記事では、Cisco ネットワークデバイスの管理および設定に使える、素早いコマンドガイドとしてのチートシートを提供します。いくつかのコマンドについて、実際の動作を手順ごとに示すためのスクリーンショットを掲載しています。スクリーンショットは、ルーターまたはスイッチにコンソール接続して撮影しました。
クイックリファレンス:必須の Cisco コマンド
基本モードとナビゲーション
Command | Purpose |
|---|---|
|
enable |
Enter privileged EXEC mode |
|
configure terminal |
Enter global configuration mode |
|
show running-config |
View the device's active configuration |
インターフェイスと VLAN 設定
Command | Purpose |
|---|---|
|
interface gigabitethernet 0/1 |
Select an interface to configure |
|
vlan 10 |
Create or select VLAN 10 |
|
switchport mode access |
Set a port to access mode |
ルーティングの基礎
Command | Purpose |
|---|---|
|
ip route 0.0.0.0 0.0.0.0 <next-hop> |
Add a default static route |
|
router ospf 1 |
Start an OSPF routing process |
|
show ip route |
View the routing table |
トラブルシューティング
Command | Purpose |
|---|---|
|
show ip interface brief |
Check interface status and IP addresses at a glance |
|
ping <address> |
Test connectivity to a device |
|
show version |
Check IOS version and uptime |
これらのコマンドで構成変更を行いますか?Netwrix Auditor for Network Devices は ネットワーク構成変更の追跡 を追加するので、誰が何をいつ変更したのかを常に把握できます。
コマンドライン・インターフェイス(CLI)構造の概要
コマンドモード
Cisco IOS のコマンドライン・インターフェイス(CLI)は、次のコマンドモードで階層的に構成されています。
- User EXEC モード — これは Cisco デバイスにログインしたときのデフォルトのモードです。アクセスは限定されており、基本的な監視コマンドのみを許可し、設定変更を行う機能は制限されます。このモードは、プロンプトが > で終わることで識別できます。
- Privileged EXEC モード — 権限が昇格されたこのモードでは、すべての show コマンドとシステムレベルの操作にアクセスできます。システムの完全な可視性は提供しますが、設定へのアクセスはできません。また、ユーザーがデバイスの診断やファイル管理のタスクを実行できるようにもなります。このモードは、プロンプトが # で終わることで示されます。
- Global Configuration モード — この高度に特権化されたモードでは、システム全体にわたる設定変更を行うことができ、インターフェイス設定など特定の設定に対してさまざまなサブモードへアクセスできます。このモードでは、プロンプトに (config)# が含まれます。
コマンドモード間の移動
Cisco ルーターまたはスイッチに最初にログインすると、User EXEC モードになります。以下のコマンドを使用して、より特権の高いモードに切り替えてください:
- enable — Privileged Exec モードにアクセスするために使用します
- config terminal(または単に config t)— Global Configuration モードにアクセスするために使用します
これらのコマンドは、下のスクリーンショットに表示されています:
グローバル構成(Global Configuration)モードは、さまざまなコンポーネントを設定できるように、いくつかのサブモードにさらに分けることができます。以下に、そのサブモードとそれらへアクセスするためのコマンドを示します:
|
Interface Configuration mode |
interface [interface-type] [interface-number] |
|
Subinterface Configuration mode |
interface [interface-type] [interface-number].[subinterface-number] |
|
Router Configuration mode |
router [routing-protocol] |
|
Line Configuration mode |
line [line-type] [line-number] |
より高い特権モードに移動するためのコマンドを理解したところで、そこから戻るためのコマンドを紹介します。
- exit — 設定モードの階層で1つ上のレベルに戻るために使用します。以下のスクリーンショットは、管理者が Privileged Exec モードに戻る様子を示しています:
- end — どの設定モードからでも、Privileged EXEC モードへ直ちに戻るために使用します。ネストされた設定レベルから素早く抜け出すのに便利です。
システム設定の表示
Cisco デバイスにログインしたら、おそらく基本的なシステム設定を確認したいはずです。これは、show running-config と入力するだけで簡単に行えます。あるいは単に show run でも構いません。このコマンドは、デバイスのメモリに保存されているアクティブな設定を表示します。
下のスクリーンショットでは、まず User Exec モードでコマンドを試したところ、権限が不十分なため失敗したことがわかります。スクリーンショットには running config の一部だけが表示されています。
設定に関連するその他のコマンドには、次のようなものがあります。
|
show startup-config |
Displays the saved configuration stored in the device's NVRAM, which will be loaded when the device starts up |
|
copy running-config startup-config |
Replaces the startup config with the active config when the Cisco network device initializes |
|
copy startup-config running-config |
Merges the startup config with the currently active config in RAM |
|
write erase erase startup-config |
Deletes the startup config |
ショートカットとコマンド履歴
素早いナビゲーションのための追加コマンドをいくつか紹介します:
- Ctrl+Z — このキーボードショートカットはいつでも使用でき、現在のどの設定モードからでも即座に抜けて Privileged EXEC mode に戻ります
- Tab キー — このキーを使用すると、途中まで入力したコマンドを自動補完したり、考えられる補完候補を表示したりできます。
- 上矢印キー / 下矢印キー — これらのキーを使用して、過去のコマンドを順に切り替えできます。
- show history — このコマンドを使用すると、コマンド履歴バッファを表示します。
デバイスのセットアップと基本設定
デバイス名の変更
先ほどのスクリーンショットに表示された running config では、router がホスト名(hostname)として示されていました。これは switch が Cisco スイッチのデフォルト名であるのと同様に、Cisco ルーターのデフォルト名です。デバイス名はコマンドプロンプトに表示されます。
hostname コマンドを使用してデバイス名を変更します。ネットワーク内での識別を容易にするため、各デバイスには固有の名前を選択してください。以下の例では、ルーターの名前を NorthOfficeRouter に変更しました。新しい名前が最終的なプロンプトの一部としてどのように表示されるか確認してください。
IP アドレスの割り当て
リモートでデバイスを管理できるように、デバイスに IP アドレスも割り当てる必要があります。IP アドレスを割り当てたいインターフェイスを選択し、次の手順を完了してください:
- インターフェース設定モードに入ります:
interface <interface-name>
- IP アドレスとサブネットマスクを割り当てます:
ip address <IP-address>
- インターフェイスを有効にします:
no shutdown
こちらは、この手順が Cisco IOS でどのように表示されるかです。config-if は、インターフェイス設定サブモードにいることを示します。
パスワードの設定
新しいデバイスにログオンしたため、パスワードを入力する必要はありませんでした。セキュリティを強化するためにパスワードを有効にするコマンドは次のとおりです:
|
enable password <pass-value> |
Defines the password required when using the enable command1 |
|
enable secret <pass-value> |
Sets the password required for any user to enter enable mode and encrypts it |
|
service password-encryption |
Directs the Cisco IOS software to encrypt the passwords, CHAP secrets and similar data saved in its configuration file |
バナーの設定
ほかにも、構成できるさまざまなバナーがあります:
- メッセージ・オブ・ザ・デイ(motd)バナー:
バナー motd #Unauthorized access prohibited#
- ログイン バナー:
バナーログイン #資格情報を入力してください#
- Exec バナー:
バナー Exec #ネットワークへようこそ#
スイッチの設定
スイッチはルーターとは別の目的で使用されるため、使用するコマンドも異なります。理解しておくべき主な概念は次のとおりです:
- スイッチポート モード — スイッチポート モードは、ポートが VLAN トラフィックをどのように処理するかを決定します。主なモードは 3 つで、access mode, trunk mode、dynamic modeです。
- デュプレックス速度 — デュプレックス設定により、ポートがデータを同時に送受信できるかどうかが決まります。half, full または auto を指定できます。 Auto では、スイッチが接続先デバイスとデュプレックス設定をネゴシエーションできます。
- スピード — この設定により、ポートのデータ伝送レートが決まります。スイッチの対応能力に応じて、スピードを 10 Mbps、100 Mbps、1000 Mbps(1 Gbps)または auto に設定できます。
VLAN 設定
VLAN 設定は、ネットワークのセグメンテーションと管理における重要な要素です。Global Configuration モードでは、次のコマンドを使用できます。
|
vlan <vlan-id> |
Creates a VLAN |
|
Vlan <vlan-name> |
Assigns a name to the VLAN |
|
vlan switchport access vlan <vlan-id> |
Sets the VLAN that the interface belongs to |
|
no vlan <vlan-id> |
Deletes a VLAN |
|
show vlan |
Display the VLAN configuration |
以下のスクリーンショットは、基本的なポート設定のためのコマンドを示しています:
スパニングツリープロトコル(Spanning Tree Protocol、STP)コマンド
スパニングツリープロトコル(Spanning Tree Protocol、STP)は、ネットワークループを防ぐのに役立つ Cisco スイッチの機能です。STP は、すべての VLAN に対して Cisco スイッチでデフォルトで有効化されています。スイッチ全体に対して STP 設定をグローバルに変更することも、ネットワークのさまざまな部分での STP 動作をきめ細かく制御するために、個々のインターフェイスまたは VLAN に対して特定の設定を適用することもできます。コマンドは以下のとおりです:
spanning-tree mode rapid-pvst
トランクポートの設定
複数の VLAN トラフィックを運ぶ必要があるポートは、トランクとして設定する必要があります。まずポートをトランクに設定し、その後 VLAN を割り当てます。コマンドは以下のとおりです:
switchport trunk native vlan <vlan-id>
Cisco スイッチでトランク ポートを設定するには、次の switchport trunk と switchport trunk allowed vlan コマンドを使用します。これらのコマンドについて、詳しく説明します:
|
switchport trunk native vlan <vlan-id> |
Enables trunk mode for the port and sets the native VLAN for untagged traffic on the trunk |
|
switchport trunk allowed vlan <vlan-id> |
Adds the specified VLANs to the current list |
|
switchport trunk allowed vlan remove <vlan-id> |
Removes the specified VLANs from the allowed list |
以下のスクリーンショットは、これらの VLAN コマンドが実際に動作している様子を示しています:
ネットワーキングの基礎
IP アドレス指定とサブネット化
IP アドレス指定とサブネット化には、次のコマンドを使用します:
|
ip address <ip-value> <bnet-value> |
Assigns an IP and subnet mask |
|
show ip interface <interface-number> |
Displays the status of a network interface as well as a detailed listing of its IP configurations and related characteristics |
|
show ip interface brief |
Provides a concise summary of the IP interface status and configuration |
|
ip address <ip-value> <subnet-value> secondary |
Assigns a secondary IP address |
|
no ip address |
Removes an IP address |
以下のスクリーンショットは、show ip interface brief コマンドの出力結果を示しています:
ルーティング プロトコルの設定
次のコマンドを使用して、ルーティング プロトコルを設定できます:
|
ip route <network-number> <network-mask> {<ip-address> | <exit-interface>} |
Sets a static route in the IP routing table |
|
ip route 0.0.0.0 0.0.0.0 {next-hop-ip | exit-interface} |
Configures a default route |
|
no ip route {network} {mask} {next-hop-ip | exit-interface} |
Removes a route |
|
router rip |
Enables a Routing Information Protocol (RIP) routing process, which places you in Router Configuration mode |
|
no auto-summary |
Disables automatic summarization |
|
version 2 |
Configures the software to receive and send only RIP version 2 packets |
|
network ip-address |
Associates a network with a RIP routing process |
|
passive-interface interface |
Sets the specified interface to passive RIP mode, which means RIP routing updates are accepted by, but not sent out of, the interface |
|
show ip rip database |
Displays the contents of the RIP routing database |
|
default-information originate |
Generates a default route into RIP |
以下のスクリーンショットは、1 つの静的ルートの設定と、その他すべてのネットワークに対するデフォルト ルートの設定を示しています:
ネットワーク アドレス変換 (NAT) の設定
次のコマンドを使用して NAT を設定します。NAT により、ローカル ネットワーク上のプライベート IP アドレスを、インターネット経由で送信する前にパブリック IP アドレスへ変換できます:
|
ip nat [inside | outside] |
Specifies whether the NAT operation is applied to traffic entering or leaving the router’s network |
|
ip nat inside source {list{access-list-number | access-list-name}} interface type number[overload] |
Establishes dynamic source translation. Use the list keyword to specify an ACL to identify the traffic that will be subject to NAT. The overload option enables the router to use one global address for many local addresses |
|
ip nat inside source static local-ip global-ip |
Establishes a static translation between an inside local address and an inside global address |
トラブルシューティングと診断
以下は、トラブルシューティングや基本的な診断に役立つコマンドです:
|
ping {hostname | system-address} [source source-address] |
Reveals basic network connectivity |
|
traceroute {hostname | system-address} [source source-address] |
Traces the route that packets take to reach a destination |
|
show interfaces |
Displays detailed information about interface status, settings and counters |
|
show ip route |
Shows the routing table of the device |
|
show interface status |
Displays the interface line status |
|
show interfaces trunk |
Lists information about the currently operational trunks and the VLANs supported by those trunks |
|
show version |
Displays information about the IOS version, uptime and hardware configuration |
|
show running-config |
Displays the current active configuration on the device |
|
show tech-support |
Generates a comprehensive report of the device's configuration and status (useful for advanced troubleshooting) |
|
show cdp |
Shows whether CDP is enabled globally |
|
show cdp neighbors [detail] |
Lists summary (or detailed) information about each neighbor connected to the device |
|
cdp run |
Enables or disables Cisco Discovery Protocol (CDP) for the device |
|
show mac address-table |
Displays the MAC address table |
|
show vtp status |
Lists the current VLAN Trunk Protocol (VTP) status, including the current mode |
セキュリティ設定
アクセス リストを設定して、Cisco デバイスへの通信および Cisco デバイスからの通信を制限したり許可したりできます。次のコマンドを使用してください:
|
password <pass-value> |
Lists the password that is required if the login command (with no other parameters) is configured |
|
username name password <pass-value> |
Defines one of possibly multiple user names and associated passwords used for user authentication. It is used when the login local line configuration command has been used. |
|
enable password <pass-value> |
Defines the password required when using the enable command |
|
enable secret <pass-value> |
Sets the password required for any user to enter enable mode |
|
service password-encryption |
Directs the Cisco IOS software to encrypt the passwords, CHAP secrets and similar data saved in its configuration file |
|
ip access-list {standard | extended} {acl-name | acl-number |
Creates a standard or extended ACL |
|
permit source <source-wildcar> |
Adds permit rules for a Standard ACL |
|
deny source <source-wildcard> |
Adds deny rules for an Extended ACL |
|
ip access-group {acl-name | acl-number} {in | out} |
Applies an ACL to an interface |
|
show access-lists [acl-name | acl-number] |
Displays ACL configuration |
|
no ip access-list {standard | extended} {acl-name | acl-number} |
Removes an ACL |
|
ip domain-name name |
Configures a DNS domain name |
|
crypto key generate rsa |
Creates and stores (in a hidden location in flash memory) the keys that are required by SSH |
|
transport input {telnet | ssh} |
Defines whether Telnet or SSH access is allowed into this switch. Both values can be specified in a single command to allow both Telnet and SSH access, which are the default settings |
|
ntp peer <ip-address> |
Configures the software clock to synchronize a peer or to be synchronized by a peer |
以下のスクリーンショットでは、拡張 ACL(アクセス制御リスト)のコマンドを示します:
SSH とリモートアクセスの設定
次のコマンドを使用して、SSH とリモートアクセスを設定します:
|
hostname <name> |
Sets a hostname (if not already configured) |
|
ip domain-name [domain-name] |
Configures an IP domain name |
|
crypto key generate rsa |
Generates an RSA key pair for SSH |
|
ip ssh version 2 |
Configures SSH version 2 |
|
username [username] privilege [level] secret [password] |
Creates a local user account |
|
Router(config)# line vty [line-range] Router(config-line)# transport input ssh Router(config-line)# login local |
Configures VTY lines for SSH access |
以下のスクリーンショットでは、RSA キーの生成を示します:
ポートセキュリティの実装
次のコマンドを使用して、ポート セキュリティを実装します。
|
switchport port-security |
Enables port security on the interface |
|
switchport port-security maximum <number> |
Sets the maximum number of secure MAC addresses on the port |
|
switchport port-security mac-address {mac-addr | {sticky [mac-addr]}} |
Adds a MAC address to the list of secure MAC addresses and optionally configures them as sticky on the interface |
|
switchport port-security violation {shutdown | restrict | protect} |
Sets the action to be taken when a security violation is detected |
|
show port security [interface interface-id] |
Displays information about security options configured on the interface |
以下のスクリーンショットは、スイッチ ポートでポート セキュリティを設定する手順を示しています。
ユーザー アカウントの管理
次のコマンドを使用してユーザー アカウントを管理できます。
|
username <username> privilege <level> secret <password> |
Creates a local user account |
|
show users |
Displays current user sessions |
|
no username <username> |
Removes a user account |
|
security passwords min-length <length> |
Sets password complexity requirements |
DHCP 設定
次のコマンドを使用して DHCP を設定します:
|
ip address dhcp |
Acquires an IP address on an interface via DHCP |
|
ip dhcp pool <pool-name> |
Configures a DHCP address pool on a DHCP server and enters DHCP Pool Configuration mode |
|
domain-name <domain> |
Specifies the domain name for a DHCP client |
|
network network-number [mask] |
Configures the network number and mask for a DHCP address pool primary or secondary subnet on a Cisco IOS DHCP server |
|
ip dhcp excluded-address ip-address [last-ip-address] |
Specifies IP addresses that a DHCP server should not assign to DHCP clients |
|
ip helper-address address |
Enables forwarding of UDP broadcasts, including BOOTP, received on an interface |
|
default-router address [address2 ... address8] |
Specifies the default gateway for a DHCP client |
下のスクリーンショットは、Cisco ルーターでの基本的な DHCP 設定例を示しています:
監視とロギング
次のコマンドは、監視とロギングに役立ちます:
|
logging on |
Enables logging globally |
|
logging host {ip-address | hostname} |
Configures logging to a syslog server |
|
logging trap level |
Sets the logging severity level |
|
terminal monitor |
Sends a copy of all syslog messages, including debug messages, to the Telnet or SSH user who issues this command |
|
snmp-server community <community-string> [RO|RW] |
Enables SNMP |
|
snmp-server location <location-string> |
Configures the SNMP server location |
|
snmp-server enable traps |
Enables SNMP traps |
バックアップ、復元、アップグレード
次のコマンドは、バックアップ、復元、およびアップグレードに使用します:
|
copy running-config startup-config |
Saves the running configuration to startup configurationEnables logging globally |
|
copy running-config tftp |
Copies the running configuration to a TFTP server |
|
copy startup-config tftp |
Copies the startup configuration to a TFTP server |
|
copy tftp: running-config |
Copies the configuration from a TFTP server to the device |
|
copy running-config flash:<file name> |
Copies the configuration to flash |
|
copy {ftp: flash:} |
Copies a new IOS image to the device using TFTP or FTP |
下のスクリーンショットは、実行中の設定(running config)が起動時の設定(startup config)にバックアップされていることを示しています。
認証、認可、およびアカウンティングの設定
次のコマンドは、認証、認可、およびアカウンティング(AAA)を設定するために使用します:
|
aaa new-model |
Enables AAA |
|
radius-server host {ip-address | hostname} [auth-port port-number] [acct-port port-number] [timeout seconds] [retransmit retries] [key string] |
Configures the RADIUS server |
|
radius-server key {0 string | 7 string | string} |
Sets the RADIUS key |
|
aaa authentication login {default | list-name} method1 |
Configures AAA authentication |
|
aaa authorization {network | exec | commands level | reverse-access | configuration} {default | list-name} method1 |
Configures AAA authorization |
|
aaa accounting {system | network | exec | connection | commands level} {default | list-name} {start-stop | stop-only | none} [method1 |
Configures AAA accounting |
よくあるユースケース
Cisco スイッチのよくあるユースケースは、VLAN を使ったネットワークのセグメンテーションと品質管理です。無線、電話、カメラ、プリンターそれぞれに対して別々の VLAN を作成することで、ネットワークを分離し、さまざまな種類のトラフィックを優先できます(例:印刷よりも音声を優先する)。
Cisco ルーターでも、標準または拡張のアクセス制御リストを使ってネットワークのセグメンテーションを実現できます。これにより、特定の送信元からのトラフィックを制限したり、ルーターのセグメントに出入りする特定のトラフィック種別を制限したりできます。
ネットワークセグメント向けに Cisco ルーターを設定するための手順を、順を追って説明します:
- ルーターのホスト名を設定し、シークレットパスワードを有効にします。
- ルーターの各インターフェースに IP アドレスを割り当てます。
- 接続されているネットワーク セグメントに対するトラフィックをルーティングするには、静的ルーティング情報を設定するか、ルーティング プロトコルを設定してください。
- DHCP を設定して、ネットワークに接続するクライアントに IP アドレスやその他の DHCP オプションを配布します。
- ACL を設定してセキュリティを強化し、入出力(入方向・出方向)のトラフィックを制限します。
- インターネット アクセスのために NAT を設定します。
- ログ記録を有効にします。
- 設定を保存してください。
よくある問題のシナリオとトラブルシューティングのヒント
Cisco ルーターおよびスイッチでよくある問題と、それらの解決のヒントを紹介します:
シナリオ:VLAN またはサブネット間でデバイスが通信できない
- スイッチで VLAN 設定とトランキングを確認してください。
- IP アドレスとサブネットマスクを確認します。
- ルーティングテーブルを確認し、ルートが存在することを確認します。
- ping と traceroute で接続性をテストします。
- ACL がトラフィックをブロックしていないことを確認します。
シナリオ:インターフェイスがダウンしている、またはフラッピングしている
- 物理的な接続とケーブルの状態を確認してください。
- 次のコマンドでインターフェイス設定を確認してください:show interface。
- インターフェイスをいったんシャットダウンし、再度有効にしてください。
- さまざまな速度およびデュプレックス設定で動作確認してください。
シナリオ:不正アクセスの試行または怪しい通信(トラフィック)
- ログを確認し、show logging を使用します。
- ACL の設定とヒット数を確認してください。
- AAA と TACACS+ の設定を確認してください。
- スイッチでポートセキュリティを導入してください。
ボーナスのヒント
次のヒントは、Cisco デバイスをより効率的に管理するのに役立ちます。:
- Cisco IOS に慣れていない場合は、状況に応じたヘルプを活用しましょう。コマンドのどの位置でも ? と入力すると、提案と利用可能な
- コマンドのショートカットとタブ補完で時間を節約しましょう。たとえば sh run と入力する代わりに show running-config を入力します。
- 上下の矢印(または Ctrl+P と Ctrl+N)を使って、最近使用したコマンドにすばやくアクセスできます。
- Cisco ルーターにアクセスできない場合でも、練習してコマンドに慣れるための Cisco デバイス シミュレーターが複数ダウンロード可能です。
常にセキュリティを最優先にしてください:
- Cisco デバイスにアクセスできる人を制限しましょう。
- すべてのアカウントが暗号化された長いパスワードを使用するようにしてください。
- ロールを割り当てる際は、最小権限の原則を徹底してください。
- アクセス制御リストを作成して、さまざまなトラフィックの送信元と種類を制限します。
- ログを有効にし、サードパーティの監視ソリューションを使用して、構成が誤ってまたは悪意をもって変更された場合にアラートを受け取れるようにします。
Netwrix Auditor for Network Devices
設定変更、ログオン試行、ハードウェアの問題に関する洞察で、Cisco デバイスの監査を効率化
無料の20日間トライアルをダウンロード共有する