カテゴリ:

今回はSCPを利用したファイルの転送を設定します。以前のIOSはftp-serverコマンドを利用してFTPサーバとして稼動させることが出来ましたが、現在は通常利用出来ません。代わりにより安全なSCPを使います。SCPはSSHの機能の一つで、暗号化した状態でファイルを転送しますのでFTPより安全です。

SCPを利用するには、SSHが必要です。まず、SSHを有効にします。

R1(config)#ip domain-name example.com
R1(config)#crypto key generate rsa modulus 1024

F0/0はR2(12.12.12.2)に接続されており、F0/1はLANでLinuxサーバと接続されています。

R1(config)#do sh ip int b
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            12.12.12.1      YES manual up                    up
FastEthernet0/1            192.168.0.100   YES manual up                    up

まず認証のためにAAAを有効にします。

R1(config)#aaa new-model

AAAでauthentication loingとauthorization execを有効します。今回はローカル認証を利用します。

R1(config)#aaa authentication login default local
R1(config)#aaa authorization exec default local

認証に使うユーザを作成します。ユーザ名とパスワード共、ciscoにしました。privilegeの設定に注意が必要です。レベルによってファイルの保存がエラーになります。

R1(config)#username cisco privilege 15 secret cisco

最後にip scp server enableでSCPを有効にします。SSHを有効にしただけではSCPは利用できません。

R1(config)# ip scp server enable

接続の確認のためにデバグを有効します。

R1#debug ip scp
Incoming SCP debugging is on

まずLinuxにあるファイル(scp-test.txt)をR1に転送します。ここではルータのflashに保存を実行しています。ファイル名(from_linux)まで指定します。

$ cat scp-test.txt
File from Linux to IOS.
$ scp scp-test.txt cisco@192.168.0.100:flash:from_linux
The authenticity of host '192.168.0.100 (192.168.0.100)' can't be established.
RSA key fingerprint is 1d:a4:f5:d8:f8:88:6c:03:41:2c:b7:e2:d7:da:d1:51.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.100' (RSA) to the list of known hosts.
Password: ← パスワードを入力
scp-test.txt                                  100%   24     0.0KB/s   00:00

R1のログを確認し、届いたファイルをmoreコマンドで表示しています。

R1#
Apr 25 07:53:26.823: SCP: [22 -> 192.168.0.180:34063] send <OK>
Apr 25 07:53:26.843: SCP: [22 <- 192.168.0.180:34063] recv C0644 24 scp-test.txt
Apr 25 07:53:26.855: SCP: [22 -> 192.168.0.180:34063] send <OK>
Apr 25 07:53:26.875: SCP: [22 <- 192.168.0.180:34063] recv 24 bytes
Apr 25 07:53:27.071: SCP: [22 <- 192.168.0.180:34063] recv <OK>
Apr 25 07:53:27.075: SCP: [22 -> 192.168.0.180:34063] send <OK>
Apr 25 07:53:27.079: SCP: [22 <- 192.168.0.180:34063] recv <EOF>
R1#
R1#dir flash:
Directory of flash:/

   12  -rw-          24  Apr 25 2011 16:53:27 +09:00  from_linux

16777212 bytes total (16499660 bytes free)
R1#more flash:from_linux
File from Linux to IOS.

IOSからSCPを利用するにはcopyコマンドを利用します。下記はrunning-configをコピーする例です。

R2#copy running-config scp://cisco@12.12.12.1/
Address or name of remote host [12.12.12.1]?
Destination username [cisco]?
Destination filename [r2-confg]?
Writing r2-confg
Password:
← パスワードを入力
!
1289 bytes copied in 14.320 secs (90 bytes/sec)

転送されていることが分かります。

R1#dir flash:
Directory of flash:/
〜略〜
   15  -rw-        1289  Apr 25 2011 17:00:09 +09:00  r2-confg
〜略〜
R1#more flash:r2-confg
!
! Last configuration change at 15:13:53 JST Mon Apr 25 2011
!
version 12.4
〜略〜