UFW 正在通过 VPN 阻止 DNS 请求

UFW 正在通过 VPN 阻止 DNS 请求

我的 UFW 在 Ubuntu 18.04 上有一个非常奇怪的行为。我设置了基本规则,一切正常,直到我通过 VPN 将客户端连接到该服务器。在客户端 ping 工作正常,但 nslookup / 域 ping 被拒绝。一旦我关闭 ufw,它就运行良好。 UFW 配置:VPN 子网为 10.99.0.0/24(使用 OpenVPN):

ufw default deny incoming
ufw default allow outgoing
1194                       ALLOW       Anywhere
Anywhere                   ALLOW       10.99.0.0/24
6969                       ALLOW       10.99.0.0/24
10.99.0.0/24               ALLOW       Anywhere

从日志中(使用 8.8.8.8 和 1.0.0.1 作为 DNS):

Dec  7 23:40:28 snm kernel: [15432.700282] [UFW BLOCK] IN=tun0 OUT=eth0 MAC= SRC=10.99.0.2 DST=1.0.0.1 LEN=71 TOS=0x00 PREC=0x00 TTL=127 ID=1189 PROTO=UDP SPT=64312 DPT=53 LEN=51
Dec  7 23:41:08 snm kernel: [15472.370487] [UFW BLOCK] IN=tun0 OUT=eth0 MAC= SRC=10.99.0.2 DST=1.0.0.1 LEN=71 TOS=0x00 PREC=0x00 TTL=127 ID=1192 PROTO=UDP SPT=50962 DPT=53 LEN=51
Dec  7 23:41:09 snm kernel: [15473.384535] [UFW BLOCK] IN=tun0 OUT=eth0 MAC= SRC=10.99.0.2 DST=8.8.8.8 LEN=71 TOS=0x00 PREC=0x00 TTL=127 ID=1193 PROTO=UDP SPT=50962 DPT=53 LEN=51

您对如何调试这个有什么建议吗?

答案1

如果您看到的只是域 ping 失败,则需要将服务器和/或客户端防火墙设置为允许转发:

# Allow TUN interface connections to OpenVPN server
iptables -A INPUT -i tun+ -j ACCEPT

# Allow TUN interface connections to be forwarded through other interfaces
iptables -A FORWARD -i tun+ -j ACCEPT

更多信息:这里

另请查看客户端到客户端设置,这是访问 VPN 上其他计算机所必需的,如果未启用,您将看不到连接的其他计算机。

  • 如果您希望连接客户端能够通过 VPN 相互访问,请取消注释客户端到客户端指令。默认情况下,客户端只能访问服务器。

找到更多信息:这里

答案2

好吧,最后我通过调整 IPTABLES 解决了我的问题:

iptables -I FORWARD -i tun0 -o eth0 \
         -s 10.8.0.0/24 -m conntrack --ctstate NEW -j ACCEPT

iptables -I FORWARD -m conntrack --ctstate RELATED,ESTABLISHED \
         -j ACCEPT

iptables -t nat -I POSTROUTING -o eth0 \
          -s 10.8.0.0/24 -j MASQUERADE

我现在可以简化 ufw 规则:

To                         Action      From
--                         ------      ----
1194                       ALLOW       Anywhere
22                         ALLOW       10.8.0.0/24

如果我想在 server.conf 中更改 IP 池,但我必须相应地修改 ip 表。

port 1194
proto udp
dev tun
sndbuf 0
rcvbuf 0
ca ca.crt
cert server.crt
key server.key
dh dh.pem
auth SHA512
tls-auth ta.key 0
topology subnet
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "redirect-gateway def1"
#push "redirect-gateway def1 bypass-dhcp"
#push "dhcp-option DNS 10.8.0.1"
push "dhcp-option DNS 1.1.1.1"
push "dhcp-option DNS 1.0.0.1"
keepalive 10 120
cipher AES-256-CBC
user nobody
group nogroup
persist-key
persist-tun
log-append /var/log/openvpn/openvpn.log
status openvpn-status.log
verb 3
crl-verify crl.pem

答案3

发现,我使用错误的方式更改了 DHCP 池(仅编辑 server.conf)。使用其他方式更改 IP 池会有所帮助。

相关内容