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

對於無法立即更新,我深表歉意。我實際上已經完成了這個任務。我成功地將客戶端連接到伺服器。兩者都像普通 LAN 一樣連接,並且還可以連接到與任一 PC 連接的其他板。感謝所有檢查我的問題的人。

我的解決方案:

我將伺服器和客戶端的所有配置保持不變。我所要做的就是為客戶端的 tap0 介面分配一個 IP(並且不要忘記“sudo ip link set up tap0”)。然後tap0介面可以從客戶端到伺服器相互通信,反之亦然。

僅供參考:由於我希望伺服器能夠與客戶端的一塊板進行通信,因此我將實體介面和分接介面連接到橋接器。然後我為網橋分配實體介面中的 IP。確保用戶端指派的 IP 與伺服器位於相同子網路中。例如:192.168.x.25 和 192.168.x.26。

此設定允許我的兩台 PC 相互通信,甚至允許連接到 PC 的板進行通訊。

再次感謝所有提供幫助的人!

相關內容