Skip to content

Commit 73cf665

Browse files
committed
Update docs
- Add advanced usage section for enabling IKEv2 perfect forward secrecy, including per-client steps (macOS/iOS, Windows, RouterOS).
1 parent a6add0e commit 73cf665

7 files changed

Lines changed: 79 additions & 0 deletions

File tree

README-ja.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ https://gitlab.com/hwdsl2/setup-ipsec-vpn/-/raw/master/extras/vpnupgrade.sh
386386
- [代替DNSサーバーの使用](docs/advanced-usage.md#use-alternative-dns-servers)
387387
- [DNS名とサーバーIPの変更](docs/advanced-usage.md#dns-name-and-server-ip-changes)
388388
- [IKEv2専用VPN](docs/advanced-usage.md#ikev2-only-vpn)
389+
- [IKEv2完全前方秘匿性を有効にする](docs/advanced-usage.md#enable-ikev2-perfect-forward-secrecy)
389390
- [内部VPN IPとトラフィック](docs/advanced-usage.md#internal-vpn-ips-and-traffic)
390391
- [VPNサーバーのパブリックIPを指定する](docs/advanced-usage.md#specify-vpn-servers-public-ip)
391392
- [VPNサブネットのカスタマイズ](docs/advanced-usage.md#customize-vpn-subnets)

README-ru.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ https://gitlab.com/hwdsl2/setup-ipsec-vpn/-/raw/master/extras/vpnupgrade.sh
386386
- [Использование альтернативных DNS-серверов](docs/advanced-usage.md#use-alternative-dns-servers)
387387
- [Изменения DNS-имени и IP-адреса сервера](docs/advanced-usage.md#dns-name-and-server-ip-changes)
388388
- [VPN только с IKEv2](docs/advanced-usage.md#ikev2-only-vpn)
389+
- [Включить совершенную прямую секретность IKEv2](docs/advanced-usage.md#enable-ikev2-perfect-forward-secrecy)
389390
- [Внутренние IP-адреса VPN и трафик](docs/advanced-usage.md#internal-vpn-ips-and-traffic)
390391
- [Указание публичного IP-адреса VPN-сервера](docs/advanced-usage.md#specify-vpn-servers-public-ip)
391392
- [Настройка подсетей VPN](docs/advanced-usage.md#customize-vpn-subnets)

README-zh-Hant.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ https://gitlab.com/hwdsl2/setup-ipsec-vpn/-/raw/master/extras/vpnupgrade.sh
386386
- [使用其他 DNS 伺服器](docs/advanced-usage-zh.md#使用其他的-dns-服务器)
387387
- [網域名稱與變更伺服器 IP](docs/advanced-usage-zh.md#域名和更改服务器-ip)
388388
- [僅限 IKEv2 的 VPN](docs/advanced-usage-zh.md#仅限-ikev2-的-vpn)
389+
- [啟用 IKEv2 前向保密](docs/advanced-usage-zh.md#启用-ikev2-前向保密)
389390
- [VPN 內網 IP 與流量](docs/advanced-usage-zh.md#vpn-内网-ip-和流量)
390391
- [指定 VPN 伺服器的公有 IP](docs/advanced-usage-zh.md#指定-vpn-服务器的公有-ip)
391392
- [自訂 VPN 子網](docs/advanced-usage-zh.md#自定义-vpn-子网)

README-zh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ https://gitlab.com/hwdsl2/setup-ipsec-vpn/-/raw/master/extras/vpnupgrade.sh
386386
- [使用其他的 DNS 服务器](docs/advanced-usage-zh.md#使用其他的-dns-服务器)
387387
- [域名和更改服务器 IP](docs/advanced-usage-zh.md#域名和更改服务器-ip)
388388
- [仅限 IKEv2 的 VPN](docs/advanced-usage-zh.md#仅限-ikev2-的-vpn)
389+
- [启用 IKEv2 前向保密](docs/advanced-usage-zh.md#启用-ikev2-前向保密)
389390
- [VPN 内网 IP 和流量](docs/advanced-usage-zh.md#vpn-内网-ip-和流量)
390391
- [指定 VPN 服务器的公有 IP](docs/advanced-usage-zh.md#指定-vpn-服务器的公有-ip)
391392
- [自定义 VPN 子网](docs/advanced-usage-zh.md#自定义-vpn-子网)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ See [Advanced usage](docs/advanced-usage.md).
386386
- [Use alternative DNS servers](docs/advanced-usage.md#use-alternative-dns-servers)
387387
- [DNS name and server IP changes](docs/advanced-usage.md#dns-name-and-server-ip-changes)
388388
- [IKEv2-only VPN](docs/advanced-usage.md#ikev2-only-vpn)
389+
- [Enable IKEv2 perfect forward secrecy](docs/advanced-usage.md#enable-ikev2-perfect-forward-secrecy)
389390
- [Internal VPN IPs and traffic](docs/advanced-usage.md#internal-vpn-ips-and-traffic)
390391
- [Specify VPN server's public IP](docs/advanced-usage.md#specify-vpn-servers-public-ip)
391392
- [Customize VPN subnets](docs/advanced-usage.md#customize-vpn-subnets)

docs/advanced-usage-zh.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [使用其他的 DNS 服务器](#使用其他的-dns-服务器)
66
* [域名和更改服务器 IP](#域名和更改服务器-ip)
77
* [仅限 IKEv2 的 VPN](#仅限-ikev2-的-vpn)
8+
* [启用 IKEv2 前向保密](#启用-ikev2-前向保密)
89
* [VPN 内网 IP 和流量](#vpn-内网-ip-和流量)
910
* [指定 VPN 服务器的公有 IP](#指定-vpn-服务器的公有-ip)
1011
* [自定义 VPN 子网](#自定义-vpn-子网)
@@ -73,6 +74,42 @@ sudo bash ikev2only.sh
7374
另外,你也可以手动启用仅限 IKEv2 模式。首先使用 `ipsec --version` 命令检查 Libreswan 版本,并[更新 Libreswan](../README-zh.md#升级libreswan)(如果需要)。然后编辑 VPN 服务器上的 `/etc/ipsec.conf`。将 `ikev1-policy=accept` 替换为 `ikev1-policy=drop`。如果该行不存在,则在 `config setup` 小节的末尾添加 `ikev1-policy=drop`,开头必须空两格。保存文件并运行 `service ipsec restart`。在完成后,你可以使用 `ipsec status` 命令来验证仅启用了 `ikev2-cp` 连接。
7475
</details>
7576

77+
## 启用 IKEv2 前向保密
78+
79+
默认情况下,IKEv2 子安全关联(Child SA)从现有 IKE SA 派生密钥材料,不进行新的 Diffie-Hellman 交换(`pfs=no`)。启用前向保密(PFS)后,每次子 SA 重新生成密钥时都会执行新的 DH 交换,从而确保即使服务器私钥在将来遭到泄露,攻击者也无法解密之前录制的会话。
80+
81+
**注:** IKE SA 已将 ECP-256(`aes_gcm_c_256-hmac_sha2_256-ecp_256`)作为首选提案,所有现代客户端均会协商使用,因此这些客户端的会话密钥已与长期密钥材料独立。为子 SA 启用 PFS 是一项渐进式安全加固措施,而非关键漏洞修复。
82+
83+
**客户端兼容性:** 所有现代客户端均支持 PFS。但是,macOS 和 iOS 客户端需要重新导出并导入已将 `EnablePFS` 设为 `1``.mobileconfig` 配置文件(详见下文)。Windows 客户端需要更新连接配置。RouterOS 用户需将 IKEv2 配置文件中的 `pfs-group=none` 改为 `pfs-group=ecp256`。Android 和 Linux strongSwan 客户端无需更改。Windows 7 IKEv2 客户端不支持 ECP PFS 组,若服务器启用 PFS,将无法连接。
84+
85+
要在服务器上启用 PFS,请编辑 `/etc/ipsec.d/ikev2.conf`,将 `conn ikev2-cp` 部分中的 `pfs=no` 改为 `pfs=yes`,然后重启 IPsec 服务:
86+
87+
```bash
88+
sudo sed -i 's/pfs=no/pfs=yes/' /etc/ipsec.d/ikev2.conf
89+
sudo service ipsec restart
90+
```
91+
92+
**Docker 用户:** 请先[在容器内打开 Bash shell](https://github.com/hwdsl2/docker-ipsec-vpn-server/blob/master/docs/advanced-usage-zh.md#在容器中运行-bash-shell),运行上述 `sed` 命令,然后 `exit` 并运行 `docker restart ipsec-vpn-server`
93+
94+
启用 PFS 后,需要更新以下客户端配置:
95+
96+
- **macOS / iOS:** 使用 `sudo ikev2.sh --exportclient <名称>` 重新导出客户端 `.mobileconfig` 文件,然后编辑导出的文件以启用 PFS:
97+
```bash
98+
sed -i '/EnablePFS/{n;s/0/1/;}' <名称>.mobileconfig
99+
```
100+
在设备上重新导入更新后的文件。
101+
- **Windows:** 在提升权限的 PowerShell 窗口中运行 `Set-VpnConnection -Name "你的VPN名称" -PfsGroup ECP256`(替换为实际的 VPN 连接名称),然后重新连接 VPN。
102+
- **RouterOS (MikroTik):** 在 IKEv2 对等配置文件中,将 `pfs-group=none` 改为 `pfs-group=ecp256`
103+
104+
Android 和 Linux strongSwan 客户端无需更改,PFS 会自动协商。
105+
106+
要恢复默认设置(禁用 PFS):
107+
108+
```bash
109+
sudo sed -i 's/pfs=yes/pfs=no/' /etc/ipsec.d/ikev2.conf
110+
sudo service ipsec restart
111+
```
112+
76113
## VPN 内网 IP 和流量
77114

78115
在使用 [IPsec/L2TP](clients-zh.md) 模式连接时,VPN 服务器在虚拟网络 `192.168.42.0/24` 内具有内网 IP `192.168.42.1`。为客户端分配的内网 IP 在这个范围内:`192.168.42.10``192.168.42.250`。要找到为特定的客户端分配的 IP,可以查看该 VPN 客户端上的连接状态。

docs/advanced-usage.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [Use alternative DNS servers](#use-alternative-dns-servers)
66
* [DNS name and server IP changes](#dns-name-and-server-ip-changes)
77
* [IKEv2-only VPN](#ikev2-only-vpn)
8+
* [Enable IKEv2 perfect forward secrecy](#enable-ikev2-perfect-forward-secrecy)
89
* [Internal VPN IPs and traffic](#internal-vpn-ips-and-traffic)
910
* [Specify VPN server's public IP](#specify-vpn-servers-public-ip)
1011
* [Customize VPN subnets](#customize-vpn-subnets)
@@ -73,6 +74,42 @@ Alternatively, you may manually enable IKEv2-only mode.
7374
Alternatively, you may manually enable IKEv2-only mode. First check Libreswan version using `ipsec --version`, and [update Libreswan](../README.md#upgrade-libreswan) if needed. Then edit `/etc/ipsec.conf` on the VPN server. Replace `ikev1-policy=accept` with `ikev1-policy=drop`. If the line does not exist, append `ikev1-policy=drop` to the end of the `config setup` section, indented by two spaces. Save the file and run `service ipsec restart`. When finished, you can run `ipsec status` to verify that only the `ikev2-cp` connection is enabled.
7475
</details>
7576

77+
## Enable IKEv2 perfect forward secrecy
78+
79+
By default, IKEv2 Child SAs derive keying material from the existing IKE SA without a new Diffie-Hellman exchange (`pfs=no`). Enabling perfect forward secrecy (PFS) causes each Child SA rekey to perform a fresh DH exchange, so that a future compromise of the server's private key cannot decrypt previously recorded sessions.
80+
81+
**Note:** The IKE SA already proposes ECP-256 as its first preference (`aes_gcm_c_256-hmac_sha2_256-ecp_256`), and all modern clients negotiate it, so session keys are already independent of the server's long-term private key for those clients. Enabling PFS for Child SAs is an incremental hardening step, not a critical gap.
82+
83+
**Client compatibility:** All modern clients support PFS. However, macOS and iOS clients require re-export and re-import of the `.mobileconfig` profile with `EnablePFS` set to `1` (see below). Windows clients require a connection update. RouterOS users must change `pfs-group=none` to `pfs-group=ecp256` in their IKEv2 profile. Android and Linux strongSwan clients require no changes. Windows 7 IKEv2 clients do not support ECP PFS groups and will fail to connect if PFS is enabled on the server.
84+
85+
To enable PFS on the server, edit `/etc/ipsec.d/ikev2.conf` and change `pfs=no` to `pfs=yes` in the `conn ikev2-cp` section, then restart the IPsec service:
86+
87+
```bash
88+
sudo sed -i 's/pfs=no/pfs=yes/' /etc/ipsec.d/ikev2.conf
89+
sudo service ipsec restart
90+
```
91+
92+
**Docker users:** Open a [Bash shell inside the container](https://github.com/hwdsl2/docker-ipsec-vpn-server/blob/master/docs/advanced-usage.md#bash-shell-inside-container), run the `sed` command above, then `exit` and run `docker restart ipsec-vpn-server`.
93+
94+
After enabling PFS, the following client configurations must be updated:
95+
96+
- **macOS / iOS:** Re-export the client `.mobileconfig` using `sudo ikev2.sh --exportclient <name>`, then edit the exported file to enable PFS:
97+
```bash
98+
sed -i '/EnablePFS/{n;s/0/1/;}' <name>.mobileconfig
99+
```
100+
Re-import the updated file on your device.
101+
- **Windows:** In an elevated PowerShell window, run `Set-VpnConnection -Name "Your VPN Name" -PfsGroup ECP256` (replace with your actual VPN connection name), then reconnect the VPN.
102+
- **RouterOS (MikroTik):** In the IKEv2 peer profile, change `pfs-group=none` to `pfs-group=ecp256`.
103+
104+
Android and Linux strongSwan clients require no changes; PFS is auto-negotiated.
105+
106+
To revert to the default (PFS disabled):
107+
108+
```bash
109+
sudo sed -i 's/pfs=yes/pfs=no/' /etc/ipsec.d/ikev2.conf
110+
sudo service ipsec restart
111+
```
112+
76113
## Internal VPN IPs and traffic
77114

78115
When connecting using [IPsec/L2TP](clients.md) mode, the VPN server has internal IP `192.168.42.1` within the VPN subnet `192.168.42.0/24`. Clients are assigned internal IPs from `192.168.42.10` to `192.168.42.250`. To check which IP is assigned to a client, view the connection status on the VPN client.

0 commit comments

Comments
 (0)