问题:
通过 OpenVPN 从网络外部连接到路由器,并通过 VPN 设置所有流量可以访问:
路由器本身
路由器后面的 LAN 主机
无效的方法:
局域网外的网络访问
DNS 解析(尽管 DNS 是通过 VPN 推送的)
对外部 IP 执行 ping 操作会报告“目标端口不可达”。
对于任何请求,tcpdump 都会填充
12:03:22.070072 IP 10.8.4.2 > 10.8.4.1: ICMP 10.8.4.2 udp port 49763 unreachable, length 93
其中 10.8.4.2 是客户端 IP,10.8.4.1 是服务器(端口会发生变化)。
设置:
- OpenWRT 路由器(Turris Omnia),内部网络为 192.168.10.0/24
- OpenVPN 监听端口 1196(开放且可访问)
- 路由器上的端口 443 重定向到 1196(针对阻止 1196 的网络)
- 防火墙中定义了三个区域:
vpn
、、lan
。wan
- 客户端:Android 8 客户端,带有适用于 Android 的 OpenVPN(Nexus 5X)
openvpn配置:
port 1196
proto tcp
dev tun2
ca /etc/openvpn/ca.crt
cert /etc/openvpn/mycrt.crt
key /etc/openvpn/mycrt.key # This file should be kept secret
dh /etc/openvpn/dh2048.pem
server 10.8.4.0 255.255.255.0
ifconfig-pool-persist /tmp/openvpn/clients/ipp-local.txt
client-config-dir ccd
client-to-client
keepalive 10 120
tls-auth /etc/openvpn/ta.key 0
comp-lzo no
persist-key
persist-tun
status /tmp/log/openvpn-status.log
verb 3
mute 20
push "route 192.168.10.0 255.255.255.0"
push "route 192.168.20.0 255.255.255.0"
mssfix
cipher AES-256-CBC
auth SHA512
tls-cipher TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-256-CBC-SHA:TLS-DHE-RSA-WITH-CAMELLIA-256-CBC-SHA:TLS-DHE-RSA-WITH-AES-128-CBC-SHA:TLS-DHE-RSA-WITH-CAMELLIA-128-CBC-SHA
status /var/log/openvpn-server-status.log
topology subnet
重定向完成于ccd/myclient
:
push "redirect-gateway local def1"
push "dhcp-option DNS 192.168.10.1"
现在openWRT端的配置是:
/etc/config/openvpn
config openvpn 'local_service'
option config '/etc/openvpn/server-local.conf'
option enabled '1'
/etc/config/网络
config interface 'vpn2'
option ifname 'tun2'
option proto 'none'
option auto '1'
/etc/config/防火墙
config zone
option input 'ACCEPT'
option output 'ACCEPT'
option name 'vpn'
option masq '1'
option forward 'ACCEPT'
option mtu_fix '1'
option network 'vpn2'
config forwarding
option dest 'vpn'
option src 'lan'
config forwarding
option dest 'lan'
option src 'vpn'
config forwarding
option dest 'wan'
option src 'vpn'
config redirect
option target 'DNAT'
option src 'wan'
option dest 'lan'
option proto 'tcp'
option src_dport '443'
option dest_ip '192.168.10.1'
option dest_port '1196'
option name 'openvpn https'
客户端配置:
# Enables connection to GUI
management /data/user/0/de.blinkt.openvpn/cache/mgmtsocket unix
management-client
management-query-passwords
management-hold
setenv IV_GUI_VER "de.blinkt.openvpn 0.6.73"
setenv IV_PLAT_VER "27 8.1.0 arm64-v8a google bullhead Nexus 5X"
machine-readable-output
allow-recursive-routing
ifconfig-nowarn
client
verb 4
connect-retry 2 300
resolv-retry 60
dev tun
remote my-remote-gateway.example.com 443 tcp-client
<ca>
REDACTED
</ca>
<key>
REDACTED
</key>
<cert>
REDACTED
</cert>
comp-lzo
<tls-auth>
REDACTED
</tls-auth>
key-direction 1
route 0.0.0.0 0.0.0.0 vpn_gateway
verify-x509-name seldon name
remote-cert-tls server
cipher AES-256-CBC
auth SHA512
# Use system proxy setting
management-query-proxy
答案1
问题解决了。实际上二问题:
- 防火墙不允许从 VPN 转发到服务器外部;
- 指定的 DNS IP 与通过 VPN 分配的 IP 位于不同的子网,因此无法正常工作
wan
在和之间的 openWRT 中启用转发vpn
并为 DNS 设置正确的地址解决了这些问题。