LoginSignup
22
20

More than 5 years have passed since last update.

SoftLayerとvyosでネットワークの基礎を勉強1-(トンネルGRE編)

Last updated at Posted at 2015-12-03

1. はじめに

 クラウドシステムの基盤構築を行う上で、ネットワークは重要な要素の一つです。学習する上で実機を使って行うほうが、理解が深まります。
ただ、必要な機材を準備すると費用と時間がかかりますが、SoftLayreを使って、安く短時間に実機で構築学習を行います。
(これがクラウドの良いところだです。)

今回は、基本としてGREの設定してみます。

2. GREについて

 GRE(Generic Routing Encapsulation)の前に、VPNについてを説明します。
VPN(Virtual Private Network)は文字通り、公衆ネットワーク(Internet)を介してプライベートネットワーク間を接続します。
ネットワークは、あたかも自分専用の回線として接続されますので、公衆ネットワーク経由でもセキュリティを高めてくれます。
 
そのVPNの仕組みで重要な要素は、
(1)トンネリング-----経路
(2)暗号化------------データ  です。
 
GREはトンネリングプロトコルのひとつで、他には
・Layer2トンネリングのL2F, PPTP, L2TP
・Layer3トンネリングのGRE, IPsec などがあります。
また、暗号化はIPsecのみですので、L2TP/IPsecのようにトンネリングと暗号化を組み合わせて利用します。

今回は、GREのトンネリングだけで暗号化は行いません。

3. 構成について

 SoftLayerのシンガポールと東京の2ロケーションをGRE(VyOS)で接続して、各ロケーションにデプロイしたWindows2012サーバ間でデータの送受信を行います。
注意点として、VLANスパニングをオフにして、2ロケーションのプライベートネットワークが接続されていない状態で確認テストを行います。
 また、VyOSの導入は下記情報などを参考にしてください。
QIITA「SoftLayer仮想サーバにVyOSをインストールしました」
http://qiita.com/Mitsu-Murakita/items/d793250566a8e9f3562b
03.png
05.png
06.png

4. 構築手順

07.png

5. 構築

 VyOSの基本的な操作について

VyOSには「一般モード」(プロンプト$)と「設定モード」(プロンプト#)があります。
モード変更は、
・「一般モード」から「設定モード」へ変更は”configure”コマンド
・「設定モード」から「一般モード」へ変更は"exit"コマンド です。
08.png
「一般モード」では、設定状態や動作状態が確認できます。
「設定モード」では、動作のための値が設定できます。
「設定モード」でよく使うコマンドは、
"set"-------値の入力
"delete"---値の削除
"discard"--入力した値の破棄(commit前なら有効)
"commit"--入力した値の有効化
"save"-----保存(saveしないで再起動すると、値が消えてしまいます。)
"show"----構成情報の表示

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

SoftLayerポータルでの操作です。
09.png
「Network」⇒「VLANs」⇒「Span」タグ

10.png
「Off」選択

以上で「VLANスパニングをOFF」完了です。
※テスト終わりましたら、ONに戻してください。

5-2. VyOS-TOK(VyOS)の設定

まず、Tokyo側から設定。
IPをまだ設定してないので、SoftLayerのKVM操作です。

VyOSの初期値は下記の通りです。

vyos初期値
interfaces {
    ethernet eth0 {
        hw-id 06:ce84:86:0a:e6
    }
    ethernet eth1 {
        hw-id 06:96:da:92:17:25
    }
    loopback lo {
    }
}
system {
    config-management {
        commit-revisions 20
    }
    console {
        device hvc0 {
            speed 9600
        }
        device ttyS0 {
            speed 9600
        }
    }
    login {
        user vyos {
            authentication {
                encrypted-password  
                plaintext-password ""
            }
            level admin
        }
    }
    ntp {
        server 0.pool.ntp.org {
        }
        server 1.pool.ntp.org {
        }
        server 2.pool.ntp.org {
        }
    }
    package {
        repository community {
            components main
            distribution helium
            url http://packages.vyos.net/vyos
        }
    }
    syslog {
        global {
            facility all {
                level notice
            }
            facility protocols {
                level debug
            }
        }
    }
}

この初期値に値を設定していきます。

IP(interface)の設定

ここでは、eth0がプライベート、eth1がパブリックです。

IP(interfaces)の設定
# set interfaces ethernet eth0 address 10.132.52.247/26 ⏎
# set interfaces ethernet eth1 address 161.202.91.38/28 ⏎
# commit ⏎
# save ⏎

下記3行は再起動後、自動的に追加されますが、ここでは明示的に設定します。
・duplex auto
・smp_affinity auto
・speed auto

IP(interfaces)の設定続き
# set interfaces ethernet eth0 duplex auto ⏎
# set interfaces ethernet eth1 duplex auto ⏎
# set interfaces ethernet eth0 smp_affinity auto ⏎
# set interfaces ethernet eth1 smp_affinity auto ⏎
# set interfaces ethernet eth0 speed auto ⏎
# set interfaces ethernet eth1 speed auto ⏎
# commit ⏎
# save ⏎

ssh(service)の設定

クライアントPCからssh接続できるようにします。

ssh(service)の設定
# set service ssh port 22 ⏎
# commit ⏎
# save ⏎

Gatewayアドレス(system)の設定

パブリックのゲートウェイアドレスを設定。

Gatewayアドレス(system)の設定
# set system gateway-address 161.202.91.33 ⏎
# commit ⏎
# save ⏎

DNS(system)の設定

SoftLayerのDNS、
・10.0.80.11
・10.0.80.12 を設定します。

DNS(system)の設定
# set system name-server 10.0.80.11 ⏎
# set system name-server 10.0.80.12 ⏎
# commit ⏎
# save ⏎

ドメイン名(system)の設定

ここではドメイン名を「softlayer.com」にしました。

ドメイン名(system)の設定
# set system domain-name softlayer.com ⏎
# commit ⏎
# save ⏎

ホスト名(system)の設定

ここではホスト名を「VyOS-TOK」にしました。

ホスト名(system)の設定
# set system host-name VyOS-TOK ⏎
# commit ⏎
# save ⏎

タイムゾーン(system)の設定

ここではタイムゾーンを「Asia/Tokyo」にしました。

ホスト名(system)の設定
# set system time-zone Asia/Tokyo ⏎
# commit ⏎
# save ⏎

GREトンネル(interfaces)の設定

トンネルは「tun0」という名前にします。
Tokyo側のトンネルIPは、”10.20.20.2/24”です。

GREトンネル(interfaces)の設定-Tokyo側トンネルIP設定
# set interfaces tunnel tun0 address 10.20.20.2/24 ⏎
# commit ⏎
# save ⏎

トンネルの記述を、"GRE tunnel to VyOS-SNG”にします。

GREトンネル(interfaces)の設定-Tokyo側トンネル記述設定
# set interfaces tunnel tun0 description "GRE tunnel to VyOS-SNG” ⏎
# commit ⏎
# save ⏎

パケットに新しいヘッダを付け加え、カプセル化(Encapsulation)して通信するのにGREを使います。

GREトンネル(interfaces)の設定-カプセル化にGRE使用
# set interfaces tunnel tun0 encapsulation gre ⏎
# commit ⏎
# save ⏎

ローカルIP指定(Tokyo側パブリックIP)

GREトンネル(interfaces)の設定-ローカルIP指定(Tokyo側パブリックIP)
# set interfaces tunnel tun0 local-ip 161.202.91.38 ⏎
# commit ⏎
# save ⏎

リモートIP指定(Singapore側パブリックIP)

GREトンネル(interfaces)の設定-リモートIP指定(Singapore側パブリックIP)
# set interfaces tunnel tun0 remote-ip 161.202.24.119 ⏎
# commit ⏎
# save ⏎

Singaporeに対してのスタティックルート(protocols)の設定

GREトンネル(interfaces)の設定-Singaporeに対してのスタティックルート(protocols)の設定
# set protocols static route 10.116.145.0/26  next-hop 10.20.20.2 ⏎
# commit ⏎
# save ⏎

以上で、「VyOS-TOK(VyOS)の設定」完了です。
"show"コマンドで設定値を確認します。

GREトンネルの設定(Tokyo)-showコマンドで確認
 interfaces {
     ethernet eth0 {
         address 10.132.52.247/26
         duplex auto
         hw-id 06:ce:84:86:0a:e6
         smp_affinity auto
         speed auto
     }
     ethernet eth1 {
         address 161.202.91.38/28
         duplex auto
         hw-id 06:96:da:92:17:25
         smp_affinity auto
         speed auto
     }
     loopback lo {
     }
     tunnel tun0 {
         address 10.20.20.2/24
         description "GRE tunnel to VyOS-SNG"
         encapsulation gre
         local-ip 161.202.91.38
         remote-ip 161.202.24.119
      }
 }
 protocols {
     static {
         route 10.116.145.0/26 {
             next-hop 10.20.20.2 {
             }
         }
     }
 }
 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.91.33
     host-name VyOS-TOK
     login {
         user vyos {
             authentication {
                 encrypted-password 
                 plaintext-password ""
             }
             level admin
         }
     }
     name-server 10.0.80.11
     name-server 10.0.80.12
     ntp {
         server 0.pool.ntp.org {
         }
         server 1.pool.ntp.org {
         }
          server 2.pool.ntp.org {
         }
     }
     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
 }

5-3. VyOS-SNG(VyOS)の設定

「5-2. VyOS-TOK(VyOS)の設定」と同じ操作で設定してください。

GREトンネルの設定(Singapore)-showコマンドで確認
 interfaces {
     ethernet eth0 {
         address 10.116.145.13/26
         duplex auto
         hw-id 06:bd:96:13:b1:e0
         smp_affinity auto
         speed auto
     }
     ethernet eth1 {
         address 161.202.24.119/28
         duplex auto
         hw-id 06:f0:5f:d6:7b:c4
         smp_affinity auto
         speed auto
     }
     loopback lo {
     }
     tunnel tun0 {
         address 10.20.20.1/24
         description "GRE tunnel to VyOS-TOK"
         encapsulation gre
         local-ip 161.202.24.119
         remote-ip 161.202.91.38
      }
 }
 protocols {
     static {
         route 10.132.52.192/26 {
             next-hop 10.20.20.1 {
             }
         }
     }
 }
 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.24.113
     host-name VyOS-SNG
     login {
         user vyos {
             authentication {
                 encrypted-password 
                 plaintext-password ""
             }
             level admin
         }
     }
     name-server 10.0.80.11
     name-server 10.0.80.12
     ntp {
         server 0.pool.ntp.org {
         }
         server 1.pool.ntp.org {
         }
          server 2.pool.ntp.org {
         }
     }
     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
 }

6. GREトンネル接続確認

6-1. VyOSトンネルが”up”状態であることを確認

VyOSの「一般モード」で行います。
show コマンドで確認します。

GREトンネルup確認
$ show interfaces tunnel ⏎

11.png

GREトンネルup確認-詳細
$ show interfaces tunnel detail⏎

12.png

Toykyo側で確認しましたが、Shigapore側でも確認してください。

6-2. PINGで確認

PINGはVyOSの「一般モード」で行います。

(1)Tokyo側のVyOS-TOKから、Singapore側のVyOS-SNGのプライベートアドレス(10.116.145.13)に対してPINGが通る事を確認する。

(2)Singaporeo側のVyOS-SNGから、Tokyo側のVyOS-TOKのプライベートアドレス(10.132.52.247)に対してPINGが通る事を確認する。

7. Windows2012R2サーバ、スタティックルートの設定

PowerShellでの操作です。

・W2012R2-TOK設定

W2012R2-TOKスタティックルート設定
>route add -p 10.116.145.0 mask 255.255.255.0 10.132.52.247 ⏎

・W2012R2-SNG設定

W2012R2-SNGスタティックルート設定
>route add -p 10.132.52.0 mask 255.255.255.0 10.116.145.13 ⏎

8 Windows2012Server間データ転送確認

「6. GREトンネル接続確認」を参考にして確認してください。

(1)Tokyo側のW2012R2-TOKから、Singapore側のW2012R2-SNGのプライベートアドレス(10.116.145.25)に対してPINGが通る事を確認する。

(2)Singaporeo側のW2012R2-SNGから、Tokyo側のW2012R2-TOKのプライベートアドレス(10.132.52.213)に対してPINGが通る事を確認する。

6. おわりに

 IPアドレスには表示上マスクをかけるのが安全ですが、わかりにくくなると思い、あえてマスクをかけませんでした。
(インスタンスを削除する予定です。)

SoftLayerを活用すると、ネットワークを勉強する上で、少ない費用で実機勉強でき知識が深まります。

今後、L2TPやIPsecも投稿する予定です。

22
20
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
22
20