linux 开机启动iptables的rules脚本

2,334 阅读1分钟

永久保存iptables 的rules

  1. 在 /etc/init.d/下新建一个脚本文件 ipnat
    #后面的内容也是需要的,相应修改下
#! /bin/sh
### BEGIN INIT INFO
# Provides:          ipnat
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:
# Short-Description: ip route nat 
### END INIT INFO
iptables -t nat -A POSTROUTING  -o wlx200db032926f  -j MASQUERADE
iptables -t nat -A POSTROUTING -o enp4s0  -j MASQUERADE
exit 0
  1. 运行命令
chmod a+x /etc/init.d/ipnat
  1. 运行下面的命令
sudo update-rc.d ipnat defaults

在/etc/rc5.d/下面多出一个S01ipnat文件