Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 无法在Linux中使用iptables防火墙的启动脚本_Bash_Shell_Startup_Iptables_Init - Fatal编程技术网

Bash 无法在Linux中使用iptables防火墙的启动脚本

Bash 无法在Linux中使用iptables防火墙的启动脚本,bash,shell,startup,iptables,init,Bash,Shell,Startup,Iptables,Init,无法在Linux中使用iptables防火墙的启动脚本 我有一个剧本: #!/bin/bash ### BEGIN INIT INFO # Provides: firewall # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Descrip

无法在Linux中使用iptables防火墙的启动脚本 我有一个剧本:

#!/bin/bash

### BEGIN INIT INFO
# Provides:          firewall
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

IPTABLES="/sbin/iptables"
START="/bin/bash"
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
NAME="$0"
N="/etc/init.d/$NAME"

if [ ! -f /scripts/rc.firewall ]; then
echo "/scripts/rc.firewall does not exist"
exit 0
fi

case "$1" in
start|restart)
echo -n "Starting up iptables firewall..."
$START /scripts/rc.firewall
echo "done."
;;
stop)

$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT

$IPTABLES -F
$IPTABLES -X

for TABLE in filter nat mangle
    do
        $IPTABLES -t $TABLE -F
        $IPTABLES -t $TABLE -X
        $IPTABLES -t $TABLE -Z
done

echo "done."
exit 0;
;;
*)
echo "Usage: $N {start|restart|stop}" >&2
exit 1
;;
esac

exit 0
此脚本启动其他脚本:

#!/bin/bash

IPTABLES="/sbin/iptables"

SSHport=$( set | grep "\(SSH_CONNECTION\)" | sed -e "s/^SSH_CONNECTION='//g" | sed -e "s/^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\x20[0-9]*\x20//g" | sed -e "s/^[0-9$

$IPTABLES -F
$IPTABLES -t nat -F
$IPTABLES -t mangle -F

$IPTABLES -X
$IPTABLES -t nat -X
$IPTABLES -t mangle -X

/sbin/modprobe ip_tables
/sbin/modprobe ip_conntrack
/sbin/modprobe iptable_filter
/sbin/modprobe iptable_mangle
/sbin/modprobe iptable_nat
/sbin/modprobe ipt_LOG
/sbin/modprobe ipt_limit
/sbin/modprobe ipt_state
/sbin/modprobe ipt_owner
/sbin/modprobe ipt_REJECT
/sbin/modprobe ipt_MASQUERADE
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_conntrack_irc
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ip_nat_irc
/sbin/modprobe ip_gre
/sbin/modprobe ip_nat_pptp

if [ -f /scripts/ssh_allow.txt ]; then
 for SSH_ALLOW in `grep -v ^# /scripts/ssh_allow.txt`; do
  $IPTABLES -A INPUT -s $SSH_ALLOW -p tcp -m tcp --dport $SSHport -j ACCEPT
  done
fi

$IPTABLES -A INPUT -p tcp -m tcp --dport $SSHport -j DROP

if [ -f /scripts/bad_input_ip.txt ]; then
 for BAD_INPUT_IP in `grep -v ^# /scripts/bad_input_ip.txt`; do
  $IPTABLES -A INPUT -s $BAD_INPUT_IP -j DROP
  done
fi

if [ -f /scripts/port_deny.txt ]; then
 for PORT_DENY in `grep -v ^# /scripts/port_deny.txt`; do
  $IPTABLES -A INPUT -p tcp --dport $PORT_DENY -j DROP
  done
fi
当我尝试开始时:

/etc/init.d/firewall start
一切正常

但在添加启动初始化脚本和重新启动后,我只有一条规则:

iptables -L -v -n
Chain INPUT (policy ACCEPT 2368 packets, 1433K bytes)
 pkts bytes target     prot opt in     out     source               destination
    2   120 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:25
但我应该:

iptables -L -v -n
Chain INPUT (policy ACCEPT 226 packets, 110K bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     tcp  --  *      *       192.168.110.22       0.0.0.0/0            tcp dpt:22
   11   892 ACCEPT     tcp  --  *      *       192.168.11.2         0.0.0.0/0            tcp dpt:22
    0     0 ACCEPT     tcp  --  *      *       192.168.1.2          0.0.0.0/0            tcp dpt:22
    0     0 ACCEPT     tcp  --  *      *       192.168.1.22         0.0.0.0/0            tcp dpt:22
    0     0 ACCEPT     tcp  --  *      *       192.168.110.26       0.0.0.0/0            tcp dpt:22
    0     0 ACCEPT     tcp  --  *      *       192.168.110.27       0.0.0.0/0            tcp dpt:22
    0     0 ACCEPT     tcp  --  *      *       192.168.110.2        0.0.0.0/0            tcp dpt:22
    0     0 ACCEPT     tcp  --  *      *       192.168.110.1        0.0.0.0/0            tcp dpt:22
    0     0 ACCEPT     tcp  --  *      *       192.168.110.3        0.0.0.0/0            tcp dpt:22
    0     0 ACCEPT     tcp  --  *      *       192.168.110.4        0.0.0.0/0            tcp dpt:22
    0     0 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22
    0     0 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:25

我哪里有错误?请提供帮助。

这可能会有帮助。这可能会有帮助。这可能会有帮助。这可能会有帮助。这可能会有帮助。这可能会有帮助。这可能会有帮助。这可能会有帮助。这可能会有帮助:我发现了一个问题,我发现了一个问题,发现了一个问题,这可能会有一个问题,这可能会有助于,这方面,这可能会:::::<代码>代码>SSP>SSHHHHHHHHHHHHspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspspsport=/(学校学校学校学校学校学校学校学校学校学校学校学校学校学校,并并并为为为为为获取(10(SSH(SSHU连接连接)的连接)的(SSH(SSH(SSH(10 10 10)的连接连接)的连接)的)的)的“““““““““*”