2020年3月28日 星期六

RouterOS-架設VPN-l2tp/Ipsec, 用iOS連接

(更新, 有搭建IKEV2的範例, 可以參考 RouterOS-架設VPN-IKEV2, 用iOS連接

目的 : 建立l2tp/Ipsec VPN, 讓手機iOS可以連
Ref :
https://blog.ladsai.com/mikrotik-routeros-%E5%BB%BA%E7%BD%AE-l2tp-over-ipsec-vpn-server.html
https://omega.idv.tw/kdb120/viewthread.php?forumid=67&goto=lastpost
http://www.128px.com/2018/01/RouterOS-V641-2.html
Mikrotik : https://wiki.mikrotik.com/wiki/Manual:IP/IPsec#Basic_L2TP.2FIPsec_setup

目的 : 建立l2tp/Ipsec VPN, 讓手機iOS可以連

l2tp/Ipsec 須要三個資訊, 下面都是範例
l2tp帳號 : l2tp_user
l2tp密碼 : l2tp_pwd
Ipsec密鑰 : ipsec_pwd

網路環境基本資訊
社區網路
Pubilc IP : 111.222.333.444
Port : UDP-1701, 500, 4500已經有port forward到Router

Router上網設定(社區網路是固定ip, 這邊是網路公司提供)
Static IP : 192.168.99.20
Netmask : 255.255.255.0
Gateway : 192.168.99.254

內網Router設定
Router ip : 192.168.88.1
DHCP Server : 192.168.88.100-192.168.88.120
DNS : 168.95.1.1/8.8.8.8

1. 建立 VPN 網段
   Winbox > IP > Pool, 新增一組網段
   /ip pool
   add name=L2TP_VPN ranges=192.168.88.200-192.168.88.220

2. 建立給 L2TP 使用的 profile
   Winbox > PPP > Profiles, 新增profile
   name: L2TP_Profile
   local-address: 輸入你的 L2TP Server IP,也就是你的 RouterBoard IP。
   remote-address: 輸入你要分配給連入的 L2TP 連線的 IP,就是上面設定的網段L2TP_VPN

   /ppp profile
   add local-address=192.168.88.1 name=L2TP_Profile remote-address=L2TP_VPN use-encryption=required

   建立VPN Profile,use-encryption必須要是required或是Yes,否則有可能無法連線
   如果只是要存取內網的資源,DNS可以不必填,而如果是經過VPN上網或翻牆,DNS一定要填。

3. 建立 L2TP 連線用的帳號密碼
   Winbox > PPP > Secrets

   name : 帳號(l2tp_user)
   password : 密碼(l2tp_pwd)
   service : l2tp
   profile : 選上面建立出的L2TP_Profile
 
   /ppp secret
   add name=l2tp_user password=l2tp_pwd profile=L2TP_Profile service=l2tp

4. 啟動L2TP server,設定Ipsec共享金鑰。
   Winbox > PPP > Interface 有個L2TP Server

   default-profile : 選上面的L2TP_Profile
   ipsec-secret : ipsec密鑰(ipsec_pwd)

   /interface l2tp-server server
   set default-profile=L2TP_Profile enabled=yes ipsec-secret=ipsec_pwd use-ipsec=yes

5. 開啟對應的防火牆L2TP則是udp port 1701/500/4500。
   Winbox > IP > Firewall > Filter Rules
   新增一組filter rule, 接受由WAN(ether1_WAN)來的upd port 1701, 500, 4500 L2TP連線
   /ip firewall filter
   add action=accept chain=input comment="Accept L2TP VPN" dst-port=1701,500,4500 in-interface=ether1_WAN protocol=udp

6. 讓VPN連線後, 可以ping到內網的device
   須要對VPN連線進來ip做偽裝
   Winbox > IP > Firewall > Address Lists
   新增一組list, 192.168.88.200-192.168.88.220
   /ip firewall address-list
   add address=192.168.88.200-192.168.88.220 list=VPN

   Winbox > IP > Firewall > NAT
   新增一組NAT, srcnat, 由VPN ip來,但不是要到VPN ip的做偽裝
   /ip firewall nat
   add action=masquerade chain=srcnat comment="VPN NAT" dst-address-list=!VPN src-address-list=VPN

7. iOS設定
   設定 > 一般 > VPN > 加入VPN設定
   類型 : L2TP
   描述 : 自行取個名字, e.g. HomeVPN
   伺服器 : 社區網路的對外IP, 111.222.333.444
   帳號 : l2tp的帳號, l2tp_user
   密碼 : l2tp的密碼, l2tp_pwd
   密鑰 : ipsec密鑰, ipsec_pwd

沒有留言:

張貼留言

在Raspberry Pi 2B上跑Docker, AdguardHome, Bitwarden, RPi-Monitor

在Raspberry Pi 2B上跑Docker, AdguardHome, Bitwarden, RPi-Monitor 請先參考前置準備工作 安裝Raspberry Pi 2B 來跑docker 前置準備 安全性考量, 移除預設pi帳號 Ref :     h...