vim /lib/systemd/system/rc.local.service(實例系統已經配置了這個文件,如果沒有,請手動配置)
# SPDX-License-Identifier: LGPL-2.1+
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
首先配置iptables:
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 1000:10000 -j DNAT --to-destina
系統爲ubuntu18.04版本:
首先配置iptables:
查看配置:iptables -L -t nat
保存iptables配置到文件:/etc/iptables.rules
重啓系統後,使配置生效,需要運行命令
可能由於系統環境,以下兩種方式失敗:
在/etc/network/interfaces文件中添加iptables-restore < /etc/iptables.rules命令,重啓系統,iptables配置未生效
在/etc/network/if-pre-up.d/中添加腳本的方式,重啓系統,iptables配置依然失敗
成功解決方法:
vim /etc/rc.local
chmod +x /etc/rc.local
vim /lib/systemd/system/rc.local.service(實例系統已經配置了這個文件,如果沒有,請手動配置)
systemctl enable rc.local
重啓系統測試,iptables配置生效,問題解決
參考文章:https://ilouis.cn/ubuntu/ubuntu_setting_iptables.html