如何在 Ubuntu 上启动/停止 iptables 服务?
我试过了
service iptables stop
Run Code Online (Sandbox Code Playgroud)
但它正在提供“无法识别的服务”。
为什么要这样做?有没有其他方法?
JMu*_*ove 86
我不知道“Ubuntu”,但通常在 Linux 中,“iptables”不是服务 - 它是操作 netfilter 内核防火墙的命令。您可以通过将所有标准链上的默认策略设置为“接受”并刷新规则来“禁用”(或停止)防火墙。
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -F
Run Code Online (Sandbox Code Playgroud)
(您可能还需要刷新其他表,例如“nat”,如果您使用过它们)
Ubuntu 网站上的以下文章描述了设置 iptables 以与 NetworkManager 一起使用:https : //help.ubuntu.com/community/IptablesHowTo
Fre*_*sen 50
你都错了:-)
您正在寻找的命令是:
$ sudo ufw disable
Run Code Online (Sandbox Code Playgroud)
Emb*_*eau 37
我会首先检查它是否安装了(可能是):
dpkg -l | grep iptables
Run Code Online (Sandbox Code Playgroud)
在 Ubuntu 上,iptables 不是一项服务。为了阻止它,您必须执行以下操作:
sudo iptables-save > /root/firewall.rules
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
Run Code Online (Sandbox Code Playgroud)
为了恢复您以前的规则:
iptables-restore < /root/firewall.rules
Run Code Online (Sandbox Code Playgroud)
这取自http://www.cyberciti.biz/faq/turn-on-turn-off-firewall-in-linux/并在许多 Ubuntu 8.X 和 9.10 安装上进行了测试。
puz*_*-it 19
iptables 是一个命令,它不是一个服务,所以通常不可能使用像这样的命令
service iptables start
Run Code Online (Sandbox Code Playgroud)
或者
service iptables stop
Run Code Online (Sandbox Code Playgroud)
为了启动和停止防火墙,但是像centos这样的发行版已经安装了一个叫做iptables的服务来启动和停止防火墙以及一个配置文件来配置它。无论如何,可以制作一个服务来管理 ipotables 编辑或为此范围安装脚本。linux中的所有服务,ubuntu也不例外,都是/etc/init.d文件夹内的可执行脚本,实现了标准接口(启动,停止,重启)一个可能的脚本如下所示:
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: iptables
# Required-Start: mountvirtfs ifupdown $local_fs
# Default-Start: S
# Default-Stop: 0 6
### END INIT INFO
# July 9, 2007
# James B. Crocker <ubuntu@james.crocker.name>
# Creative Commons Attribution - Share Alike 3.0 License (BY,SA)
# Script to load/unload/save iptables firewall settings.
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
IPTABLES=/sbin/iptables
IPTABLES_SAVE=/sbin/iptables-save
IPTABLES_RESTORE=/sbin/iptables-restore
IPTABLES_CONFIG=/etc/iptables.conf
[ -x $IPTABLES ] || exit 0
. /lib/lsb/init-functions
case "$1" in
start)
log_action_begin_msg "Starting firewall"
type usplash_write >/dev/null 2>/dev/null && usplash_write "TIMEOUT 120" || true
if $IPTABLES_RESTORE < $IPTABLES_CONFIG ; then
log_action_end_msg $?
else
log_action_end_msg $?
fi
type usplash_write >/dev/null 2>/dev/null && usplash_write "TIMEOUT 15" || true
;;
stop)
log_action_begin_msg "Saving current firewall configuration"
if $IPTABLES_SAVE > $IPTABLES_CONFIG ; then
log_action_end_msg $?
else
log_action_end_msg $?
fi
log_action_begin_msg "Flushing ALL firewall rules from chains!"
if $IPTABLES -F ; then
log_action_end_msg $?
else
log_action_end_msg $?
fi
log_action_begin_msg "Deleting ALL firewall chains [Warning: ACCEPTING ALL PORT SERVICES!]"
if $IPTABLES -X ; then
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT
log_action_end_msg $?
else
log_action_end_msg $?
fi
;;
save)
log_action_begin_msg "Saving current firewall configuration"
if $IPTABLES_SAVE > $IPTABLES_CONFIG ; then
log_action_end_msg $?
else
log_action_end_msg $?
fi
;;
force-reload|restart)
log_action_begin_msg "Reloading firewall configuration [Warning: POTENTIAL NETWORK INSECURITY DURING RELOAD]"
$IPTABLES -F
$IPTABLES -X
if $IPTABLES_RESTORE < $IPTABLES_CONFIG ; then
log_action_end_msg $?
else
log_action_end_msg $?
fi
;;
*)
echo "Usage: /etc/init.d/iptables {start|stop|save|restart|force-reload}"
exit 1
;;
esac
exit 0
Run Code Online (Sandbox Code Playgroud)
该脚本是本教程的一部分,必须根据上面的脚本将配置防火墙的所有命令插入到 /etc/iptables.conf 文件中。此脚本必须插入到/etc/init.d 中名为iptables的文件中,并使用
chmod+x *iptables*
Run Code Online (Sandbox Code Playgroud)
并将服务添加到运行级别使用
update-rc.d iptables defaults
Run Code Online (Sandbox Code Playgroud)
您可以从 shell 添加新规则,这些规则将立即生效,并在服务停止时添加到 /etc/iptables.conf(这意味着它们将在系统关闭时确保保存)。
我希望这对每个人都有帮助。
| 归档时间: |
|
| 查看次数: |
622013 次 |
| 最近记录: |