2016年頃に初めてVPN接続でクラウド使い始めたときの記録。

ルータでVPN接続する仕組みを勉強したかったので、けっこう頑張ってやってたけど、2か月もせずGoogle cloudに引っ越した。

業務利用ではawsが選ばれるんだろうけど、個人的にはGoogle cloudのほうが扱いやすい。

ルータはyamaha rtx1200。tera termで接続できるのは知ってたけど、どんなふうに設定するのか、どう扱えばいいのかという知識は皆無。

ネットにも情報はあるけど1冊本買って昼休みに勉強した。

設定はコマンドラインが多いのに、ブラウザで設定もできるっていう敷居の低さに飛びついて勉強し始めた。

一般家庭のルータが1万円程度なのに対し、発売されて数か月以内に7万円弱で買ったから授業料としてはけっこう高い。

マンションが契約しているプロバイダに依頼してルータのMACアドレスに紐づくよう固定IPも取った。なんと無料で固定IP提供してくれる。

とても助かる。

VPC作成

VPCとはawsの中のネットワーク。最初にこれを作っておいて、この中にec2インスタンスを作るらしい。

外部からどのポートでの接続を許可する、なんて設定を入れて初めて接続できるようになる。

まずは左下のネットワーキングにあるVPCを選ぶ

aws

「VPCウィザードの開始」を選択

aws

step1:プライベートのサブネットへ自前環境と接続できるタイプを選択

aws

step2:特に変更せず

aws

step3:VPN接続する自前環境の固定IPと名前を入力し、ルーティングに「動的」を選択してから「VPCの作成」を押して数分待つ

aws

作成完了してOK

aws

VPCが作成されたことを確認してから、左下の「VPN接続」を選ぶ

aws

「設定のダウンロード」を選択する

aws

ベンダーをyamahaにすると自動的にプラットフォームとソフトウェアが入るが、rev10.1.16+とある

aws

作業時のローカル環境のファームウェア状態

aws

公開バージョンの確認

aws

公開されているファームウェアのバージョン

設定例のページにある ファームウェアバージョン

aws

ダウンロードした結果をルータでコマンド実行

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# tunnel select 2 
# ipsec ike encryption 2 aes-cbc
# ipsec ike group 2 modp1024
# ipsec ike hash 2 sha
# ipsec ike pre-shared-key 2 text (キー値)
# ipsec tunnel 201
# ipsec sa policy 201 2 esp aes-cbc  sha-hmac
# ipsec ike duration ipsec-sa 2 3600
# ipsec ike pfs 2 on
# ipsec tunnel outer df-bit clear
# ipsec ike keepalive use 2 on dpd 10 3
# ipsec ike local address 2 172.16.xx.xx
# ipsec ike remote address 2 52.197.xx.xx
# ip tunnel address 169.254.xx.xx/xx
# ip tunnel remote address 169.254.xx.xx
# ip tunnel tcp mss limit 1387
# tunnel enable 2
# tunnel select none
# ipsec auto refresh on
# bgp use on
# bgp autonomous-system 65000
# bgp neighbor 2 10124 169.254.xx.xx hold-time=30 local-address=169.254.xx.xx
# bgp import filter 2 equal 0.0.0.0/0
# bgp import 10124 static filter 2
# tunnel select 3 
# ipsec ike encryption 3 aes-cbc
# ipsec ike group 3 modp1024
# ipsec ike hash 3 sha
# ipsec ike pre-shared-key 3 text (キー値)
# ipsec tunnel 202
# ipsec sa policy 202 3 esp aes-cbc  sha-hmac
# ipsec ike duration ipsec-sa 3 3600
# ipsec ike pfs 3 on
# ipsec tunnel outer df-bit clear
# ipsec ike keepalive use 3 on dpd 10 3
# ipsec ike local address 3 172.16.xx.xx
# ipsec ike remote address 3 52.198.xx.xx
# ip tunnel address 169.254.xx.xx/xx
# ip tunnel remote address 169.254.xx.xx
# ip tunnel tcp mss limit 1387
# tunnel enable 3
# tunnel select none
# ipsec auto refresh on
# bgp use on
# bgp autonomous-system 65000
# bgp neighbor 3 10124 169.254.xx.xx hold-time=30 local-address=169.254.xx.xx
# bgp import filter 3 equal 0.0.0.0/0
# bgp import 10124 static filter 3
# bgp configure refresh
# save
セーブ中... CONFIG0 終了
# 

トンネルがつながった様子

aws

aws

以下、接続確認をrtx1210のコマンドラインで実行

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# show status tunnel 1
TUNNEL[1]: 
説明: 
  インタフェースの種類: L2TP
  トンネルインタフェースはL2TPで利用されています
  L2TPの状態はshow status ppコマンドとshow status l2tpコマンドで表示できます
# 
# show status tunnel 2
TUNNEL[2]: 
説明: 
  インタフェースの種類: IPsec
  トンネルインタフェースは接続されています
  開始: 2016/11/25 05:35:49
  通信時間: 23分28秒
  受信: (IPv4) 385 パケット [23641 オクテット]
        (IPv6) 0 パケット [0 オクテット]
  送信: (IPv4) 428 パケット [19393 オクテット]
        (IPv6) 0 パケット [0 オクテット]
# 
# show ipsec sa
Total: isakmp:2 send:2 recv:2

sa    sgw isakmp connection    dir  life[s] remote-id
----------------------------------------------------------------------------
1     2    -     isakmp        -    27367   52.68.xx.xx
2     3    -     isakmp        -    27367   52.193.xx.xx
3     2    1     tun[0002]esp  send 2169    52.68.xx.xx
4     2    1     tun[0002]esp  recv 2169    52.68.xx.xx
5     3    2     tun[0003]esp  send 2169    52.193.xx.xx
6     3    2     tun[0003]esp  recv 2169    52.193.xx.xx

# 
# show ipsec sa gateway 2 detail
SA[1] 寿命: 27262秒
自分側の識別子: 172.16.xx.xx
相手側の識別子: 52.68.xx.xx
プロトコル: IKE
アルゴリズム: AES-CBC, SHA-1, MODP 1024bit
SPI: b7 87 85 f2 45 32 1b 7e 4b d8 ab 0d 80 74 4a 2d 
鍵 : ** ** ** ** **  (confidential)   ** ** ** ** **
----------------------------------------------------

SA[3] 寿命: 2064秒
自分側の識別子: 172.16.xx.xx
相手側の識別子: 52.68.xx.xx
送受信方向: 送信
プロトコル: ESP (モード: tunnel)
アルゴリズム: AES-CBC (認証: HMAC-SHA)
SPI: 65 23 84 ac 
鍵 : ** ** ** ** **  (confidential)   ** ** ** ** **
----------------------------------------------------

SA[4] 寿命: 2064秒
自分側の識別子: 172.16.xx.xx
相手側の識別子: 52.68.xx.xx
送受信方向: 受信
プロトコル: ESP (モード: tunnel)
アルゴリズム: AES-CBC (認証: HMAC-SHA)
SPI: fa f0 06 7a 
鍵 : ** ** ** ** **  (confidential)   ** ** ** ** **
----------------------------------------------------

# 
# show ipsec sa gateway 3 detail
SA[2] 寿命: 27227秒
自分側の識別子: 172.16.xx.xx
相手側の識別子: 52.193.xx.xx
プロトコル: IKE
アルゴリズム: AES-CBC, SHA-1, MODP 1024bit
SPI: 97 fd c2 8e 19 59 84 e8 25 75 e4 78 c7 3a d0 db 
鍵 : ** ** ** ** **  (confidential)   ** ** ** ** **
----------------------------------------------------

SA[5] 寿命: 2029秒
自分側の識別子: 172.16.xx.xx
相手側の識別子: 52.193.xx.xx
送受信方向: 送信
プロトコル: ESP (モード: tunnel)
アルゴリズム: AES-CBC (認証: HMAC-SHA)
SPI: 9d f3 c5 03 
鍵 : ** ** ** ** **  (confidential)   ** ** ** ** **
----------------------------------------------------

SA[6] 寿命: 2029秒
自分側の識別子: 172.16.xx.xx
相手側の識別子: 52.193.xx.xx
送受信方向: 受信
プロトコル: ESP (モード: tunnel)
アルゴリズム: AES-CBC (認証: HMAC-SHA)
SPI: 0e 42 07 e2 
鍵 : ** ** ** ** **  (confidential)   ** ** ** ** **
----------------------------------------------------

# 
# show status bgp neighbor

BGP neighbor is 169.254.xx.xx, remote AS 10124, local AS 65000, external link

  BGP version 4, remote router ID 169.254.xx.xx
  BGP state = Established, up for 00:10:28
  Last read 00:00:08, hold time is 30, keepalive interval is 10 seconds
  Received 64 messages, 0 notifications, 0 in queue
  Sent 68 messages, 1 notifications, 0 in queue
  Connection established 1; dropped 0
  Last reset never
Local host: 169.254.xx.xx, Local port: 1029
Foreign host: 169.254.xx.xx, Foreign port: 179

BGP neighbor is 169.254.xx.xx, remote AS 10124, local AS 65000, external link
  BGP version 4, remote router ID 169.254.xx.xx
  BGP state = Established, up for 00:10:19
  Last read 00:00:09, hold time is 30, keepalive interval is 10 seconds
  Received 63 messages, 0 notifications, 0 in queue
  Sent 67 messages, 1 notifications, 0 in queue
  Connection established 1; dropped 0
  Last reset never
Local host: 169.254.xx.xx, Local port: 1030
Foreign host: 169.254.xx.xx, Foreign port: 179

# 
# show ip route
宛先ネットワーク    ゲートウェイ     インタフェース  種別  付加情報
default             10.88.200.1      LAN2(DHCP)    static  
10.0.0.0/16         169.254.xx.xx    TUNNEL[3]       BGP  path=10124
10.88.200.0/22      10.88.xx.xx          LAN2  implicit  
169.254.xx.xx/30   -                 TUNNEL[3]  implicit  
169.254.xx.xx/30    -                 TUNNEL[2]  implicit  
172.16.0.0/16       172.16.xx.xx           LAN1  implicit  
# 

接続確認できたらEC2でamazon linuxのサーバ作る

aws

aws

aws

適当に8GBで作ったのを後で後悔

aws

aws

本当はここで接続制限しておくが、後で実施

aws

aws

aws

aws

teratermのマクロを用意

pemファイルはawsコンソールから取得して保管しておく。

“/F"はウィンドウサイズや色設定なんかが入ったiniファイルをtera termの「設定」から作成・保存しておく。

awsなのでオレンジ色っぽいのにした。

1
2
3
4
5
6
7
8
9
;接続

connect '10.0.1.20 /ssh /1 /auth=publickey /passwd=gvis /user=ec2-user /keyfile=S:\smb\sc\connect\AWS\gvisDB.pem /F=S:\smb\sc\connect\teraIni\orange.ini'

wait "[ec2-user@"
sendln "df -h"

wait "[ec2-user@"
sendln "w"

known hostsへの追加確認

aws

接続確認OK!!!

aws

rootユーザのパスワードを設定してyum実行したり、普段使いのOSユーザ作ったりできる。

aws

セキュリティグループ設定しとく

aws

aws

作業用のOSユーザを作成

直接sshさせるため、ec2-userのホームディレクトリにある.sshフォルダをそのままコピーし、所有権を変更してsshできることを確認

aws