我曾经使用以下脚本来控制 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 上正确运行它?