大网数据广告活动
服务器运维问答

Access VPN of docker container from outside (host machine or other containers)

· 52CE 我爱测

I have few docker containers on the same machine and one of them is running OpenVPN server, so it has network interface tun0 ( 192.168.255.1 ). This virtual private network has one client 192.168.255.2 remotely. I need to be able…

问题原文

原帖链接 · Andrii Zymohliad · CC BY-SA 3.0

I have few docker containers on the same machine and one of them is running OpenVPN server, so it has network interface tun0 (192.168.255.1). This virtual private network has one client 192.168.255.2 remotely.
I need to be able to communicate with that remote client from another docker containers or from the host machine, as if they would be in the same local network. I added route on the host machine:

# ip route add 192.168.255.0/24 dev docker0 

Now I can ping 192.168.255.1 (VPN server) but clients are unreachable:

# ping 192.168.255.2
PING 192.168.255.2 (192.168.255.2) 56(84) bytes of data.
From 172.17.0.1 icmp_seq=1 Destination Host Unreachable
From 172.17.0.1 icmp_seq=2 Destination Host Unreachable
From 172.17.0.1 icmp_seq=3 Destination Host Unreachable

I tried TAP and TUN OpenVPN device modes, default and subnet topologies - doesn't help

已采纳解答

原帖链接 · Huygens · CC BY-SA 3.0

You should have a look at my answer here: https://serverfault.com/a/879809/67419 that's exactly what I have configured execpt that I did not use the default Docker bridge but created a dedicated one. But it would work similarly with the default bridge.

You indeed have to add the proper route (as you did), but you also need at least to allow FORWARDING on your iptables, something like sudo iptables -A FORWARD -i tun+ -j ACCEPT.

Make sure also to have client-to-client and topology subnet at least in your OpenVPN server configuration.

All the details are in my other answer.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。