電訊茶室's Archiver

gfx86674 發表於 2018-2-21 21:11

iPhone使用IKEv2翻牆

[i=s] 本帖最後由 gfx86674 於 2018-7-9 15:26 編輯 [/i]

前言:
IPSec 作為新一代網路安全協定,為網路傳輸提供了安全保證,
使端到端的資料保密成為可能,是互聯網上的新一代安全標準。

提供包括存取控制、不需連線的完整性、資料來源認證、抗重放 (replay)保護、
保密和有限傳輸保密性在內的服務,
服務基於 IP 層並對 IP 及上層協議進行保護。服務的實施通過兩種通信安全協議:
認證頭(AH)和封裝安全負載(ESP)以及 Internet 金鑰交換(IKE)協定來達到這些目標。

IPSec AH 協定提供資料來源認證、不需連線的完整性和可選的抗重放服務。

ESP 協定提供資料保密性,有限的資料流程保密性、
資料來源認證、不需連線的完整性及抗重放服務。

IKE 協定用於協商 AH 和 ESP 協定所使用的密碼演算法,
並將演算法所需的必備金鑰放在合適的位置。

IPSec 有兩種模式:傳輸模式和隧道模式。它們都是對外出的資料包添加 IPSec 頭進行加密和認證,
而對於接收的 IPSec 資料包作解密認證處理和適當的轉發傳送。

gfx86674 發表於 2018-2-21 21:12

[i=s] 本帖最後由 gfx86674 於 2018-2-22 02:10 編輯 [/i]

[img]https://wiki.mikrotik.com/images/5/5a/Ipsec-road-warrior.png[/img]
此環境在官網稱Road Warrior ,是建構在IPSec IKE環境,需憑證(certificate)交換認證.
您可以用憑證頒發機構,但以下說明皆是在RouterOS的憑證視窗,自簽證明生成的(第三方憑證)

[size=4]憑證有3組,分別是: [color=Green]ca[/color] / [color=Red]server[/color] / [color=Blue]client[/color][/size]

[size=4][color=Green]/certificate 新增憑證ca:[/color][/size]
[img]https://i.imgur.com/oWZ6E50.png[/img]
[img]https://i.imgur.com/kCjOkN9.png[/img]

gfx86674 發表於 2018-2-21 21:12

[i=s] 本帖最後由 gfx86674 於 2018-2-21 22:28 編輯 [/i]

[size=4][color=Red]/certificate 新增server(伺服端)憑證:[/color][/size]
[attach]3919[/attach][attach]3920[/attach]
[attach]3921[/attach]
[attach]3927[/attach]

[size=4][color=Blue]/certificate 新增client(用戶端)憑證:[/color][/size]
[attach]3923[/attach][attach]3924[/attach]
[attach]3925[/attach]
[attach]3926[/attach]

gfx86674 發表於 2018-2-21 21:12

[i=s] 本帖最後由 gfx86674 於 2018-2-21 22:46 編輯 [/i]

[size=4]匯出憑證給用戶:[/size]
[size=4][color=Green]憑證ca[/color][/size]
[attach]3928[/attach]

[size=4][color=Blue]client(用戶端)憑證[/color][/size]
[attach]3929[/attach]

[size=4]匯出的檔案:[/size]
[attach]3930[/attach]
先將2個檔案拉至電腦桌面 ,再用附件將兩檔寄到自己的mail信箱

gfx86674 發表於 2018-2-21 21:13

[i=s] 本帖最後由 gfx86674 於 2018-2-21 23:32 編輯 [/i]

因Road Warrior並沒有像其它vpn有Change TCP MSS的功能,
有的用戶是來自固網,有的是PPPoE,還有DHCP-Client...

這些通道寬度不一,再經IPSec隧道後MTU早非原先的值.
所以我們自己手動新增Change TCP MSS ,避免因通道寬(MTU)的值不對丟失封包.

[size=4]/ip firewall mangle 新增2筆:[/size]
1.
[attach]3931[/attach]
[attach]3932[/attach]

2.
[attach]3933[/attach]
[attach]3935[/attach]

這2筆新增完要擺在/ip firewall mangle 最優先的位置0,1 ,封包交換時才不會有疏漏
[attach]3934[/attach]

gfx86674 發表於 2018-2-21 21:13

[i=s] 本帖最後由 gfx86674 於 2018-2-22 08:12 編輯 [/i]

[size=4]IKEv2 Server設定:[/size]
/ip pool
[attach]3936[/attach]
連結:[url=http://www.subnet-calculator.com/subnet.php?net_class=C]subnet計算機[/url]

[attach]3945[/attach]
操作[color=Blue]subnet-Mask[/color]或[color=Red]Mask-Bits[/color],
用[color=Red]最大的Mask-Bits[/color]值將您的VPN-Pool含在[color=Red]Host-Address-Range[/color]裡.
而[color=Red]Subnet-ID與Mask-Bits 的組合[/color]即您的VPN-Pool的遮罩表示法.

/ip ipsec proposal
[attach]3937[/attach]

/ip ipsec mode-conf
[attach]3938[/attach]

/ip ipsec group
[attach]3939[/attach]

/ip ipsec policy
[attach]3940[/attach]
[attach]3941[/attach]

/ip ipsec peer
[attach]3942[/attach]
[attach]3943[/attach]
[attach]3944[/attach]

gfx86674 發表於 2018-2-21 21:52

[i=s] 本帖最後由 gfx86674 於 2018-2-22 02:19 編輯 [/i]

IKEv2 Client(iPhone)設定:
1.iPhone收到桌機寄出含附件的mail ,先進行[color=Green]憑證ca的匯入[/color]
直接點擊ca憑證即可.
[attach]3946[/attach][attach]3947[/attach][attach]3948[/attach][attach]3949[/attach]

2.進行[color=Blue]client(用戶端)[/color]憑證的匯入
[attach]3950[/attach][attach]3951[/attach][attach]3952[/attach][attach]3953[/attach][attach]3954[/attach]

3.讓iPhone對憑證產生信任
設定 -> 一般 -> 關於本機 -> 憑證信任設定 [Settings -> General -> About -> Certificate]
[attach]3955[/attach][attach]3956[/attach]

4.新增IKEv2撥號
[attach]3957[/attach]

5.連線成功
[attach]3958[/attach][attach]3959[/attach]

gfx86674 發表於 2018-2-22 01:59

注意有些人會將vpn-pool與dhcp-pool放在同個網段,
這是非常不正確的做法,會讓arp查詢發生問題
在路由是會把它當成兩個相同的網段,而非用戶認為的同一網段,這種差異是巨大的.

在其它vpn可以在ethernet設置proxy-arp進行ethernet偽裝欺騙,
但ipsec-tunnel內可是沒這種服務的.

所以若連線並未順遂的話,除檢驗憑證與設置外,看自己是否有發生網段重疊的低級失誤.

角色 發表於 2018-2-22 09:17

[i=s] 本帖最後由 角色 於 2018-2-22 12:08 編輯 [/i]

首先CHing辛苦了!

谢谢你这幅帖子,把我们不会的带到另外一个领域那里。{:5_221:}

我会把这幅帖子链接到MikroTik的Forum里。Ching能否说一下,按照WiKi里的信息,先把Road Worrior 的PC(RW PC)连接到IPSec router,那么RW PC就可以连接到IPSec router后面的local network devices.

我的问题是更加或者加了些什么,能够local network + Internet呢?就是OpenVPN TUN and TAP mode。

我已经把你的信息的链接发到MikroTik Forum里:
[url]https://forum.mikrotik.com/viewtopic.php?f=2&t=131161&p=644032#p644032[/url]

lookforyou 發表於 2018-2-22 10:21

虽然不用vpn,但也要为你点个赞

yiucsw 發表於 2018-2-23 02:42

找不到,IPsec server 的配置?

ckleea 發表於 2018-2-23 06:34

[b]回復 [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=44426&ptid=7126]9#[/url] [i]角色[/i] [/b]


    是可以用來連內聯網,因為客戶端是有一個 local address

gfx86674 發表於 2018-2-23 08:07

[i=s] 本帖最後由 gfx86674 於 2018-2-23 20:30 編輯 [/i]

[b]回復 [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=44451&ptid=7126]11#[/url] [i]yiucsw[/i] [/b]
上面說的IKEv2 Server配置即IPSec配置。iPhone預設支援的3種VPN全都與IPSec有關:

L2TP:在加密的IPSec隧道進行L2TP封包交換,間接的替L2TP做了加密動作。

IKEv2:Road Warrior傳輸的憑證認證模式(或稱IKE)。

IPSec:Road Warrior傳輸的帳/密認証模式(或稱Xauth)。
[color=Pink]目前Server對iOS支援有局限,只可對classB(192.168.0.0/16)的局部區網做封包交換。
若將傳輸範圍擴展至整個互連網(0.0.0.0/0),用戶端會不能連線。[/color]

gfx86674 發表於 2018-3-2 17:16

[i=s] 本帖最後由 gfx86674 於 2018-3-2 17:19 編輯 [/i]

我胡搞把這篇IKEv2製作的憑證拿來對ovpn瞎鬧...結果竟又可以用 [大笑]

憑證有3個分別是ca /server /client
我將ovpn-server先掛上ca ,然後將ca與server匯出:

因windows桌機的openvpn設定檔只需要ca ,所以先試:
連線過程出現這警告:
[size=2][color=Red]WARNING: INSECURE cipher with block size less than 128 bit (64 bit). This allows attacks like SWEET32. Mitigate by using a --cipher with a larger block size (e.g. AES-256-CBC).[/color][/size][code]client
dev tun
remote 12345678.sn.mynetname.net 1194
proto tcp
auth-user-pass
redirect-gateway
mute-replay-warnings

<ca>
------- ca_code --------
</ca>[/code]但不影響連線,連線成功了{:5_258:}
[img]https://i.imgur.com/TDaZfea.png[/img]
[img]https://i.imgur.com/QJwrAKb.png[/img]
------------------------------------------
再來換iPhone ,ovpn設定檔上傳:[code]client
dev tun
remote 12345678.sn.mynetname.net 1194
proto tcp
auth-user-pass
redirect-gateway
mute-replay-warnings

<ca>
------- ca_code --------
</ca>

<cert>
----- server_code ------
</cert>[/code]ovpn的連線畫面多出了選擇憑證的欄位,但不理會一樣可以連線.
[img]https://i.imgur.com/3DBgsoE.png[/img][img]https://i.imgur.com/UGYcjwo.png[/img]
------------------------------------------
再來...
選擇憑證的欄位我很介意,想說能否利用?
所以我把設定檔憑證的部份全刪就直接套到iPhone裡用[code]client
dev tun
remote 12345678.sn.mynetname.net 1194
proto tcp
auth-user-pass
redirect-gateway
mute-replay-warnings[/code]選擇已匯入的client憑證,竟也是連上線了{:5_199:}
[img]https://i.imgur.com/8navYTC.png[/img][img]https://i.imgur.com/hIwLo6b.png[/img]

Skypeus 發表於 2018-10-13 11:08

在设置到:
/ip firewall mangle 新增2筆:
这里出现在下面这个出错,怎么办?
[attach]4194[/attach]

gfx86674 發表於 2018-10-13 11:18

[i=s] 本帖最後由 gfx86674 於 2018-10-13 11:19 編輯 [/i]

[b]回復 [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=45492&ptid=7126]15#[/url] [i]Skypeus[/i] [/b]
這兩其一您lose了...
[attach]4197[/attach]
[attach]4195[/attach]

Skypeus 發表於 2018-10-13 11:47

[quote]回復  Skypeus
這兩其一您lose了...
[size=2][color=#999999]gfx86674 發表於 2018-10-13 11:18[/color]
嗯,这个可以了。
然后测试了一下,用iphone在内网以IP 192.168.X.X 地址形式可以连接上IKEV2服务端。
但换用DDNS域名 [url]www.xxxxtest.com[/url] 这样的形式就连接不上IKEV2服务端了。
请教一下:
IKEV2服务端没有公网IP,我用花生壳映射到了内网IP,端口是443吗? 还是用那个端口呢?

gfx86674 發表於 2018-10-13 12:02

[b]回復 [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=45494&ptid=7126]17#[/url] [i]Skypeus[/i] [/b]
ikev2是用ipsec協定,會用到udp port:500,4500

會無法從public address連接,幾乎很肯定您同時有開啟l2tp服務.
因為l2tp也會用到ipsec協定(udp port:500,4500),衝突到了.
您只要把l2tp關閉,ikev2隨即能從public address連接.

Skypeus 發表於 2018-10-13 12:37

[b]回復 [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=45495&ptid=7126]18#[/url] [i]gfx86674[/i] [/b]


    把l2tp關閉,ikev2也还是不能从外网的域名连接进来。是不是DDNS花生壳转换不到内网的IP和端口啊?

在没有公网IP的情况下,还有其他方法可以访问到内网的IKEv2服务端吗?

gfx86674 發表於 2018-10-13 12:43

[quote]回復  gfx86674
    把l2tp關閉,ikev2也还是不能从外网的域名连接进来。是不是DDNS花生壳转换不到内网的 ...
[size=2][color=#999999]Skypeus 發表於 2018-10-13 12:37[/color] [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=45496&ptid=7126][img]http://www.telecom-cafe.com/forum/images/common/back.gif[/img][/url][/size][/quote]端看您isp可否申請將udp port:500,4500映射至您的private address上,
如可問題就排除了;若否不管任何vpn-server都是無解的.

Skypeus 發表於 2018-10-13 13:18

[b]回復 [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=45497&ptid=7126]20#[/url] [i]gfx86674[/i] [/b]


    哦,原来是ISP作了端口限制了啊。

Skypeus 發表於 2018-10-20 13:51

[quote]回復  Skypeus
ikev2是用ipsec協定,會用到udp port:500,4500

會無法從public address連接,幾乎很肯定您同 ...
[size=2][color=#999999]gfx86674 發表於 2018-10-13 12:02[/color] [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=45495&ptid=7126][img]http://www.telecom-cafe.com/forum/images/common/back.gif[/img][/url][/size][/quote]

把l2tp關閉,释放UDP Port:500, 4500
是在ROS里面的 /PPP -Interface: L2TP Server Binding [[b]Disabe[/b]]吗?
还有其他地方要移除 Port:500, 4500的吗?

gfx86674 發表於 2018-10-20 16:33

[b]回復 [url=http://www.telecom-cafe.com/forum/redirect.php?goto=findpost&pid=45589&ptid=7126]22#[/url] [i]Skypeus[/i] [/b]
[attach]4215[/attach]
這不要選yes,
也就是l2tp可以開但不要選ipsec加密就好,其他的不影響.

amanx 發表於 2019-9-20 15:41

ios 13 用這方法ikev2 不能connect...
但ios12沒有問題

頁: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.