在 openvswitch 上配置 GRE tunnel


如果你是用 openvswitch 內置的 GRE tunnel,那么配置很簡單,基本上就一條命令:

ovs-vsctl add-port br0 gre0 -- set interface gre0 type=gre options:remote_ip=192.168.1.10

本文想談的顯然不是這個。因為 upstream 內核(指 Linus tree)中的 openvswitch 是不支持 GRE tunnel 的,那我們如何在 upstream 內核中上使用 GRE tunnel 呢?

其實也不難,我們可以創建一個普通的 GRE tunnel,然后把它添加到 openvswitch bridge 中去就可以了。至少這在理論上是可行的,而實際操作中卻有一些問題,你可以動手試一試。我們假設網絡環境如下圖所示:

我們的目標是讓 HOST1 上面的兩個 VM 和 HOST2 上面的兩個 VM 通過 GRE tunnel 實現通信。因為兩邊的配置是對稱的,所以下面只說明 HOST2 上是如何配置的,HOST1 上以此類推即可。

在這個環境中,一個很可能的錯誤是把 HOST2 上的 uplink,即 eth0 也加入到 openvswitch 的 bridge 中,這是不對的,需要加入僅僅的是 GRE tunnel 設備,即 gre1 (你當然也可以把它命名為其它名字)。

剩下的一個最重要的問題是,GRE tunnel 是無法回應 ARP 的,因為它是一個 point to point 的設備(ip addr add 192.168.2.1/24 peer 192.168.1.1/24 dev gre1),所以很明顯設置了 NOARP。這個問題是這里的關鍵。因為這個的緣故,即使你在 VM1 上也無法 ping HOST2 上的 gre1。所以這里需要一個技巧,就是要給 bridge 本身配置一個 IP 地址,然后讓 bridge 做一個 ARP proxy

所以最后在 HOST2 上面的配置如下:

[root@host2 ~]# ip tunnel show
gre0: gre/ip  remote any  local any  ttl inherit  nopmtudisc
gre1: gre/ip  remote 10.16.43.214  local 10.16.43.215  ttl inherit
[root@host2 ~]# ip r s
192.168.2.0/24 dev ovsbr0  proto kernel  scope link  src 192.168.2.4
192.168.1.0/24 dev gre1  scope link
192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1
10.16.40.0/21 dev eth0  proto kernel  scope link  src 10.16.43.215
169.254.0.0/16 dev eth0  scope link  metric 1005
default via 10.16.47.254 dev eth0
[root@host2 ~]# ovs-vsctl show
71f0f455-ccc8-4781-88b2-4b663dd48c5f
    Bridge "ovsbr0"
        Port "vnet0"
            Interface "vnet0"
        Port "ovsbr0"
            Interface "ovsbr0"
                type: internal
        Port "vnet1"
            Interface "vnet1"
        Port "gre1"
            Interface "gre1"
    ovs_version: "1.7.0"

[root@host2 ~]# ip addr ls gre1 && ip addr ls ovsbr0
17: gre1:  mtu 1476 qdisc noqueue state UNKNOWN
    link/gre 10.16.43.215 peer 10.16.43.214
    inet 192.168.2.1/24 scope global gre1
    inet 192.168.2.1 peer 192.168.1.1/24 scope global gre1
13: ovsbr0:  mtu 1500 qdisc noqueue state UNKNOWN
    link/ether 66:d7:ae:42:db:44 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.4/24 brd 192.168.2.255 scope global ovsbr0
    inet6 fe80::64d7:aeff:fe42:db44/64 scope link
       valid_lft forever preferred_lft forever

[root@host2 ~]# cat /proc/sys/net/ipv4/conf/ovsbr0/proxy_arp
1

HOST2 上面的 VM1 只需添加一個路由即可,配置如下:

[root@localhost ~]# ip r s
192.168.2.0/24 dev eth1  proto kernel  scope link  src 192.168.2.2
192.168.1.0/24 dev eth1  scope link  src 192.168.2.2
[root@localhost ~]# ping 192.168.1.2
PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data.
64 bytes from 192.168.1.2: icmp_seq=1 ttl=62 time=561 ms
64 bytes from 192.168.1.2: icmp_seq=2 ttl=62 time=0.731 ms
64 bytes from 192.168.1.2: icmp_seq=3 ttl=62 time=0.669 ms
64 bytes from 192.168.1.2: icmp_seq=4 ttl=62 time=0.765 ms

--- 192.168.1.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3823ms
rtt min/avg/max/mdev = 0.669/140.860/561.275/242.726 ms


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM