tabimoba.net

とあるエンジニアの雑記帳

VyOSのIPSec site-to-site VPNでVPN対向先の別セグメントに対してルーティングする方法

はじめに

VyOSを利用することで、IaaSやVPN上にSite-to-Site(拠点間接続)なIPSecルーターを構築することが出来ます。

例えば、IDCFクラウドでは、こちらで自社サービスでVyOSによる拠点間VPN接続の方法を紹介しており、こちらで接続ガイドを公開しています。

上記接続ガイド通りに設定を行うと、IaaSと自社の間でVPNを簡単に構築することが出来ますが、接続ガイドに沿った設定の場合、自社の向こうに異なるネットワークセグメントが別に存在する場合、別セグメントからIaaSに対するルーティング、あるいはIaaSから別セグメントに対するルーティングが通らないという問題が生じます。

理由

vpn ipsec site-to-site peer ... tunnel ? の場合、remoteで設定されたセグメント以外に対するルーティングが行われません。 (後述NGパターン1)

また、1つのpeerに対して、tunnelを複数指定することはできません。 (後述NGパターン2)

対向側に複数のセグメントが存在し、全てのセグメントに対してルーティングできるようにする場合は、tunnelではなく、vti (Virtual Tunnel Interface)を用いる必要があります。

設定

以下は、IDCFクラウドの接続ガイドに書かれている、YAMAHA RT/RTXシリーズとの接続手順に対する変更差分として記述しています。

まずは接続ガイド通りに設定を行い、その後に本設定を参考に変更点を反映していただければ良いと思います。

なお、下記ネットワーク図の(2),(3),(4)各ルーターにおいては、それぞれに192.168.1.0/24,192.168.2.0/24,192.168.3.0/24へのルーティングが通るように、スタティックルーティング等の設定が事前に行われていることとします。

ネットワーク図

スライド1.png

インターフェースの設定

interfaces {
     ethernet eth0 {
         address dhcp
         duplex auto
         smp_affinity auto
         speed auto
     }
     tunnel tun0 {
         address 192.168.123.1/24
         encapsulation ipip
         local-ip 192.168.1.1
         mtu 1422
         multicast disable
         remote-ip 172.16.1.2
     }
     vti vti0 {
     }
 }

スタティックルーティングの設定

 protocols {
     static {
         interface-route 192.168.2.0/24 {
             next-hop-interface vti0 {
             }
         }
         interface-route 192.168.3.0/24 {
             next-hop-interface vti0 {
             }
         }
     }
 }

トンネリングの設定

vti {
    bind vti0
}

NGパターン

NGパターン1

  • (1)から(4)および192.168.3.0/24セグメントの端末へtracerouteすると(2)で止まります。
  • 192.168.1.0/24セグメントの端末から192.168.3.0/24セグメントの端末へtracerouteすると、(3)から先にルーティングされません。

インターフェースの設定

interfaces {
     ethernet eth0 {
         address dhcp
         duplex auto
         smp_affinity auto
         speed auto
     }
     tunnel tun0 {
         address 192.168.123.1/24
         encapsulation ipip
         local-ip 192.168.1.1
         mtu 1422
         multicast disable
         remote-ip 172.16.1.2
     }
 }

スタティックルーティングの設定

 protocols {
     static {
         interface-route 192.168.2.0/24 {
             next-hop-interface tun0 {
             }
         }
         interface-route 192.168.3.0/24 {
             next-hop-interface tun0 {
             }
         }
     }
 }

トンネリングの設定

tunnel 1 {
 allow-nat-networks disable
 allow-public-networks disable
 local {
     prefix 192.168.1.0/24
 }
 remote {
     prefix 192.168.2.0/24
 }
}

NGパターン2

  • (1)および192.168.1.0/24セグメントの端末から、(4)および192.168.3.0/24セグメントの端末へtracerouteすると、(3)から先にルーティングされません。

インターフェースの設定

interfaces {
     ethernet eth0 {
         address dhcp
         duplex auto
         smp_affinity auto
         speed auto
     }
     tunnel tun0 {
         address 192.168.123.1/24
         encapsulation ipip
         local-ip 192.168.1.1
         mtu 1422
         multicast disable
         remote-ip 172.16.1.2
     }
 }

スタティックルーティングの設定

 protocols {
     static {
     }
 }

トンネリングの設定

tunnel 1 {
 allow-nat-networks disable
 allow-public-networks disable
 local {
     prefix 192.168.1.0/24
 }
 remote {
     prefix 192.168.2.0/24
 }
}
tunnel 2 {
 allow-nat-networks disable
 allow-public-networks disable
 local {
     prefix 192.168.1.0/22
 }
 remote {
     prefix 192.168.3.0/24
 }
}