![服务器启动时的 iptables 规则](https://linux22.com/image/1165219/%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%90%AF%E5%8A%A8%E6%97%B6%E7%9A%84%20iptables%20%E8%A7%84%E5%88%99.png)
我曾经使用以下脚本来控制 iptables 规则:
#!/bin/sh
# Get LSB functions
. /lib/lsb/init-functions
IPT="/sbin/iptables"
INET_IFACE="eno1"
#INET_IFACE=""
UNPRIPORTS="1024:65535"
start_fw()
{
echo 1 > /proc/sys/net/ipv4/ip_forward
$IPT -F
$IPT -X
$IPT -P INPUT DROP
$IPT -P FORWARD DROP
#$IPT -P OUTPUT DROP
...
}
flush_fw()
{
$IPT -P INPUT ACCEPT
$IPT -P FORWARD ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -F
$IPT -X
}
stop_fw()
{
flush_fw
echo 0 > /proc/sys/net/ipv4/ip_forward
}
# Check that the package is still installed
[ -x $IPT ] || exit 0;
case "$1" in
start) log_begin_msg "Starting firewall: iptables"
start_fw
log_end_msg 0
;;
stop) log_begin_msg "Stopping firewall: iptables"
stop_fw
log_end_msg 0
;;
save) log_begin_msg "Saving firewall: iptables"
iptables-save > /etc/iptables.rule
log_end_msg 0
;;
restart) log_begin_msg "Restarting firewall: iptables"
start_fw
log_end_msg 0
;;
*) echo "Usage: /etc/init.d/iptables-rules start|stop|save|restore|restart"
#|reload|force-reload
exit 1
;;
esac
exit 0
并使用 sudo update-rc.d iptables-rules defaults 将其注册为服务
但是它在 ubuntu 18 中不再起作用应该怎么做才能在 ubuntu 18 上正确运行它?