在Ubuntu中,使用iptables自定义链可以帮助您更好地管理和组织规则。以下是创建自定义链的步骤:
sudo apt-get update
sudo apt-get install iptables
sudo iptables -L
sudo iptables -N my_custom_chain
sudo iptables -I INPUT -j my_custom_chain
sudo iptables -A my_custom_chain -s 192.168.1.100 -j DROP
sudo apt-get install iptables-persistent
在安装过程中,它会询问您是否要保存当前的iptables规则。选择“是”,然后选择“IPv4”和“IPv6”以保存规则。
sudo systemctl restart netfilter-persistent
现在,您已经成功创建了一个名为“my_custom_chain”的自定义链,并在其中添加了一条规则。您可以根据需要添加更多规则,并将它们插入到其他规则链中。