有在 GCP(Google Cloud Platform)搭建 strongswan 的嘛? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
churchmice
V2EX    问与答

有在 GCP(Google Cloud Platform)搭建 strongswan 的嘛?

  •  
  •   churchmice 2017-03-11 18:40:15 +08:00 8059 次点击
    这是一个创建于 3134 天前的主题,其中的信息可能已经有所发展或是发生改变。
    搭完可以正常连接上,但是访问不了 google 家的所有网站,因为 google 的服务器跟 VPS 在同一个内网的关系?
    有办法解决吗?

    1.在默认防火墙的基础上加了 ESP,AH,UDP:500,UDP:4500 的放行规则
    2. 虚拟 IP 池设置的是 10.0.64.0/24
    3. 也在 iptables 里面加了 iptables -t nat -A POSTROUTING -s 10.0.64.0/24 -o eth0 -j MASQUERADE

    具体的配置如下:

    config setup
    #charOndebug="ike 1, knl 1, cfg 0"
    uniqueids=no

    conn ikev2-vpn
    # leftfirewall=yes
    auto=add
    compress=no
    type=tunnel
    keyexchange=ikev2
    fragmentation=yes
    forceencaps=yes
    ike=aes256-sha1-modp1024,3des-sha1-modp1024!
    esp=aes256-sha1,3des-sha1!
    dpdaction=clear
    dpddelay=300s
    rekey=no
    left=%any
    leftid=@bla_bla_bla
    leftcert=/etc/ipsec.d/certs/serverCert.pem
    leftsendcert=always
    leftsubnet=0.0.0.0/0
    right=%any
    rightid=%any
    rightauth=eap-mschapv2
    rightdns=8.8.8.8,8.8.4.4
    rightsourceip=10.0.64.0/24
    rightsendcert=never
    eap_identity=%identity
    第 1 条附言    2017-03-12 23:46:14 +08:00
    搞定了,用 tcpdum 抓了下发现是 MTU 的锅,设成 1360 就好了

    Android 用的 strongswan 客户端,可以直接设置 MTU
    MAC 的话连上 VPN 之后 ifconfig ipsec0 mtu 1360
    28 条回复    2018-11-01 14:26:44 +08:00
    churchmice
        1
    churchmice  
    OP
       2017-03-11 18:40:39 +08:00
    我访问其他网站都没问题,就是 google 全家桶不行
    Showfom
        2
    Showfom  
    PRO
       2017-03-12 04:27:12 +08:00 via iPhone
    不要用 10/8

    你换 192.168/16 试试呢
    churchmice
        3
    churchmice  
    OP
       2017-03-12 09:51:05 +08:00 via Android
    @Showfom 192.168.16.0/24 也是同样的结果, gcp 内网 IP 断是 10.128.0.0/9
    redsonic
        4
    redsonic  
       2017-03-12 10:08:47 +08:00
    有抓包看过没有?

    另外问一下,你搭的 strongswan 隧道和 tcp 明文传输带宽损失多少?
    blues9
        5
    blues9  
       2017-03-12 11:20:45 +08:00
    我在 gce 上搭的 strongswan ,工作的很好。
    大概看了一下配置,和你不一样的地方基本知识子网 ip ,我用的 192.168.55.0/24,iptables 规则是这样的:
    iptables -t nat -A POSTROUTING -s 192.168.55.0/24 -j SNAT --to 10.x.x.x

    另外,我在同一台机器上搭了 openvpn , traceroute 显示能连接成功,但是 dns 没法解析,不知道怎么回事。。。
    blues9
        6
    blues9  
       2017-03-12 12:58:16 +08:00
    对了,我的问题和楼主正好相反,连上 openvpn 以后只能访问 google 系列网站,访问其他的不行
    churchmice
        7
    churchmice  
    OP
       2017-03-12 13:32:12 +08:00
    @redsonic 这玩意怎么测?没弄过啊
    churchmice
        8
    churchmice  
    OP
       2017-03-12 13:32:48 +08:00
    @blues9 嗯,我试试,因为 GCP 里面 eth0 的地址并不是真正的外网地址
    churchmice
        9
    churchmice  
    OP
       2017-03-12 13:41:42 +08:00
    @blues9 改成 192.168.55.0/24 也是不行,方便把你的 /etc/ipsec.conf 贴一下吗?

    openvpn 的话我参考的这个 https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-debian-8

    DNS 解析不了的话你看看 push 的 DNS 是多少?
    redsonic
        10
    redsonic  
       2017-03-12 15:12:04 +08:00
    用 iperf 跑一下,先跑裸线,然后再跑你隧道里的那个地址看看。 strongswan 我在很多家的上面都搭过 额外开销很大,下行 50Mb 的裸线 跑隧道就变 40Mb 了。
    blues9
        11
    blues9  
       2017-03-12 16:05:33 +08:00
    @churchmice ipse.conf 配置文件如下:
    config setup
    uniqueids=never

    conn iOS_cert
    keyexchange=ikev1
    fragmentation=yes
    leftsendcert=always
    left=%defaultroute
    leftauth=pubkey
    leftsubnet=0.0.0.0/0
    leftcert=server.cert.pem
    right=%any
    rightauth=pubkey
    rightauth2=xauth
    rightsourceip=192.168.55.0/24
    rightcert=client.cert.pem
    auto=add

    我的 openvpn 的 dns 配置是这样的:
    push "dhcp-option DNS 208.67.220.220"
    push "dhcp-option DNS 8.8.8.8"
    churchmice
        12
    churchmice  
    OP
       2017-03-12 16:57:51 +08:00
    @blues9 DNS 改成 8.8.4.4 ? 还有你的防火墙这么配置的?

    我的配置如下:

    port 2048

    proto udp

    dev tun


    ca /etc/openvpn/ca.crt
    cert /etc/openvpn/server.crt
    key /etc/openvpn/server.key # This file should be kept secret

    dh /etc/openvpn/dh2048.pem

    server 10.0.32.0 255.255.255.0

    ifconfig-pool-persist ipp.txt








    push "redirect-gateway def1 bypass-dhcp"

    push "dhcp-option DNS 8.8.4.4"
    push "dhcp-option DNS 8.8.8.8"



    keepalive 10 120



    comp-lzo


    user nobody
    group nogroup

    persist-key
    persist-tun

    status openvpn-status.log


    verb 3


    cipher AES-256-CBC
    churchmice
        13
    churchmice  
    OP
       2017-03-12 17:14:06 +08:00
    @redsonic
    [ ID] Interval Transfer Bandwidth
    [ 5] 0.00-60.00 sec 15.5 MBytes 2.17 Mbits/sec sender
    [ 5] 0.00-60.00 sec 15.4 MBytes 2.16 Mbits/sec receiver


    我家的瓶颈在无线路由器....
    redsonic
        14
    redsonic  
       2017-03-12 17:17:31 +08:00
    @churchmice 这是裸线还是走隧道? 要对比一下。不过你这带宽足够了,损失多少无所谓了。
    churchmice
        15
    churchmice  
    OP
       2017-03-12 18:27:44 +08:00   1
    @redsonic 连上 strongswan 之后本机(mac)当 server,gcp 当 client 的数据

    root@nox-gcp:~# iperf3 -u -c 10.0.64.1 -b 50M -t 60 -i 10
    Connecting to host 10.0.64.1, port 5201
    [ 4] local ********** port 47358 connected to 10.0.64.1 port 5201
    [ ID] Interval Transfer Bandwidth Total Datagrams
    [ 4] 0.00-10.00 sec 59.2 MBytes 49.6 Mbits/sec 7575
    [ 4] 10.00-20.00 sec 59.6 MBytes 50.0 Mbits/sec 7629
    [ 4] 20.00-30.00 sec 59.6 MBytes 50.0 Mbits/sec 7629
    [ 4] 30.00-40.00 sec 59.6 MBytes 50.0 Mbits/sec 7630
    [ 4] 40.00-50.00 sec 59.6 MBytes 50.0 Mbits/sec 7629
    [ 4] 50.00-60.00 sec 59.6 MBytes 50.0 Mbits/sec 7630
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
    [ 4] 0.00-60.00 sec 357 MBytes 49.9 Mbits/sec 0.522 ms 26/45722 (0.057%)
    [ 4] Sent 45722 datagrams

    iperf Done.
    churchmice
        16
    churchmice  
    OP
       2017-03-12 18:39:56 +08:00
    @redsonic
    刚才可能有人在看电视,所以数据不准
    现在拿本机(mac)当 client,gcp 当 server,数据如下

    churchmice@rmbp:~ $-> iperf3 -u -c 104.x.x.x -b 50M -t 60 -i 10
    Connecting to host 104.x.x.x, port 5201
    [ 5] local 10.0.16.64 port 49369 connected to 104.x.x.x port 5201
    [ ID] Interval Transfer Bandwidth Total Datagrams
    [ 5] 0.00-10.01 sec 59.0 MBytes 49.5 Mbits/sec 43975
    [ 5] 10.01-20.00 sec 59.6 MBytes 50.0 Mbits/sec 44404
    [ 5] 20.00-30.00 sec 59.6 MBytes 50.0 Mbits/sec 44386
    [ 5] 30.00-40.00 sec 59.6 MBytes 50.0 Mbits/sec 44390
    [ 5] 40.00-50.01 sec 59.6 MBytes 50.0 Mbits/sec 44391
    [ 5] 50.01-60.01 sec 59.6 MBytes 50.0 Mbits/sec 44393
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
    [ 5] 0.00-60.01 sec 357 MBytes 49.9 Mbits/sec 1.645 ms 241581/265936 (91%)
    [ 5] Sent 265936 datagrams

    iperf Done.

    连上 strongswan
    churchmice@rmbp:~ $-> iperf3 -u -c 104.x.x.x -b 50M -t 60 -i 10
    Connecting to host 104.x.x.x, port 5201
    [ 5] local 10.0.16.64 port 61546 connected to 104.x.x.x port 5201
    [ ID] Interval Transfer Bandwidth Total Datagrams
    [ 5] 0.00-10.00 sec 59.1 MBytes 49.5 Mbits/sec 43990
    [ 5] 10.00-20.00 sec 59.6 MBytes 50.0 Mbits/sec 44382
    [ 5] 20.0030.00 sec 59.6 MBytes 50.0 Mbits/sec 44407
    [ 5] 30.00-40.00 sec 59.6 MBytes 50.0 Mbits/sec 44364
    [ 5] 40.00-50.00 sec 59.6 MBytes 50.0 Mbits/sec 44391
    [ 5] 50.00-60.00 sec 59.6 MBytes 50.0 Mbits/sec 44402
    - - - - - - - - - - - - - - - - - - - - - - - - -
    [ ID] Interval Transfer Bandwidth Jitter Lost/Total Datagrams
    [ 5] 0.00-60.00 sec 357 MBytes 49.9 Mbits/sec 1.704 ms 241100/265927 (91%)
    [ 5] Sent 265927 datagrams

    iperf Done.
    churchmice
        17
    churchmice  
    OP
       2017-03-12 19:55:02 +08:00
    用 tcp 模式测试的话,gcp 开 server,mac 当 client,测试命令 iperf3 -c 104.x.x.x -t 60 -i 10, 连上 vpn 和未连 vpn 速度都是差不多

    [ 5] 0.00-60.15 sec 25.9 MBytes 3.62 Mbits/sec sender
    [ 5] 0.00-60.15 sec 25.8 MBytes 3.60 Mbits/sec receiver

    连上后 mac 当 server,gcp 当 client,测试的话速度倒是挺快 iperf3 -c 10.0.64.1 -t 60 -i 10
    [ ID] Interval Transfer Bandwidth Retr
    [ 4] 0.00-60.00 sec 348 MBytes 48.6 Mbits/sec 257 sender
    [ 4] 0.00-60.00 sec 346 MBytes 48.4 Mbits/sec receiver
    churchmice
        18
    churchmice  
    OP
       2017-03-12 19:56:09 +08:00
    不过我的问题还是没法解决啊,很诡异的
    ping www.google.com 都是没有问题的
    wget 就卡了

    churchmice@ancients:~ $-> ping www.google.com
    PING www.google.com (64.233.188.104): 56 data bytes
    64 bytes from 64.233.188.104: icmp_seq=0 ttl=52 time=48.167 ms
    ^C
    --- www.google.com ping statistics ---
    1 packets transmitted, 1 packets received, 0.0% packet loss
    round-trip min/avg/max/stddev = 48.167/48.167/48.167/0.000 ms
    churchmice@ancients:~ $-> wget www.google.com
    --2017-03-12 19:55:58-- http://www.google.com/
    Resolving www.google.com... 64.233.188.103, 64.233.188.104, 64.233.188.106, ...
    Connecting to www.google.com|64.233.188.103|:80... connected.
    HTTP request sent, awaiting response... ^C
    blues9
        19
    blues9  
       2017-03-12 20:46:23 +08:00
    @churchmice
    我的 openvpn 配置和你大同小异。改了 dns 也没有用。
    iptables 规则是:
    iptables -t nat -A POSTROUTING -s 192.168.66.0/24 -j SNAT --to 10.x.x.x

    在我的 macbook 上连上 open VPN ,命令行 ping 和 traceroute 某个 ip 都是没有问题的
    churchmice
        20
    churchmice  
    OP
       2017-03-12 21:07:06 +08:00
    @blues9 英吹思婷,我的是 ping 没问题,wget 就卡
    blues9
        21
    blues9  
       2017-03-12 21:19:08 +08:00
    @churchmice
    对了,还有一个现象就是 google 家的网站访问都没问题,别的就不行。总感觉是路由哪里有问题,但找不到原因。
    churchmice
        22
    churchmice  
    OP
       2017-03-12 23:25:47 +08:00
    @blues9 tcpdump 看了下是 MTU 有问题

    need to frag (mtu 1398), length 556



    所以 ping 没有问题,但是 wget 有问题
    churchmice
        23
    churchmice  
    OP
       2017-03-12 23:54:22 +08:00
    @blues9 搞定,在客户端把 MTU 设成 1360 就好了
    blues9
        24
    blues9  
       2017-03-13 08:13:33 +08:00 via iPhone
    @churchmice
    恭喜。我的 openvpn 还是没搞定,还是 dns 不通
    churchmice
        25
    churchmice  
    OP
       2017-03-13 12:12:31 +08:00 via Android
    @blues9 那只能 server 端 tcpdump 抓包了
    sdrzlyz
        26
    sdrzlyz  
       2017-06-06 11:25:03 +08:00
    同样的问题。其他网站 ok,但是 google 自家的就不行,也是通过客户端设施 MTU 可以搞定。这个很奇怪啊。。。为什么默认的 1400 就不行呢? server 端的 mtu 是 1460.
    churchmice
        27
    churchmice  
    OP
       2017-06-06 12:11:50 +08:00 via Android
    @sdrzlyz GCP 内网的锅吧
    blues9
        28
    blues9  
       2018-11-01 14:26:44 +08:00
    我的 open vpn 的问题后来解决了,需要在创建 instance 的时候在网络设置里打开 ip forwarding 开关。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5288 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 28ms UTC 09:07 PVG 17:07 LAX 02:07 JFK 05:07
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86