はじめての Cisco C841M ルータ: 初期設定


私はネットワークエンジニアではないのだが、勉強用に Cisco C841M J シリーズ(Cisco Start ギガビット対応 VPN ルータ)を個人で購入した。Cisco 製品は主に業務向けで高価なイメージが強かったが、この製品は Amazon.co.jp で 10,000 円程度で購入することができる。

目的

  • Cisco IOS CLI の基本的な操作方法について学ぶ。
  • 家庭内 LAN からインターネットに接続できるようにする。

前提条件

  • 今回コンソールケーブルは購入しなかったため、telnet によりルータに接続し設定を行う。
  • 本製品には Web 管理画面が組み込まれているが、評判が悪いし勉強にならないので今回は使用しない。

初回ログインとユーザーの作成

ルータの電源を投入したら telnet コマンドによりルータに接続できる(本製品の初期 IP アドレスは 10.10.10.1)。

telnet 10.10.10.1

ユーザー名 cisco 、パスワード cisco を入力して Cisco IOS CLI にログインする。なお、IOS は Internetwork Operating System の略語であるらしい。Apple の iOS とは無関係である。初回ログインに成功すると以下のメッセージが表示される。

% Password expiration warning.
-----------------------------------------------------------------------

Cisco Configuration Professional (Cisco CP) is installed on this device
and it provides the default username "cisco" for  one-time use. If you have 
already used the username "cisco" to login to the router and your IOS image 
supports the "one-time" user option, then this username has already expired. 
You will not be able to login to the router with this username after you exit 
this session.

It is strongly suggested that you create a new username with a privilege level 
of 15 using the following command.

username <myuser> privilege 15 secret 0 <mypassword>

Replace <myuser> and <mypassword> with the username and password you 
want to use.

-----------------------------------------------------------------------

yourname#

新しいユーザーを作成するように促すメッセージとプロンプトが表示される。ここで、メッセージの指示に従い username ... コマンドを実行してもエラーになる。ルータの設定を変更するためには Configuration Mode と呼ばれるモードに移行しなければならない。Configuration Mode に移行するには configure terminal コマンドを実行する。続けて、新しいユーザー admin を作成する。Configuration Mode を終了するには exit コマンドを実行する。

yourname#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
yourname(config)#username admin privilege 15 secret 0 passw0rd
yourname(config)#exit

reload コマンドを実行するとルータが再起動する。

yourname#reload

System configuration has been modified. Save? [yes/no]: yes
Building configuration...
[OK]
Proceed with reload? [confirm]

参考)Cisco IOS ソフトウェアとは

ホスト名の変更と設定の永続化

Configuration Mode で hostname コマンドによりルータのホスト名を設定することができる。ホスト名はプロンプトにも表示される。ここではホスト名を C841M に設定した。

yourname#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
yourname(config)#hostname C841M
C841M(config)#exit

このままの状態ではルータを再起動すると設定は元に戻ってしまう。設定を永続化させるためには copy running-config startup-config コマンドを実行する。現在の設定を起動時の設定に反映させるイメージで分かりやすい。なお、このコマンドは多くの場合 copy run start と省略される。このコマンドに限らず、Cisco IOS CLI ではコマンドを構成する各単語について、候補が 1 個に絞れるまで入力されていれば、残りの部分は省略できるようだ。例えば、configure terminalconf t と書いても同じことである。

C841M#copy running-config startup-config
Destination filename [startup-config]? 
Building configuration...
[OK]

参考)Cisco IOS - コンフィグレーションの管理

設定のバックアップ

本体背面の USB ポートに USB メモリを挿しこみ、format コマンドでフォーマットを実行する。

C841M#format usbflash0:
Format operation may take a while. Continue? [confirm]
Format operation will destroy all data in "usbflash0:".  Continue? [confirm]

Primary Partition created...Size 3289 MB

Drive communication & 1st Sector Write OK...

FAT32 DOS signature not found in boot sector, found 00:00
FAT32 DOS signature not found in boot sector, found 00:00
Format: All system sectors written. OK...

Format: Total sectors in formatted partition: 6736352
Format: Total bytes in formatted partition: 3449012224
Format: Operation completed successfully.

Format of usbflash0: complete

ルータが認識しているファイルシステムの一覧は show file system コマンドにより確認できる。

C841M#show file system
File Systems:

       Size(b)       Free(b)      Type  Flags  Prefixes
             -             -    opaque     rw   archive:
             -             -    opaque     rw   system:
             -             -    opaque     rw   tmpsys:
*   1950683136    1881706496      disk     rw   sdflash: flash:#
             -             -    opaque     rw   null:
             -             -   network     rw   tftp:
        262136        247176     nvram     rw   nvram:
             -             -    opaque     wo   syslog:
             -             -    opaque     rw   xmodem:
             -             -    opaque     rw   ymodem:
             -             -   network     rw   rcp:
             -             -   network     rw   http:
             -             -   network     rw   ftp:
             -             -   network     rw   scp:
             -             -    opaque     ro   tar:
             -             -   network     rw   https:
             -             -    opaque     ro   cns:
             -             -    opaque     rw   security:
    3442262016    3442257920  usbflash     rw   usbflash0:

ルータ本体のフラッシュメモリに保存されているルータのプログラム(バイナリ)flash:c800m-universalk9-mz.SPA.155-3.M4a.bin と現在の起動設定 startup-config を USB メモリ(usbflash0)にコピーする。

C841M#copy flash:c800m-universalk9-mz.SPA.155-3.M4a.bin usbflash0:
Destination filename [c800m-universalk9-mz.SPA.155-3.M4a.bin]? 
58997820 bytes copied in 56.068 secs (1052255 bytes/sec)

C841M#copy startup-config usbflash0:customer-config.20181124
Destination filename [customer-config.20181124]? 
3770 bytes copied in 0.688 secs (5480 bytes/sec)

USB メモリの内容を show usbflash0: コマンドにより確認すると、確かにコピーされていることがわかる。

C841M#show usbflash0: 
-#- --length-- -----date/time------ path
1     58997820 Nov 23 2018 15:18:56 +00:00 c800m-universalk9-mz.SPA.155-3.M4a.bin
2         3770 Nov 23 2018 15:20:26 +00:00 customer-config.20181124

3383255040 bytes available (59006976 bytes used)

WAN 側インターフェースの設定

現在のネットワークインターフェースの状態は show ip interface brief コマンドにより確認できる。

C841M#show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
GigabitEthernet0/0         unassigned      YES unset  down                  down    
GigabitEthernet0/1         unassigned      YES unset  up                    up      
GigabitEthernet0/2         unassigned      YES unset  down                  down    
GigabitEthernet0/3         unassigned      YES unset  down                  down    
GigabitEthernet0/4         unassigned      YES NVRAM  administratively down down    
GigabitEthernet0/5         unassigned      YES NVRAM  administratively down down    
Vlan1                      10.10.10.1      YES NVRAM  up                    up  

GigabitEthernet0/1 ポートに LAN ケーブルを接続して telnet 通信を行なっているため、GigabitEthernet0/1 のみ Status が up になっている。他のポートには LAN ケーブルを接続していないが、これより GigabitEthernet0/4 ポートを WAN 側機器(VDSL モデム)と接続する。このモデムはルータ機能を内蔵しており、192.168.1.0/24 のネットワークを形成しているため、GigabitEthernet0/4 ポートには、このネットワークから IP アドレス 192.168.1.21 を割り当てたい。

C841M(config)#interface gigabitethernet 0/4
C841M(config-if)#ip address 192.168.1.21 255.255.255.0
C841M(config-if)#no shutdown
C841M(config-if)#exit

GigabitEthernet0/4 ポートに IP アドレス 192.168.1.21 が割り当てられた。

C841M#show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
GigabitEthernet0/0         unassigned      YES unset  down                  down    
GigabitEthernet0/1         unassigned      YES unset  up                    up      
GigabitEthernet0/2         unassigned      YES unset  down                  down    
GigabitEthernet0/3         unassigned      YES unset  down                  down    
GigabitEthernet0/4         192.168.1.21    YES manual up                    up      
GigabitEthernet0/5         unassigned      YES NVRAM  administratively down down    
Vlan1                      10.10.10.1      YES NVRAM  up                    up  

この設定により VDSL モデム(192.168.1.1)に対して ping が通るようになる。

C841M#ping 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms

ルーティングの設定

現在のルーティングテーブルの設定は show ip route コマンドにより確認できる。

C841M#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       a - application route
       + - replicated route, % - next hop override, p - overrides from PfR

Gateway of last resort is not set

      10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C        10.10.10.0/25 is directly connected, Vlan1
L        10.10.10.1/32 is directly connected, Vlan1
      192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.1.0/24 is directly connected, GigabitEthernet0/4
L        192.168.1.21/32 is directly connected, GigabitEthernet0/4

デフォルトゲートウェイとして 192.168.1.1 を設定する。

C841M(config)#ip routing
C841M(config)#ip route 0.0.0.0 0.0.0.0 192.168.1.1

デフォルトゲートウェイとして 192.168.1.1 が設定された。

C841M#show ip route
Gateway of last resort is 192.168.1.1 to network 0.0.0.0

S*    0.0.0.0/0 [1/0] via 192.168.1.1
      10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
C        10.10.10.0/25 is directly connected, Vlan1
L        10.10.10.1/32 is directly connected, Vlan1
      192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C        192.168.1.0/24 is directly connected, GigabitEthernet0/4
L        192.168.1.21/32 is directly connected, GigabitEthernet0/4

この設定によりインターネット経由の ping が通るようになる。

C841M#ping 216.58.197.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 216.58.197.4, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/18/28 ms

さらに、ルータの LAN 側に接続したホストがインターネットと通信できるようにするために、NAT 変換の設定を追加する。

C841M(config)#ip nat inside source list 23 interface gigabitethernet 0/4 overload
C841M(config)#interface gigabitethernet 0/4
C841M(config-if)#ip nat outside
C841M(config-if)#exit

DNS の設定

ルータの DNS 機能を有効にする。問い合わせ先として WAN 側機器(VDSL モデム)の IP アドレス(192.168.1.1)を指定した。

C841M(config)#ip dns server
C841M(config)#ip domain lookup
C841M(config)#ip name-server 192.168.1.1

DHCP の設定

DHCP 機能を有効化し IP アドレスなどの接続情報をホストに提供できるようにする。ここでは 10.10.10.1 〜 10.10.10.63 の IP アドレスを DHCP の割当範囲から除外している。IP アドレスの有効期間は 2 日間とした。

C841M(config)#no ip dhcp excluded-address 10.10.10.1
C841M(config)#ip dhcp excluded-address 10.10.10.1 10.10.10.63
C841M(config)#ip dhcp pool ccp-pool
C841M(dhcp-config)#dns-server 10.10.10.1
C841M(dhcp-config)#lease 2
C841M(dhcp-config)#exit

なお、DHCP による IP アドレスの割当状態は show ip dhcp binding コマンドにより確認できる。

C841M#show ip dhcp binding
Bindings from all pools not associated with VRF:
IP address          Client-ID/                Lease expiration        Type
                Hardware address/
                User name
10.10.10.65         0123.4567.89ab.cdef     Nov 27 2018 02:26 AM    Automatic
10.10.10.66         0123.4567.89ab.cdef     Nov 27 2018 02:26 AM    Automatic
10.10.10.67         0123.4567.89ab.cdef     Nov 26 2018 06:56 AM    Automatic

タイムゾーンと時刻同期設定

ルータのタイムゾーンを Asia/Tokyo に設定し、NTP サーバとして asia.pool.ntp.org を使用するよう設定する。

C841M(config)#clock timezone JST 9
C841M(config)#ntp server asia.pool.ntp.org

現在時刻を表示するには show clock コマンドを実行する。

C841M#show clock
*14:09:37.023 JST Sun Nov 25 2018

その他の設定

冒頭でも述べたように本製品には Web 管理画面が組み込まれているのだが、不要なので無効化する。

C841M(config)#no ip http server
C841M(config)#no ip http secure-server

設定の保存

設定を終えたら copy run start を実行することを忘れずに。

次回はルータのファームウェアアップデートを行う。