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

Restrict all outbound connections to a specific interface, and block if unavailable

· 52CE 我爱测

I'm running Centos 7 in a VM (I don't believe this should matter, but for context...) Inside the VM, I'm running software to establish a tunnel. I can already accept connections from the host okay, but I want to force all outboun…

问题原文

原帖链接 · Basic · CC BY-SA 4.0

I'm running Centos 7 in a VM (I don't believe this should matter, but for context...)

Inside the VM, I'm running software to establish a tunnel. I can already accept connections from the host okay, but I want to force all outbound traffic over the tunnel.

How can I allow return packets for existing connections, while also ensuring no new connections are established from the box unless over tun0?

I've looked at this question iptables blocking all outbound connections but it appears a bit brute-force... I've been using firewall-cmd and the output for iptables -L -n -v is verbose.

Conversely, with Use specific interface for outbound connections (Ubuntu 9.04), I can't see how to apply it to centos.

How can I reliably ensure that all outbound traffic is either established over tun0 or not at all?

已采纳解答

原帖链接 · Ginnungagap · CC BY-SA 4.0

This would effectively prevent any outgoing (IPv4) traffic except on tun0.

iptables -F OUTPUT
iptables -A OUTPUT -o tun0 -j ACCEPT
iptables -P OUTPUT DROP

Be aware that this will prevent any outbound traffic on any interface except tun0, which includes DHCP traffic, established SSH tunnels or the outbound packets from your established tunnel.

This can similarly be applied to IPv6 using ip6tables.

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

资料来源与适用范围

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

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

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