如何阻止传出域请求

How to block outgoin domain request

我有一个服务器。我希望能够从 Internet 向该服务器发送请求(这可行),同时阻止从服务器到域的请求。

我要输入

ping google.com

在服务器上看到没有

现在明白了

ping google.com
PING google.com (216.58.205.46) 56(84) bytes of data.
64 bytes from mil04s24-in-f46.1e100.net (216.58.205.46): icmp_seq=1 ttl=54 time=36.3 ms
64 bytes from mil04s24-in-f46.1e100.net (216.58.205.46): icmp_seq=2 ttl=54 time=63.7 ms

您可以使用 iptables 防火墙规则阻止任何 tcp/udp 传出流量。

例如,您可以使用以下防火墙规则阻止来自端口 5050 的任何传出 TCP 流量 -

iptables -A OUTPUT -p tcp --dport 4050 -j DROP
iptables save

与阻止 ping 请求类似,您可以阻止任何出站流量的 ICMP 协议。