LoginSignup
3
4

More than 5 years have passed since last update.

SoftLayerとVyOSでネットワークの基礎を勉強4-(IPsecVPN LAN間接続編)

Posted at

1. はじめに

今回は、VyOSを使ってInternet-VPN LAN間接続を行います。使用するプロトコルは、よく利用されているIPsecです。

2. IPSecについて

2-1. VPNの種類

VPNは、トンネリング・暗号化の機能で構成されています。

トンネリングプロトコルの種類は、PPTP, L2F, L2TP, GRE, IPsec があり、
暗号化プロトコルは、IPsecです。
この2つを組み合わせて、VPN通信を行っています。

トンネリングをIPsec、暗号化をIPsecで行えば、IPsecだけで完結すると思われますが、IPsecでできないところを別のトンネリングプロトコルでカバーする必要があります。
例えば、IPsecではできないマルチキャスト環境の場合、トンネリングをGRE、暗号化をIPsecの組み合わせで通信設定を行います。(GRE over IPsec)

2-2. IPSecの構成

2-2-1. IPSecのプロトコル

IPsecはAH, ESP, IKE等のプロトコルから構成されています。
ただ、ESPにはAHの機能である”改ざん防止”機能が含まれているので、AHを使用せず、ESPとIKEのみで構成します。
・AH(Authentication Header)
   パケット改ざん防止のための認証
・ESP(Encapsulated Security Payload)
   パケット改ざん防止のための認証
   ペーロール部分(ユーザーデータ)の暗号化
・IKE(Internet Key Exchange)
   鍵の交換を安全に行う

2-2-2. IPSecの通信モード

ほとんどの構成は、ホストそれぞれに設定する必要のないトンネルモードが使われる。
・トランスポートモード ---- ホスト間でのIPsec-VPN
・トンネルモード ---- VPNゲートウェイ間でのIPsec-VPN

2-2-3. VPNゲートウェイ間でのコネクション

VPNゲートウェイ間の接続(コネクション)をSA(Security Association)といい、片方通行のトンネルで送用と受信用のSAがの合計2つ作られます。
SAの中身はIPsecのパラメータです。
パラメータとしては、プロトコル、IPsec通信モード、暗号化方式、その暗号鍵
認証、認証鍵などがあります。
 SAは、IKE(鍵交換プロトコル)を使用して生成します。
生成はフェーズ1とフェーズ2のステップがあります。
・IKEフェーズ1:各種パラメータを交換しISAKMP SAを生成。
・IKEフェーズ2:ISAKMP SA上で各種パラメータを交換してIPsec SAを生成。

3. 構成について

 SoftLayerの東京ロケーションとシンガポールロケーションそれぞれにVyOS(IPsec用)とWindows2012R2を構築し、Windowsのリモートデスクトップで接続確認を行います。
01.png
02.png

4. 構築手順

03.png

5. 構築

5-1. ①VLANスパニングをOFF

SoftLayerのポータルで操作します。
「ネットワーク」⇒「IP管理」⇒「VLAN」
04.png
「スパン」 をクリック。
05.png
「オフ」 をチェック。
これで、スパンニングがオフになりました。
※テスト終わりましたら、ONに戻してください。

5-2. ② vyos-TOK(VyOS)の基本設定

VyOSの導入は省略します。

(参考情報)・VyOS導入
「SoftLayer仮想サーバにVyOSをインストールしました」
http://qiita.com/Mitsu-Murakita/items/d793250566a8e9f3562b >

(1) IP Address(PrivateとPublic)
(2) SSH
(3) Gateway Address
(4) DNS
(5) Domain Name
(6) Host Name
(7) Static route
(8) Time Server
(9) Time Zone
を設定します。
※説明しやすいように行番号(xxx)をつけてますが、実際に登録する際は行番号を入力しないでください。

vyos-TOK基本設定
(001)  interfaces {
(002)      ethernet eth0 {
(003)          address 10.132.52.225/26
(004)          duplex auto
(005)          hw-id 06:65:fa:44:1c:fb
(006)          smp_affinity auto
(007)          speed auto
(008)      }
(009)      ethernet eth1 {
(010)          address 161.202.236.157/29
(011)          duplex auto
(012)          hw-id 06:b1:22:00:62:82
(013)          smp_affinity auto
(014)          speed auto
(015)      }
(016)      loopback lo {
(017)      }
(018)  }
(019)  protocols {
(020)      static {
(021)          route 10.0.0.0/8 {
(022)              next-hop 10.132.52.193 {
(023)              }
(024)          }
(025)      }
(026)  }
(027)  service {
(028)      ssh {
(029)          port 22
(030)      }
(031)  }
(032)  system {
(033)      config-management {
(034)          commit-revisions 20
(035)      }
(036)      console {
(037)          device hvc0 {
(038)              speed 9600
(039)          }
(040)          device ttyS0 {
(041)              speed 9600
(042)          }
(043)      }
(044)      domain-name softlayer.com
(045)      gateway-address 161.202.236.153
(046)      host-name vyos-TOK
(047)      login {
(048)          user vyos {
(049)              authentication {
(050)                  encrypted-password xxxxxxxxxxxxxxxxxxxxx
(051)                  plaintext-password ""
(052)              }
(053)              level admin
(054)          }
(055)      }
(056)      name-server 10.0.80.11
(057)      name-server 10.0.80.12
(058)      ntp {
(059)          server time.service.networklayer.com {
(060)          }
(061)      }
(062)      package {
(063)          auto-sync 1
(064)          repository community {
(065)              components main
(066)              distribution helium
(067)              password ""
(068)              url http://packages.vyos.net/vyos
(069)              username ""
(070)          }
(071)      }
(072)      syslog {
(073)          global {
(074)              facility all {
(075)                  level notice
(076)              }
(077)              facility protocols {
(078)                  level debug
(079)              }
(080)          }
(081)      }
(082)      time-zone Asia/Tokyo
(083)  }

◆ (001)-(018) IPアドレス関連の設定
プライベートアドレス:address 10.132.52.225/26
パブリックアドレス:address 161.202.236.157/29
eth0とeth1:duplex auto、smp_affinity auto、speed auto を設定
◆ (019)-(026) Static routeの設定
プライベートネットワークのゲートウェイ10.132.52.193を設定
◆ (027)-(031) SSHの設定
ポート22を設定
◆ (044)-(044) ドメイン名の設定
softlayer.comを設定
◆ (045)-(045) Gateway Addressの設定
パブリックネットワークのゲートウェイ161.202.236.153を設定
◆ (046)-(046) ホスト名の設定
ホスト名vyos-TOKを設定
◆ (056)-(057) DNSの設定
SoftLayerのDNS 10.0.80.11、10.0.80.12を設定
◆ (058)-(061) タイムサーバーの設定
SoftLayerのタイムサーバーtime.service.networklayer.comを設定
◆ (081)-(083) タイムゾーンの設定
Asia/Tokyoを設定

5-3. ③ vyos-SNG(VyOS)の基本設定

vyos-TOK01と同じ手順で設定します。基本設定と違う箇所は、
(003) address 10.132.52.225/26
(005) hw-id 06:65:fa:44:1c:fb
(010) address 161.202.236.157/29
(012) hw-id 06:b1:22:00:62:82
(022) next-hop 10.132.52.193 {
(045) gateway-address 161.202.236.153
(046) host-name vyos-TOK
です。尚、hw-idは自動で設定されているはずですので、実際変更するのは
(003-SNG) address 10.116.128.215/26
(010-SNG) address 161.202.1.244/29
(022-SNG) next-hop 10.116.128.193
(045-SNG) gateway-address 161.202.1.241
(046-SNG) host-name vyos-SNG

です。

vyos-SNG基本設定
(001-SNG)  interfaces {
(002-SNG)      ethernet eth0 {
(003-SNG)          address 10.116.128.215/26
(004-SNG)          duplex auto
(005-SNG)          hw-id 06:a7:8c:9d:4e:da
(006-SNG)          smp_affinity auto
(007-SNG)          speed auto
(008-SNG)      }
(009-SNG)      ethernet eth1 {
(010-SNG)          address 161.202.1.244/29
(011-SNG)          duplex auto
(012-SNG)          hw-id 06:17:fe:9b:9b:3e
(013-SNG)          smp_affinity auto
(014-SNG)          speed auto
(015-SNG)      }
(016-SNG)      loopback lo {
(017-SNG)      }
(018-SNG)  }
(019-SNG)  protocols {
(020-SNG)      static {
(021-SNG)          route 10.0.0.0/8 {
(022-SNG)              next-hop 10.116.128.193 {
(023-SNG)              }
(024-SNG)          }
(025-SNG)      }
(026-SNG)  }
(027-SNG)  service {
(028-SNG)      ssh {
(029-SNG)          port 22
(030-SNG)      }
(031-SNG)  }
(032-SNG)  system {
(033-SNG)      config-management {
(034-SNG)          commit-revisions 20
(035-SNG)      }
(036-SNG)      console {
(037-SNG)          device hvc0 {
(038-SNG)              speed 9600
(039-SNG)          }
(040-SNG)          device ttyS0 {
(041-SNG)              speed 9600
(042-SNG)          }
(043-SNG)      }
(044-SNG)      domain-name softlayer.com
(045-SNG)      gateway-address 161.202.1.241
(046-SNG)      host-name vyos-SNG
(047-SNG)      login {
(048-SNG)          user vyos {
(049-SNG)              authentication {
(050-SNG)                  encrypted-password xxxxxxxxxxxxxxxxxxx
(051-SNG)                  plaintext-password ""
(052-SNG)              }
(053-SNG)              level admin
(054-SNG)          }
(055-SNG)      }
(056-SNG)      name-server 10.0.80.11
(057-SNG)      name-server 10.0.80.12
(058-SNG)      ntp {
(059-SNG)          server time.service.networklayer.com {
(060-SNG)          }
(061-SNG)      }
(062-SNG)      package {
(063-SNG)          auto-sync 1
(064-SNG)          repository community {
(065-SNG)              components main
(066-SNG)              distribution helium
(067-SNG)              password ""
(068-SNG)              url http://packages.vyos.net/vyos
(069-SNG)              username ""
(070-SNG)          }
(071-SNG)      }
(072-SNG)      syslog {
(073-SNG)          global {
(074-SNG)              facility all {
(075-SNG)                  level notice
(076-SNG)              }
(077-SNG)              facility protocols {
(078-SNG)                  level debug
(079-SNG)              }
(080-SNG)          }
(081-SNG)      }
(082-SNG)      time-zone Asia/Tokyo
(083-SNG)  }

5-4. ④ vyos-TOK(VyOS)のIPsec設定

IPsec接続に最低限必要な設定を行います。
尚、未設定の値にはデフォルト値が使用されます。

(1)パブリックインターフェースeth1のIPsecVPN有効化
(2)IKEで利用する暗号化用の暗号化アルゴリズムと認証用ハッシュアルゴリズムの定義
(3)ESPで利用する暗号化用の暗号化アルゴリズムと認証用ハッシュアルゴリズムの定義
(4)vyos-SNGへの接続設定

5-4-1. (1)パブリックインターフェースeth1のIPsecVPN有効化

eth1のIPsecVPN有効化
set vpn ipsec ipsec-interface interface eth1

IPsecVPN通信にパブリックインターフェースeth1のを使用します。

5-4-2. (2)IKEで利用する暗号化用の暗号化アルゴリズムと認証用ハッシュアルゴリズムの定義

IKEの設定
set vpn ipsec ike-group IKE-TOK
set vpn ipsec ike-group IKE-TOK proposal 1 encryption aes256
set vpn ipsec ike-group IKE-TOK proposal 1 hash sha1
set vpn ipsec ike-group IKE-TOK lifetime 3600

暗号化アルゴリズムや認証アルゴリズムを双方でネゴシエーションするために、複数の組み合わせを定義できますが、ここでは1つ(proposal 1)だけ定義しています。
暗号化をAES256、ハッシュをSHA1とし、ライフタイムを3600としました。

5-4-3. (3)ESPで利用する暗号化用の暗号化アルゴリズムと認証用ハッシュアルゴリズムの定義

ESPの設定
set vpn ipsec esp-group ESP-TOK
set vpn ipsec esp-group ESP-TOK proposal 1 encryption aes256
set vpn ipsec esp-group ESP-TOK proposal 1 hash sha1
set vpn ipsec esp-group ESP-TOK lifetime 1800

暗号化アルゴリズムや認証アルゴリズムを双方でネゴシエーションするために、複数の組み合わせを定義できますが、ここでは1つ(proposal 1)だけ定義しています。
暗号化をAES256、ハッシュをSHA1とし、ライフタイムを1800としました。

5-4-4. (4)vyos-SNGへの接続設定

vyos-SNGへの接続設定
set vpn ipsec site-to-site peer 161.202.1.244
set vpn ipsec site-to-site peer 161.202.1.244 authentication mode pre-shared-secret
set vpn ipsec site-to-site peer 161.202.1.244 authentication pre-shared-secret test_key_1
set vpn ipsec site-to-site peer 161.202.1.244 default-esp-group ESP-TOK
set vpn ipsec site-to-site peer 161.202.1.244 ike-group IKE-TOK
set vpn ipsec site-to-site peer 161.202.1.244 local-address 161.202.236.157
set vpn ipsec site-to-site peer 161.202.1.244 tunnel 1 local prefix 10.132.52.192/26
set vpn ipsec site-to-site peer 161.202.1.244 tunnel 1 remote prefix 10.116.128.192/26

IKEフェーズ1でのvyos-SNGとの認証方式を「Pre-Shared Key」とし、キーを”test_key_1”としました。

5-4-5. vyos-TOK(VyOS)の全設定

vyos-TOKの全設定
 interfaces {
     ethernet eth0 {
         address 10.132.52.225/26
         duplex auto
         hw-id 06:65:fa:44:1c:fb
         smp_affinity auto
         speed auto
     }
     ethernet eth1 {
         address 161.202.236.157/29
         duplex auto
         hw-id 06:b1:22:00:62:82
         smp_affinity auto
         speed auto
     }
     loopback lo {
     }
 }
 protocols {
     static {
         route 10.0.0.0/8 {
             next-hop 10.132.52.193 {
             }
         }
     }
 }
 service {
     ssh {
         port 22
     }
 }
 system {
     config-management {
         commit-revisions 20
     }
     console {
         device hvc0 {
             speed 9600
         }
         device ttyS0 {
             speed 9600
         }
     }
     domain-name softlayer.com
     gateway-address 161.202.236.153
     host-name vyos-TOK
     login {
         user vyos {
             authentication {
                 encrypted-password xxxxxxxxxxxxxxxxxx
                 plaintext-password ""
             }
             level admin
         }
     }
     name-server 10.0.80.11
     name-server 10.0.80.12
     ntp {
         server time.service.networklayer.com {
         }
     }
     package {
         auto-sync 1
         repository community {
             components main
             distribution helium
             password ""
             url http://packages.vyos.net/vyos
             username ""
         }
     }
     syslog {
         global {
             facility all {
                 level notice
             }
             facility protocols {
                 level debug
             }
         }
     }
     time-zone Asia/Tokyo
 }
 vpn {
     ipsec {
         esp-group ESP-TOK {
             compression disable
             lifetime 1800
             mode tunnel
             pfs enable
             proposal 1 {
                 encryption aes256
                 hash sha1
             }
         }
         ike-group IKE-TOK {
             ikev2-reauth no
             key-exchange ikev1
             lifetime 3600
             proposal 1 {
                 encryption aes256
                 hash sha1
             }
         }
         ipsec-interfaces {
             interface eth1
         }
         site-to-site {
             peer 161.202.1.244 {
                 authentication {
                     mode pre-shared-secret
                     pre-shared-secret test_key_1
                 }
                 connection-type initiate
                 default-esp-group ESP-TOK
                 ike-group IKE-TOK
                 ikev2-reauth inherit
                 local-address 161.202.236.157
                 tunnel 1 {
                     allow-nat-networks disable
                     allow-public-networks disable
                     local {
                         prefix 10.132.52.192/26
                     }
                     remote {
                         prefix 10.116.128.192/26
                     }
                 }
             }
         }
     }
 }

5-5. ⑤ vyos-SNG(VyOS)のIPsec設定

vyos-SNGKの全設定
 interfaces {
     ethernet eth0 {
         address 10.116.128.215/26
         duplex auto
         hw-id 06:a7:8c:9d:4e:da
         smp_affinity auto
         speed auto
     }
     ethernet eth1 {
         address 161.202.1.244/29
         duplex auto
         hw-id 06:17:fe:9b:9b:3e
         smp_affinity auto
         speed auto
     }
     loopback lo {
     }
 }
 protocols {
     static {
         route 10.0.0.0/8 {
             next-hop 10.116.128.193 {
             }
         }
     }
 }
 service {
     ssh {
         port 22
     }
 }
 system {
     config-management {
         commit-revisions 20
     }
     console {
         device hvc0 {
             speed 9600
         }
         device ttyS0 {
             speed 9600
         }
     }
     domain-name softlayer.com
     gateway-address 161.202.1.241
     host-name vyos-SNG
     login {
         user vyos {
             authentication {
                 encrypted-password xxxxxxxxxxxxxxxxxxxxx
                 plaintext-password ""
             }
             level admin
         }
     }
     name-server 10.0.80.11
     name-server 10.0.80.12
     ntp {
         server time.service.networklayer.com {
         }
     }
     package {
         auto-sync 1
         repository community {
             components main
             distribution helium
             password ""
             url http://packages.vyos.net/vyos
             username ""
         }
     }
     syslog {
         global {
             facility all {
                 level notice
             }
             facility protocols {
                 level debug
             }
         }
     }
     time-zone Asia/Tokyo
 }
 vpn {
     ipsec {
         esp-group ESP-SNG {
             lifetime 1800
             proposal 1 {
                 encryption aes256
                 hash sha1
             }
             proposal 2 {
                 encryption 3des
                 hash md5
             }
         }
         ike-group IKE-SNG {
             lifetime 3600
             proposal 1 {
                 encryption aes256
                 hash sha1
             }
             proposal 2 {
                 encryption aes128
                 hash sha1
             }
         }
         ipsec-interfaces {
             interface eth1
         }
         site-to-site {
             peer 161.202.236.157 {
                 authentication {
                     mode pre-shared-secret
                     pre-shared-secret test_key_1
                 }
                 default-esp-group ESP-SNG
                 ike-group IKE-SNG
                 local-address 161.202.1.244
                 tunnel 1 {
                     local {
                         prefix 10.116.128.192/26
                     }
                     remote {
                         prefix 10.132.52.192/26
                     }
                 }
             }
         }
     }
 }

5-6. ⑥IPsec接続確認

VyOSのShowコマンドで確認します。
”show vpn ike sa"
”show vpn ipsec sa"

【vyos-TOK】
06.png

【vyos-SNG】
07.png

saのステータスは"up"ですので、IPsec-VPNの通信は確立されているのが確認できました。

5-7. ⑦ W2012R2-TOK(Windows)の設定

シンガポールDCネットワークへのスタティックルート設定

W2012R2-TOKでのStaticRoute設定
> route add -p 10.116.128.192 mask 255.255.255.192 10.132.52.225

5-8. ⑧ W2012R2-SNG(Windows)の設定

東京DCネットワークへのスタティックルート設定

W2012R2-SNGKでのStaticRoute設定
> route add -p 10.132.52.192 mask 255.255.255.192 10.116.128.215

5-9. ⑨ Windows2012Server間リモートデスクトップ接続確認

(1)W2012R2-TOKからW2012R2-SNGへリモートデスクトップ接続します。
08.png

(2)W2012R2-SNGからW2012R2-TOKへリモートデスクトップ接続します。
09.png

リモートデスクトップで接続が確認できました。

6. おわりに

当投稿のsite-to-site設定は、tunnelです。
もし、相手側に複数のセグメントが存在してルーティングする場合やtunnelを複数せっていする場合は、tunnel設定ではなく、vti (Virtual Tunnel Interface)で設定してください。

今回はIPsecの勉強ですので、基本的な設定でした。
他にも色々な設定がありますので、お試しださい。

set vpn ipsec esp-group ESP-TOK mode tunnel
set vpn ipsec esp-group ESP-TOK pfs enable

set vpn ipsec nat-traversal enable

set vpn ipsec site-to-site peer 161.202.1.244 connection-type initiate
set vpn ipsec site-to-site peer 161.202.1.244 default-esp-group ESP-TOK

set vpn ipsec site-to-site peer 161.202.1.244 tunnel 1 allow-nat-networks disable
set vpn ipsec site-to-site peer 161.202.1.244 tunnel 1 allow-public-networks disable

set vpn ipsec ike-group IKE-TOK dead-peer-detection action 'restart'
set vpn ipsec ike-group IKE-TOK dead-peer-detection interval '30'
set vpn ipsec ike-group IKE-TOK dead-peer-detection timeout '30'
set vpn ipsec auto-update '60'

set vpn ipsec site-to-site peer 161.202.1.244 authentication id @TOK
set vpn ipsec site-to-site peer 161.202.1.244 authentication remote-id @SNG

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4