Docker - 连接到 VPN

Docker - 连接到 VPN

我的 Windows OpenVPN 服务器运行在 10.8.0.1。

服务器.ovpn 是:

server 10.8.0.0 255.255.255.0
port 1194

topology subnet

proto udp4       
dev tun

ca "C:\\Program Files\\OpenVPN\\config\\ca.crt"
cert "C:\\Program Files\\OpenVPN\\config\\server.crt"
key "C:\\Program Files\\OpenVPN\\config\\server.key"
dh "C:\\Program Files\\OpenVPN\\config\\dh2048.pem"

#for debug, allow same certs on all clients
duplicate-cn
        
keepalive 10 120

cipher AES-256-GCM

comp-lzo
persist-key
persist-tun
verb 3

explicit-exit-notify 1

我启动 WSL 并在 WSL2 (Ubuntu) 中通过以下方式运行 docker 映像:

docker run --gpus all --privileged -p 1777:1777 -p 1778:1778 --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 -it --rm -v/mnt/d/data:/mnt nvcr.io/nvidia/pytorch:23.06-py3

在 docker 内部,我通过以下方式安装网络工具和 OpenVPN:

apt update

apt -y install net-tools
apt -y install netcat
apt -y install iputils-ping
apt -y install iproute2
apt -y install iptables
apt -y install traceroute

apt -y install OpenVPN 

现在我安装到/mnt并运行

openvpn --config client.ovpn

客户端.ovpn 是:

client

dev tun
proto udp4
remote a.b.c.d 1194
resolv-retry infinite
nobind
persist-key
persist-tun

ca ca.crt
cert Client1.crt
key Client1.key    
remote-cert-tls server

cipher AES-256-GCM
comp-lzo
verb 3

(证书与 client.ovpn 位于同一目录中)

我认为连接已建立,因为如果我执行 ifconfig,我可以看到:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.15.1.1  netmask 255.255.255.0  broadcast 172.15.1.255
        ether 02:42:ac:0f:01:01  txqueuelen 0  (Ethernet)
        RX packets 22289  bytes 30846027 (30.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10953  bytes 734146 (734.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
        inet 10.8.0.2  netmask 255.255.255.0  destination 10.8.0.2
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

但是,当我从 docker 中执行ping 10.8.0.1(我也尝试过)时,我无法 ping 服务器或任何其他连接的客户端。 ping -I tun0 10.8.0.1Docker overeth0可以毫无问题地 ping 通互联网服务器。

我缺少什么?注意:我不是网络或 VPN 方面的专家

相关内容