如何使用 iptables 只接受特定的“子网”?

sey*_*dal 4 linux iptables

我必须限制对 8080 端口的访问,并且只允许某些 IP 和特定子网。可能吗,请您帮忙吗?

我启用了 IP 过滤,但找不到如何接受子网?

sudo /sbin/iptables -N CHN_PNTS
sudo /sbin/iptables -A CHN_PNTS --src 182.10.10.109  -j ACCEPT  
sudo /sbin/iptables -A CHN_PNTS --src 182.20.35.110  -j ACCEPT 
sudo /sbin/iptables -A CHN_PNTS --src 182.20.55.15   -j ACCEPT 
sudo /sbin/iptables -A CHN_PNTS -j DROP 
sudo /sbin/iptables -I INPUT -m tcp -p tcp --dport 8080 -j CHN_PNTS
Run Code Online (Sandbox Code Playgroud)

我想接受的子网;

182.24.137.0/24
182.24.138.0/23
Run Code Online (Sandbox Code Playgroud)

由于
ERDAL

use*_*517 10

您只需在您的问题中使用 CIDR 表示法

sudo /sbin/iptables -A CHN_PNTS --src 182.24.137.0/24   -j ACCEPT
sudo /sbin/iptables -A CHN_PNTS --src 182.24.138.0/23   -j ACCEPT
Run Code Online (Sandbox Code Playgroud)

记得把它们放在你的

sudo /sbin/iptables -A CHN_PNTS -j DROP 
Run Code Online (Sandbox Code Playgroud)

以便他们正确操作。