(NW)GREトンネル設定してみる

投稿者: | 2020年8月5日
皆さんこんにちは。
今回はGRE(Generic Routing Encapsulation)トンネルの設定をメモしておきます。

IPパケットをカプセル化してインターネット経由でもルーティングプロトコルを使用できる便利なやつっぽいです。

今回やることとしては、

1, ルータにGREの設定をする 
2, ルータにOSPFの設定をする
3, ルーティング情報が交換されているかを確認する
    – OSPFで経路交換を実施して対向のルータが管理してるNWにPingが飛ぶことを確認する
4, WireSharkでGREのパケットを覗いてみる
    – ルータの間にかませてるスイッチにミラーポートの設定をしてGREのパケットを取得します
    – トンネリング用に新しく付加されたIPヘッダ(20byte)とGREヘッダ(4byte)があるかを確認します

ルータ設定

###
### RT1
###

# 基本設定
Router>ena
Router#conf t
Router(config)#hostname RT1

# インターフェース設定
RT1(config)#interface fastEthernet 0
RT1(config-if)#ip address 1.1.1.1 255.255.255.0
RT1(config-if)#no shutdown 
RT1(config-if)#exit

RT1(config)#interface fastEthernet 1
RT1(config-if)#ip address 192.168.10.1 255.255.255.0
RT1(config-if)#no shutdown 
RT1(config-if)#exit

# GRE設定
RT1(config)#interface tunnel 0
RT1(config-if)#tunnel mode gre ip
RT1(config-if)#ip address 10.10.10.1 255.255.255.0
RT1(config-if)#tunnel source 1.1.1.1
RT1(config-if)#tunnel destination 1.1.1.2
RT1(config-if)#exit

# ルーティング設定
RT1(config)#router ospf 1
RT1(config-router)#network 10.10.10.0 0.0.0.255 area 0
RT1(config-router)#network 192.168.10.0 0.0.0.255 area 0
RT1(config-router)#end
###
### RT2
###

# 基本設定
Router>ena
Router#conf t
Router(config)#hostname RT2

# インターフェース設定
RT2(config)#int fastEthernet 0
RT2(config-if)#ip address 1.1.1.2 255.255.255.0
RT2(config-if)#no shutdown 
RT2(config-if)#exit

RT2(config)#int fastEthernet 1
RT2(config-if)#ip address 192.168.20.1 255.255.255.0
RT2(config-if)#no shutdown 
RT2(config-if)#exit

# GRE設定
RT2(config)#interface tunnel 0
RT2(config-if)#tunnel mode gre ip
RT2(config-if)#ip address 10.10.10.2 255.255.255.0
RT2(config-if)#tunnel source 1.1.1.2
RT2(config-if)#tunnel destination 1.1.1.1
RT2(config-if)#exit

# ルーティング設定
RT2(config)#router ospf 1
RT2(config-router)#network 10.10.10.0 0.0.0.255 area 0
RT2(config-router)#network 192.168.20.0 0.0.0.255 area 0
RT2(config-router)#end

ミラーポート設定

後ほどWireSharkでパケットを覗くのでミラーポートの設定をしておきます。
###
### SW1
###

# 基本設定
Switch>ena
Switch#conf t
Switch(config)#hostname SW1

# ミラーポートの設定
SW1(config)#monitor session 1 source interface fastEthernet 0/7
SW1(config)#monitor session 1 destination interface fastEthernet 0/1

もろもろ確認

PC1 –> PC2 にPingを飛ばします。
うまくトンネリングされてればOSPFの経路交換が行われて対向のRT2が管理するNWに到達出きるはずです。
$ ping -c 10 192.168.20.2
PING 192.168.20.2 (192.168.20.2): 56 data bytes
64 bytes from 192.168.20.2: icmp_seq=0 ttl=62 time=1.690 ms
64 bytes from 192.168.20.2: icmp_seq=1 ttl=62 time=1.815 ms
64 bytes from 192.168.20.2: icmp_seq=2 ttl=62 time=1.748 ms
64 bytes from 192.168.20.2: icmp_seq=3 ttl=62 time=1.736 ms
64 bytes from 192.168.20.2: icmp_seq=4 ttl=62 time=1.722 ms
64 bytes from 192.168.20.2: icmp_seq=5 ttl=62 time=1.714 ms
64 bytes from 192.168.20.2: icmp_seq=6 ttl=62 time=2.139 ms
64 bytes from 192.168.20.2: icmp_seq=7 ttl=62 time=1.685 ms
64 bytes from 192.168.20.2: icmp_seq=8 ttl=62 time=1.752 ms
64 bytes from 192.168.20.2: icmp_seq=9 ttl=62 time=1.709 ms
--- 192.168.20.2 ping statistics ---
10 packets transmitted, 10 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.685/1.771/2.139/0.128 ms
飛びました。GREトンネルはうまく張れてそうです。
次にGREのトンネルインターフェースの状態と、ルーティングテーブルをそれぞれ確認しておきます。
### GREトンネルインターフェース
RT1#show interfaces tunnel 0
Tunnel0 is up, line protocol is up
  Hardware is Tunnel
  Internet address is 10.10.10.1/24
  MTU 17916 bytes, BW 100 Kbit/sec, DLY 50000 usec,
     reliability 255/255, txload 1/255, rxload 1/255
  Encapsulation TUNNEL, loopback not set
  Keepalive not set
  Tunnel source 1.1.1.1, destination 1.1.1.2
  Tunnel protocol/transport GRE/IP
    Key disabled, sequencing disabled
    Checksumming of packets disabled
  Tunnel TTL 255, Fast tunneling enabled
  Tunnel transport MTU 1476 bytes
  Tunnel transmit bandwidth 8000 (kbps)
  Tunnel receive bandwidth 8000 (kbps)
  Last input 00:00:04, output 00:00:06, output hang never
  Last clearing of "show interface" counters never
  Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
  Queueing strategy: fifo
  Output queue: 0/0 (size/max)
  5 minute input rate 0 bits/sec, 0 packets/sec
  5 minute output rate 0 bits/sec, 0 packets/sec
     190 packets input, 19264 bytes, 0 no buffer
     Received 0 broadcasts (0 IP multicasts)
     0 runts, 0 giants, 0 throttles
     0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
     234 packets output, 23744 bytes, 0 underruns
     0 output errors, 0 collisions, 0 interface resets
     0 unknown protocol drops
     0 output buffer failures, 0 output buffers swapped out
RT1#
### ルーティングテーブル
RT1#show ip route ospf 
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
       + - replicated route, % - next hop override

Gateway of last resort is not set

O     192.168.20.0/24 [110/1001] via 10.10.10.2, 00:09:04, Tunnel0
RT1#

### OSPFのネイバーとして対向のルータを認識してる
RT1#show ip ospf neighbor 

Neighbor ID     Pri   State           Dead Time   Address         Interface
192.168.20.1      0   FULL/  -        00:00:36    10.10.10.2      Tunnel0
RT1#
それぞれ設定したとおりに値が入っていました。
次にWireSharkをつかってGREのパケットを覗いてみようとおもいます。
トンネリング用に新しく付加されたIPヘッダ(20byte)とGREヘッダ(4byte)があるはずです。
PC1 –> PC2 へのPingをキャプチャしました。
IPヘッダが2つとGREヘッダがあってカプセル化されてることが分かりますね。
ついでにOSPFのパケットも確認しました。
OSPFのマルチキャスト(224.0.0.5)のHelloパケットがRT1、RT2からそれぞれ送信されてることがわかります。