我正在尝试在 docker-compose 中使用 openvpn 创建对称 VPN 服务器。如下所示:
---
version: "3"
services:
vpn:
image: whitebox/vpn:0.2
networks:
- standard
tty: true
ports:
- "1194:1194/udp"
volumes:
- ./server:/home/server:ro
- ./static.key:/home/static.key:ro
cap_add:
- NET_ADMIN
- SYS_MODULE
restart: always
networks:
standard:
ipv4_address: "10.10.0.254"
web:
image: tutum/apache-php
volumes:
- ./web:/var/www/html:ro
- ./client:/home/client:ro
networks:
standard:
ipv4_address: "10.10.0.2"
networks:
standard:
driver: bridge
ipam:
config:
- subnet: 10.10.0.0/16
启动后,我(暂时)手动安装 openvpn,进行一些基本配置并启动服务。一切似乎都运行正常,只是我无法从任何设备连接到它。
服务器配置文件:
ifconfig 10.10.0.254 10.10.0.10
verb 3
secret static.key
keepalive 1 10
persist-key
persist-tun
proto udp
port 1195
dev tun
status /home/vpn.log
客户端配置文件:
remote 192.168.37.137 1194
dev tun
ifconfig 10.10.0.10 10.10.0.254
secret static.key
奇怪的是,我尝试在一个简单的虚拟机上安装完全相同的服务器,一切正常。客户端可以连接到它并访问 10.10.0.0/16 网络。不过,这是客户端的连接日志:
Wed Aug 11 00:37:16 2021 TUN/TAP device tun0 opened
Wed Aug 11 00:37:16 2021 /sbin/ip link set dev tun0 up mtu 1500
Wed Aug 11 00:37:16 2021 /sbin/ip addr add dev tun0 local 10.10.0.10 peer 10.10.0.254
Wed Aug 11 00:37:16 2021 TCP/UDP: Preserving recently used remote address: [AF_INET]192.168.37.137:1194
Wed Aug 11 00:37:16 2021 UDP link local (bound): [AF_INET][undef]:1194
Wed Aug 11 00:37:16 2021 UDP link remote: [AF_INET]192.168.37.137:1194
以及相应的基于容器的服务器:
Wed Aug 11 07:34:40 2021 TUN/TAP device tun0 opened
Wed Aug 11 07:34:40 2021 TUN/TAP TX queue length set to 100
Wed Aug 11 07:34:40 2021 /sbin/ip link set dev tun0 up mtu 1500
Wed Aug 11 07:34:40 2021 /sbin/ip addr add dev tun0 local 10.10.0.254 peer 10.10.0.10
Wed Aug 11 07:34:40 2021 Could not determine IPv4/IPv6 protocol. Using AF_INET
Wed Aug 11 07:34:40 2021 Socket Buffers: R=[212992->212992] S=[212992->212992]
Wed Aug 11 07:34:40 2021 UDPv4 link local (bound): [AF_INET][undef]:1195
Wed Aug 11 07:34:40 2021 UDPv4 link remote: [AF_UNSPEC]
如您所见,没有建立任何连接。有人知道为什么吗?
答案1
确保端口配置正确。
您正在将端口 1194 转发到您的容器,但 OpenVPN 配置为监听端口 1195。