大网数据广告活动
服务器运维问答

Traffic from OpenVPN client to 'self' rejected by UFW

· 52CE 我爱测

I currently have a single VPS set up with OpenVPN server. My idea behind this setup is that, while developing, I would be connected to server over VPN, which would allow me to access ports on the server that are blocked by iptabl…

问题原文

原帖链接 · Erwin · CC BY-SA 3.0

I currently have a single VPS set up with OpenVPN server. My idea behind this setup is that, while developing, I would be connected to server over VPN, which would allow me to access ports on the server that are blocked by iptables/ufw for the outside world.

OpenVPN has been set up such that is masqueraded and forwards all traffic. This works pretty well for any external website. However when I attempt to access some service/port running on the server itself, the request does not seem to be masquaraded nor does the server view it as request made from a client of the tun0 interface and therefore based on the UFW rules set the request is blocked.

I do not have alot of experience with setting up a vpn or custom routing, so my question is: what configuration am I missing such that requests made from a OpenVPN client are allowed?

In my before.rules:

:POSTROUTING ACCEPT [0:0] 
# Allow traffic from OpenVPN client to eth0
-A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE
COMMIT

Error when accessing a service on the server itself (from a connected client):

[UFW BLOCK] IN=eth0 OUT= MAC=[...] SRC=[MY-ACTUAL-CLIENT-IP] DST=[SERVER-IP] LEN=60 TOS=0x08 PREC=0x00 TTL=55 ID=46182 DF PROTO=TCP SPT=47449 DPT=9332 WINDOW=14600 RES=0x00 SYN URGP=0

已采纳解答

原帖链接 · BillThor · CC BY-SA 3.0

It looks like you are blocking the incoming VPN connection. All client VPN traffic should be tunneled over the VPN connection

Masquerading should already be caught by an existing rule for all outgoing connections on eth0. You shouldn't need to add this rule.

VPN connections will have a different device. You may need to add accept rules for that device. The naming of the device depends on the firewall and how they are creating the virtual interface they use.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。