Update docs
- Add advanced usage section for forwarding port(s) to VPN clients
This commit is contained in:
parent
b129339927
commit
340c474197
@ -211,6 +211,7 @@ wget https://git.io/vpnupgrade -O vpnup.sh && sudo sh vpnup.sh
|
||||
- [使用其他的 DNS 服务器](docs/advanced-usage-zh.md#使用其他的-dns-服务器)
|
||||
- [域名和更改服务器 IP](docs/advanced-usage-zh.md#域名和更改服务器-ip)
|
||||
- [VPN 内网 IP 和流量](docs/advanced-usage-zh.md#vpn-内网-ip-和流量)
|
||||
- [转发端口到 VPN 客户端](docs/advanced-usage-zh.md#转发端口到-vpn-客户端)
|
||||
- [VPN 分流](docs/advanced-usage-zh.md#vpn-分流)
|
||||
- [访问 VPN 服务器的网段](docs/advanced-usage-zh.md#访问-vpn-服务器的网段)
|
||||
- [仅限 IKEv2 的 VPN](docs/advanced-usage-zh.md#仅限-ikev2-的-vpn)
|
||||
|
@ -211,6 +211,7 @@ See [Advanced usage](docs/advanced-usage.md).
|
||||
- [Use alternative DNS servers](docs/advanced-usage.md#use-alternative-dns-servers)
|
||||
- [DNS name and server IP changes](docs/advanced-usage.md#dns-name-and-server-ip-changes)
|
||||
- [Internal VPN IPs and traffic](docs/advanced-usage.md#internal-vpn-ips-and-traffic)
|
||||
- [Port forwarding to VPN clients](docs/advanced-usage.md#port-forwarding-to-vpn-clients)
|
||||
- [Split tunneling](docs/advanced-usage.md#split-tunneling)
|
||||
- [Access VPN server's subnet](docs/advanced-usage.md#access-vpn-servers-subnet)
|
||||
- [IKEv2 only VPN](docs/advanced-usage.md#ikev2-only-vpn)
|
||||
|
@ -5,6 +5,7 @@
|
||||
* [使用其他的 DNS 服务器](#使用其他的-dns-服务器)
|
||||
* [域名和更改服务器 IP](#域名和更改服务器-ip)
|
||||
* [VPN 内网 IP 和流量](#vpn-内网-ip-和流量)
|
||||
* [转发端口到 VPN 客户端](#转发端口到-vpn-客户端)
|
||||
* [VPN 分流](#vpn-分流)
|
||||
* [访问 VPN 服务器的网段](#访问-vpn-服务器的网段)
|
||||
* [仅限 IKEv2 的 VPN](#仅限-ikev2-的-vpn)
|
||||
@ -113,6 +114,30 @@ iptables -I FORWARD 4 -i ppp+ -d 192.168.43.0/24 -j DROP
|
||||
iptables -I FORWARD 5 -s 192.168.43.0/24 -o ppp+ -j DROP
|
||||
```
|
||||
|
||||
## 转发端口到 VPN 客户端
|
||||
|
||||
在某些情况下,你可能想要将 VPN 服务器上的端口转发到一个已连接的 VPN 客户端。这可以通过在 VPN 服务器上添加 IPTables 规则来实现。如果要在重新启动后继续有效,你可以将这些命令添加到 `/etc/rc.local`。
|
||||
|
||||
**警告:** 端口转发会将 VPN 客户端上的端口暴露给整个因特网,这可能会带来**安全风险**!
|
||||
|
||||
**注:** 为 VPN 客户端分配的内网 IP 是动态的,而且客户端设备上的防火墙可能会阻止转发的流量。如果要将静态 IP 分配给 VPN 客户端,请参见上一节。要找到为特定的客户端分配的 IP,可以查看该 VPN 客户端上的连接状态。
|
||||
|
||||
示例 1:将 VPN 服务器上的 TCP 端口 443 转发到位于 `192.168.42.10` 的 IPsec/L2TP 客户端。
|
||||
```
|
||||
# 获取默认网络接口名称
|
||||
ifname=$(route 2>/dev/null | grep -m 1 '^default' | grep -o '[^ ]*$')
|
||||
iptables -I FORWARD 2 -i "$ifname" -o ppp+ -p tcp --dport 443 -j ACCEPT
|
||||
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to 192.168.42.10
|
||||
```
|
||||
|
||||
示例 2:将 VPN 服务器上的 UDP 端口 123 转发到位于 `192.168.43.10` 的 IKEv2(或 IPsec/XAuth)客户端。
|
||||
```
|
||||
# 获取默认网络接口名称
|
||||
ifname=$(route 2>/dev/null | grep -m 1 '^default' | grep -o '[^ ]*$')
|
||||
iptables -I FORWARD 2 -i "$ifname" -d 192.168.43.0/24 -p udp --dport 123 -j ACCEPT
|
||||
iptables -t nat -A PREROUTING -p udp --dport 123 -j DNAT --to 192.168.43.10
|
||||
```
|
||||
|
||||
## VPN 分流
|
||||
|
||||
在启用 [VPN 分流 (split tunneling)](https://wiki.strongswan.org/projects/strongswan/wiki/ForwardingAndSplitTunneling#Split-Tunneling) 时,VPN 客户端将仅通过 VPN 隧道发送特定目标子网的流量。其他流量 **不会** 通过 VPN 隧道。VPN 分流 [有一些局限性](https://wiki.strongswan.org/projects/strongswan/wiki/ForwardingAndSplitTunneling#Split-Tunneling),而且并非所有的 VPN 客户端都支持。
|
||||
|
@ -5,6 +5,7 @@
|
||||
* [Use alternative DNS servers](#use-alternative-dns-servers)
|
||||
* [DNS name and server IP changes](#dns-name-and-server-ip-changes)
|
||||
* [Internal VPN IPs and traffic](#internal-vpn-ips-and-traffic)
|
||||
* [Port forwarding to VPN clients](#port-forwarding-to-vpn-clients)
|
||||
* [Split tunneling](#split-tunneling)
|
||||
* [Access VPN server's subnet](#access-vpn-servers-subnet)
|
||||
* [IKEv2 only VPN](#ikev2-only-vpn)
|
||||
@ -113,6 +114,30 @@ iptables -I FORWARD 4 -i ppp+ -d 192.168.43.0/24 -j DROP
|
||||
iptables -I FORWARD 5 -s 192.168.43.0/24 -o ppp+ -j DROP
|
||||
```
|
||||
|
||||
## Port forwarding to VPN clients
|
||||
|
||||
In certain circumstances, you may want to forward port(s) on the VPN server to a connected VPN client. This can be done by adding IPTables rules on the VPN server. To persist after reboot, add these commands to `/etc/rc.local`.
|
||||
|
||||
**Warning:** Port forwarding will expose port(s) on the VPN client to the entire Internet, which could be a **security risk**!
|
||||
|
||||
**Note:** The internal VPN IPs assigned to VPN clients are dynamic, and firewalls on client devices may block forwarded traffic. To assign static IPs to VPN clients, refer to the previous section. To check which IP is assigned to a client, view the connection status on the VPN client.
|
||||
|
||||
Example 1: Forward TCP port 443 on the VPN server to the IPsec/L2TP client at `192.168.42.10`.
|
||||
```
|
||||
# Get default network interface name
|
||||
ifname=$(route 2>/dev/null | grep -m 1 '^default' | grep -o '[^ ]*$')
|
||||
iptables -I FORWARD 2 -i "$ifname" -o ppp+ -p tcp --dport 443 -j ACCEPT
|
||||
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to 192.168.42.10
|
||||
```
|
||||
|
||||
Example 2: Forward UDP port 123 on the VPN server to the IKEv2 (or IPsec/XAuth) client at `192.168.43.10`.
|
||||
```
|
||||
# Get default network interface name
|
||||
ifname=$(route 2>/dev/null | grep -m 1 '^default' | grep -o '[^ ]*$')
|
||||
iptables -I FORWARD 2 -i "$ifname" -d 192.168.43.0/24 -p udp --dport 123 -j ACCEPT
|
||||
iptables -t nat -A PREROUTING -p udp --dport 123 -j DNAT --to 192.168.43.10
|
||||
```
|
||||
|
||||
## Split tunneling
|
||||
|
||||
With [split tunneling](https://wiki.strongswan.org/projects/strongswan/wiki/ForwardingAndSplitTunneling#Split-Tunneling), VPN clients will only send traffic for specific destination subnet(s) through the VPN tunnel. Other traffic will NOT go through the VPN tunnel. Split tunneling has [some limitations](https://wiki.strongswan.org/projects/strongswan/wiki/ForwardingAndSplitTunneling#Split-Tunneling), and is not supported by all VPN clients.
|
||||
|
Loading…
Reference in New Issue
Block a user