OpenVPN 第 2 层以太网桥接

OpenVPN 第 2 层以太网桥接

我有一个在 Ubuntu 18.04 机器上运行的 OpenVPN 服务器,我想通过以太网桥接(第 2 层)使用 Ubuntu 20.04 机器连接到该服务器。

我已经成功创建了 OpenVPN,但似乎无法连接到它。

我的客户端的tap0没有收到IP。

我还想声明一下,我对网络等方面还很陌生。

我的最终目标是为服务器和客户端都设置一个静态 IP 地址。我不想使用 DHCP。

以下是我的配置:

服务器配置文件

port 1194
proto udp
dev tap0
ca ca.crt
cert server.crt
key server.key  # This file should be kept secret
dh dh2048.pem

up "/etc/openvpn/up.sh br0 tap0 1500"
down "/etc/openvpn/down.sh br0 tap0"

# Configure server mode for ethernet bridging.
# You must first use your OS's bridging capability
# to bridge the TAP interface with the ethernet
# NIC interface.  Then you must manually set the
# IP/netmask on the bridge interface, here we
# assume 10.8.0.4/255.255.255.0.  Finally we
# must set aside an IP range in this subnet
# (start=10.8.0.50 end=10.8.0.100) to allocate
# to connecting clients.  Leave this line commented
# out unless you are ethernet bridging.
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100

# Configure server mode for ethernet bridging
# using a DHCP-proxy, where clients talk
# to the OpenVPN server-side DHCP server
# to receive their IP address allocation
# and DNS server addresses.  You must first use
# your OS's bridging capability to bridge the TAP
# interface with the ethernet NIC interface.
# Note: this mode only works on clients (such as
# Windows), where the client-side TAP adapter is
# bound to a DHCP client.
server-bridge

keepalive 10 120
tls-auth ta.key 0 # This file is secret
cipher AES-256-CBC
persist-key
persist-tun
status /var/log/openvpn/openvpn-status.log
verb 3
explicit-exit-notify 1

客户端.ovpn

client
dev tap
proto udp
remote hidden 1194
resolv-retry infinite
nobind
user nobody
group nogroup
persist-key
persist-tun

<ca>
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
</ca>

<cert>
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
</cert>

<key>
-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----
</key>

remote-cert-tls server

key-direction 1
<tls-auth>
-----BEGIN OpenVPN Static key V1-----
-----END OpenVPN Static key V1-----
</tls-auth>

cipher AES-256-CBC
verb 4

答案1

很抱歉不能立即更新。我实际上已经完成了这项任务。我成功地将客户端连接到了服务器。两者都像普通的局域网一样连接,也可以连接到连接到任一台 PC 的其他主板。感谢所有检查我的问题的人。

我的解决方案:

我保持服务器和客户端的所有配置相同。我所要做的就是在客户端为 tap0 接口分配一个 IP(不要忘记“sudo ip link set up tap0”)。然后 tap0 接口就可以在客户端和服务器之间相互通信,反之亦然。

仅供参考:由于我希望服务器能够与客户端的其中一个电路板通信,因此我将物理接口和分接接口连接到桥接器。然后我为桥接器分配物理接口中的 IP。确保客户端中分配的 IP 与服务器位于同一子网中。例如:192.168.x.25 和 192.168.x.26。

这种设置允许我的两台电脑相互通信,甚至允许连接到电脑的电路板通信。

再次感谢所有提供帮助的人!

相关内容