port 1194 proto udp dev tap0 ca /etc/openvpn/easy-rsa/keys/ca.crt cert /etc/openvpn/easy-rsa/keys/server.crt key /etc/openvpn/easy-rsa/keys/server.key dh /etc/openvpn/easy-rsa/keys/dh2048.pem # brtctl upscript script-security 2 up /etc/openvpn/up.sh tls-server server-bridge keepalive 10 120 comp-lzo persist-key persist-tun status openvpn-status.log verb 3
服务器在网络A中运行的Debian机器上运行,客户端在网络B中的OpenWRT路由器上运行.在网络A上,tap0接口与本地网络桥接,包含DHCP服务器和到Internet的网关.在网络B上,tap0接口与没有DHCP服务器或互联网访问的单独网络桥接.这个想法是OpenVPN隧道为网络B提供互联网接入.
在此设置中,OpenVPN服务器不会分配IP地址供客户端使用.相反,它只是让本地网络中的DHCP服务器处理它.这是有效的,因为这是桥接(TAP),而不是路由(TUN)设置.
因此,DHCP确实可以在隧道上工作.网络B侧的客户端直接从网络A侧的DHCP服务器获取其IP地址.问题是看起来默认网关从DHCP回复中被剥离,因为它在网络B上的机器上是空的.
例如,这是我在连接到网络B的Windows客户端上获得的:
Ethernet adapter Ethernet: DHCP Enabled. . . . . . . . . . . : Yes Autoconfiguration Enabled . . . . : Yes IPv4 Address. . . . . . . . . . . : 192.168.2.123(Preferred) Subnet Mask . . . . . . . . . . . : 255.255.255.0 Lease Obtained. . . . . . . . . . : vrijdag 25 juli 2014 22:49:38 Lease Expires . . . . . . . . . . : zaterdag 26 juli 2014 10:49:38 Default Gateway . . . . . . . . . : DHCP Server . . . . . . . . . . . : 192.168.2.1 DNS Servers . . . . . . . . . . . : 8.8.8.8 NetBIOS over Tcpip. . . . . . . . : Enabled
我发现了这个:https://community.openvpn.net/openvpn/ticket/312#comment:3
这表明这是记录的行为,但我不知道如何禁用它.我尝试在客户端使用指令route-nopull,但它似乎没有任何效果.
此外,我不能使用redirect-gateway指令,因为我需要在与OpenVPN客户端的tap0适配器桥接的机器上获得网关,而不是在OpenVPN客户端本身.
我的客户端配置如下:
config openvpn sample_client option enabled 1 option client 1 option dev tap option proto udp list remote "server.com 1194" option resolv_retry infinite option nobind 1 option persist_key 1 option persist_tun 1 option ca /etc/openvpn/ca.crt option cert /etc/openvpn/client.crt option key /etc/openvpn/client.key option ns_cert_type server option comp_lzo yes option verb 3 option route-nopull 1
请记住,这是OpenWRT的UCI格式.
编辑:
刚刚在日志中找到了这个:
daemon.notice openvpn(sample_client)[5062]: Extracted DHCP router address: 192.168.2.1
这正是我想要禁用的行为.
还发现了这个:
If –server-bridge is used without any parameters, it will enable a DHCP-proxy mode, where connecting OpenVPN clients will receive an IP address for their TAP adapter from the DHCP server running on the OpenVPN server-side LAN. Note that only clients that support the binding of a DHCP client with the TAP adapter (such as Windows) can support this mode. The optional nogw flag (advanced) indicates that gateway information should not be pushed to the client.
有趣.我没有设置nogw.可能是隐含设置还是其他什么?我可以明确地解开它吗?
编辑:发现:https://forums.openvpn.net/topic13494.html
一个人有同样的问题,从一年前开始.没有答案. 根据OpenVPN文档 server-bridge是一个快捷方式mode server tls-server push "route-gateway dhcp"
和
server-bridge nogw是一个快捷方式
mode server tls-server
有趣的是,推送“route-gateway dhcp”激活一个DHCP代理,该代理在原始DHCP服务器的DHCP响应中分离出默认网关选项.这可以在OpenVPN日志中看到
daemon.notice openvpn [4879]:提取的DHCP路由器地址:a.b.c.d您的解决方案是使用server-bridge nogw,DHCP响应再次包含默认路由选项.
精彩评论