我正在嘗試使用一對運行 OpenVPN 的 CentOS 7 系統將兩個網路連接在一起。
我有一個“伺服器”端,後面有兩個網絡,“客戶端”端有一個網絡。基本的 openvpn 連線已建立,但我認為路由或防火牆配置有問題。
OpenVPN 是 10.8.0.0/24 上的一個池。伺服器後面有網路10.254.1.0/24和10.255.1.0/24;客戶端後面有10.255.0.1。
伺服器將這些路由選項推送到 server.conf 中:
# Push any routes the client needs to get in
# to the local network.
push "route 10.254.1.0 255.255.255.0"
push "route 10.255.1.0 255.255.255.0"
這些在客戶端的路由表中正確顯示:
10.8.0.1 via 10.8.0.5 dev tun0
10.8.0.5 dev tun0 proto kernel scope link src 10.8.0.6
10.254.1.0/24 via 10.8.0.5 dev tun0
10.255.0.0/24 dev enp6s4f0 proto kernel scope link src 10.255.0.1 metric 100
10.255.1.0/24 via 10.8.0.5 dev tun0
……並且在伺服器端我手動設定了適當的路由:
10.8.0.0/24 via 10.8.0.2 dev tun0
10.8.0.2 dev tun0 proto kernel scope link src 10.8.0.1
10.255.0.0/24 via 10.8.0.2 dev tun0
...並且客戶端網關實際上可以對伺服器網路更深處的設備執行 ping 操作:
[root@sentry openvpn]# ping -c 1 10.254.1.10
PING 10.254.1.10 (10.254.1.10) 56(84) bytes of data.
64 bytes from 10.254.1.10: icmp_seq=1 ttl=63 time=300 ms
……但我無法 ssh 到它。
# ssh [email protected]
ssh: connect to host 10.254.1.10 port 22: No route to host
……所以,我認為這可能是防火牆問題。
在兩側,我都將 tun 介面新增到我的內部區域。
在客戶端:
# firewall-cmd --info-zone="internal"
internal (active)
target: default
icmp-block-inversion: no
interfaces: enp6s4f0 tun0
sources:
services: dhcp dhcpv6-client dns http mdns mosh samba-client snmp ssh syslog
ports: 8000/tcp
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks:
rich rules:
...和伺服器:
# firewall-cmd --info-zone="internal"
internal (active)
target: default
icmp-block-inversion: no
interfaces: ens161 ens256 tun0
sources:
services: dhcpv6-client mdns samba-client snmp ssh
ports:
protocols:
masquerade: no
forward-ports:
sourceports:
icmp-blocks:
rich rules:
現在,在伺服器上為了讓兩個內部網路相互通信,我必須添加直接 iptables 規則:
firewall-cmd --direct --add-rule ipv4 filter FORWARD 0 -i ens256 -o ens161 -j ACCEPT
firewall-cmd --direct --add-rule ipv4 filter FORWARD 0 -i ens161 -o ens256 -j ACCEPT
……所以我對 openvpn 網路做了同樣的事情:
firewall-cmd --direct --add-rule ipv4 filter FORWARD 0 -i ens256 -o tun0 -j ACCEPT
firewall-cmd --direct --add-rule ipv4 filter FORWARD 0 -o ens256 -i tun0 -j ACCEPT
firewall-cmd --direct --add-rule ipv4 filter FORWARD 0 -i ens161 -o tun0 -j ACCEPT
firewall-cmd --direct --add-rule ipv4 filter FORWARD 0 -o ens161 -i tun0 -j ACCEPT
....以及在客戶端:
firewall-cmd --direct --add-rule ipv4 filter FORWARD 0 -i enp6s4f0 -o tun0 -j ACCEPT
firewall-cmd --direct --add-rule ipv4 filter FORWARD 0 -o enp6s4f0 -i tun0 -j ACCEPT
……很明顯,我要么不明白路由應該如何工作,要么我在防火牆方面遺漏了一些東西。
誰能告訴我我錯過了什麼?