LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1457|回复: 5

SSH远程登陆的问题

[复制链接]
发表于 2003-10-6 16:10:03 | 显示全部楼层 |阅读模式
我的机子是用作代理的主机,adsl上网。
我用了那个网吧的教本
每次都要先执行脚本才可以ssh或telnet进去
重启主机后就不能ssh或telnet了
当ssh时提示:c:\Documents and Settings\www>ssh -l www 172.16.0.1
ssh: connect to host 172.16.0.1 port 22: Connection reset by peer
请问这是什么原因???
 楼主| 发表于 2003-10-7 07:55:21 | 显示全部楼层
#!/bin/bash
#
# Script name: ipt_masq
# A simple script for masquerading, used in Linux (kernel 2.4.x).
#
# Copyleft 2002 by netman (netman@study-area.org).
#
# Redistribution of this file is permitted under the terms of
# the GNU General Public License (GPL).
#
# Date: 2002/02/04
# Version: 1.2

PATH=/sbin:/usr/sbin:/bin:/usr/bin
RC_SQUID=/etc/rc.d/init.d/squid
EXT_IF=ppp0
INT_IF=eth1
ALLOWED_ICMP="0 3 3/4 4 11 12 14 16 18"
DENIED_ICMP="8"

#
# ------------- ensure iptables ----------
which iptables &>/dev/null || {
echo
echo "$(basename $0): iptables program is not found."
echo " Please install the program first."
echo
exit 1
}
# ------------- disable ipchains ----------
lsmod | grep ipchains &>/dev/null && {
echo "Disabling ipchains..."
rmmod ipchains &>/dev/null
}

# ------------- modules -----------
echo "Loading modules..."
modprobe ip_tables &>/dev/null || {
echo -n "$(basename $0): loading ip_tables module failure."
echo " Please Fix it!"
exit 3
}
for file in /lib/modules/`uname -r`/kernel/net/ipv4/netfilter/ip_conntrack_*.o
do
module=$(basename $file)
modprobe ${module%.*} &>/dev/null
done
for file in /lib/modules/`uname -r`/kernel/net/ipv4/netfilter/ip_nat_*.o
do
module=$(basename $file)
modprobe ${module%.*} &>/dev/null
done

# ------------- ipforwarding -----------
echo "Turning on IP forwarding..."
echo "1" > /proc/sys/net/ipv4/ip_forward

# ------------- anti spoofing -----------
echo "Turning on anti-spoofing..."
for file in /proc/sys/net/ipv4/conf/*/rp_filter; do
echo "1" > $file
done

# ------------- flushing ----------
echo "Cleaning up..."
iptables -F -t filter
iptables -X -t filter
iptables -Z -t filter
iptables -F -t nat
iptables -X -t nat
iptables -Z -t nat

# ------------- policies -------------
echo "Setting up policies to ACCEPT..."
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t nat -P OUTPUT ACCEPT

# ------------- ICMP -------------
echo "Creating icmpfilter chain..."
iptables -N icmpfilter
for TYPE in $DENIED_ICMP; do
iptables -A icmpfilter -i $EXT_IF -p icmp \
--icmp-type $TYPE -j DROP
done
for TYPE in $ALLOWED_ICMP; do
iptables -A icmpfilter -i $EXT_IF -p icmp \
--icmp-type $TYPE -j ACCEPT
done

# ------------- block -------------
echo "Creating block chain..."
iptables -N block
iptables -A block -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A block -m state --state NEW,INVALID -i $EXT_IF -j DROP
iptables -A block -m state --state NEW -i ! $EXT_IF -j ACCEPT
iptables -A block -j DROP

# ------------- filter -------------
echo "Filtering packets..."
iptables -A INPUT -j icmpfilter
iptables -A INPUT -j block
iptables -A FORWARD -j icmpfilter
iptables -A FORWARD -j block

# ------------- masq -------------
echo "Masquerading internel network..."
iptables -t nat -A POSTROUTING -s 192.168.0.0/29 -o $EXT_IF -j MASQUERADE
#iptables -t nat -A POSTROUTING -s 192.168.0.3/32 -d 192.168.0.3

# ------------- tproxy -------------
$RC_SQUID status | grep pid &>/dev/null && {
echo "Enabling transparent proxy..."
INT_IP=$(ifconfig | grep "$INT_IF " -A 1 \
| awk '/inet/ {print $2}' | sed -e s/addr\://)
if [ -z "$INT_IP" ]; then
echo
echo "$(basename $0): there is no IP found on $INT_IF."
echo " Please make sure $INT_IF is setup properly."
echo
exit 3
fi


#iptables -t nat -A PREROUTING -d $INT_IP -i $INT_IF \
#-p tcp -m tcp --dport 80 -j ACCEPT
#iptables -t nat -A PREROUTING -i $INT_IF -p tcp -m tcp \
#--dport 80 -j REDIRECT --to-ports 3128

}
exit 0
## EOS
就是这个脚本
发表于 2003-10-7 12:33:40 | 显示全部楼层
看到
# ------------- filter -------------
这一段,里面
iptables -A INPUT -j block
这句把所有发给网关本机的连接都block掉了,也就是说这个机子只用来转发数据,机上的进程不能接受外来连接。
 楼主| 发表于 2003-10-7 17:28:14 | 显示全部楼层
是重启后才不能ssh的,或telnet或vnc
要先执行脚本才可以完成以上功能啊
发表于 2003-10-8 05:50:27 | 显示全部楼层
晕阿,这么说来,那句iptables -A INPUT -j block
是不能阻挡所有东西的.
你用什么发行版本阿?会不会你系统本身带有防火墙脚本? (例如redhat)用ntsysv关掉它, 或者还可以自己把你的脚本加入到启动时运行.
 楼主| 发表于 2003-10-8 10:42:09 | 显示全部楼层
多谢了
我的是RH9。0
我试试让脚本在启动时运行
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表