LinuxSir.cn,穿越时空的Linuxsir!

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

用iptables发布内部服务的问题

[复制链接]
发表于 2005-5-19 14:58:42 | 显示全部楼层 |阅读模式
centos4+iptables已经能带局域网上网了,搞定发布后,就可以替换win2k+isa了,请帮忙看看
互联网环境是网通的固定ip

mail、web和ftp都是rh9下的默认版本,地址是192.168.0.7
sql是2000下的,地址是192.168.0.201

以下是我的脚本,发布的mail、web、ftp和sql服务都失败了

#!/bin/bash
echo "Starting iptables rules..."
echo "1" >/proc/sys/net/ipv4/ip_forward
inet_iface=eth1
inet_ip=1.1.1.1
lan_iface=eth0
lan_ip=192.168.0.2
ip_range=192.168.0.0/24
IPT=/sbin/iptables

www_server=192.168.0.7
ftp_server=192.168.0.7
email_server=192.168.0.7
sql_server=192.168.0.201
http="80"
ftp="21"
ftp_data="20"
sql="1433"
smtp="25"
pop3="110"

/sbin/depmod -a
/sbin/modprobe ip_tables
/sbin/modprobe iptable_nat
/sbin/modprobe ip_nat_ftp
/sbin/modprobe ipt_LOG

$IPT -P INPUT ACCEPT
$IPT -P FORWARD ACCEPT
$IPT -P OUTPUT ACCEPT
$IPT -t nat -P PREROUTING ACCEPT
$IPT -t nat -P POSTROUTING ACCEPT
$IPT -t nat -P OUTPUT ACCEPT
for TABLE in filter nat mangle; do
$IPT -t $TABLE -F
$IPT -t $TABLE -X
done

$IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
for DNS in $(grep ^n /etc/resolv.conf |awk '{print $2}'); do
$IPT -A INPUT -p udp -s $DNS --sport domain -j ACCEPT
done

$IPT -A INPUT -p tcp --sport $http -j ACCEPT
$IPT -A INPUT -p tcp --sport $ftp -j ACCEPT
$IPT -A INPUT -p tcp --sport $smtp -j ACCEPT
$IPT -A INPUT -p tcp --sport $pop3 -j ACCEPT
$IPT -A INPUT -p tcp --sport $sql -j ACCEPT

$IPT -t nat -A POSTROUTING -o $inet_iface -j SNAT --to $inet_ip

$IPT -t nat -A PREROUTING -p tcp -d $inet_ip --dport $sql -j DNAT --to-destination $sql_serversql
$IPT -t nat -A PREROUTING -p tcp -d $inet_ip --dport $http -j DNAT --to-destination $www_serverhttp
$IPT -t nat -A PREROUTING -p tcp -d $inet_ip --dport $ftp -j DNAT --to-destination $ftp_serverftp

$IPT -t nat -A PREROUTING -p tcp -d $inet_ip --dport $smtp -j DNAT --to-destination $email_serversmtp
$IPT -t nat -A PREROUTING -p tcp -d $inet_ip --dport $pop3 -j DNAT --to-destination $email_serverpop3


请大侠帮帮忙,谢谢了!~
发表于 2005-5-19 17:30:41 | 显示全部楼层
$IPT -P INPUT ACCEPT

ACCEPT前不用加-j吗?我承认我很小白,呜呜~~~~
回复 支持 反对

使用道具 举报

发表于 2005-5-19 17:38:43 | 显示全部楼层
人家那句没有错。设的是策略为accept
回复 支持 反对

使用道具 举报

发表于 2005-5-19 19:17:47 | 显示全部楼层
你的固定 IP 是 1.1.1.1 吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-20 08:21:03 | 显示全部楼层
Post by Chowroc
你的固定 IP 是 1.1.1.1 吗?


不是,假设的,呵呵
我这里填的是正确的固定ip
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-20 09:58:47 | 显示全部楼层
哪位大侠成功发布过服务的帮忙看看吧
web、mail和ftp倒不着急
主要是sql得搞定,要不然不能用linux啊
多谢了。。。
回复 支持 反对

使用道具 举报

发表于 2005-5-20 10:53:24 | 显示全部楼层
人家那句没有错。设的是策略为accept

呵呵,看走眼了,-P看成-A鸟,小白鸟~~~~~
呜呜
回复 支持 反对

使用道具 举报

发表于 2005-5-20 11:08:47 | 显示全部楼层
你至少还是把运行完脚本后的iptables -L;iptables -t nat -L
列出来一下三
回复 支持 反对

使用道具 举报

发表于 2005-5-20 11:23:41 | 显示全部楼层
打开FORWARD

iptables -A FORWARD -p tcp -d $你的内网服务ip --dport $你的内网服务端口  -m state --state NEW -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-5-20 11:35:25 | 显示全部楼层
呵呵
其实我才是小白,这些命令都不知道
来了
[root@as3 ~]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       tcp  --  anywhere             218.107.130.52      tcp dpt:ms-sql-s to:192.168.35.201:1433
DNAT       tcp  --  anywhere             218.107.130.52      tcp dpt:http to:192.168.35.7:80
DNAT       tcp  --  anywhere             218.107.130.52      tcp dpt:ftp to:192.168.35.7:21
DNAT       tcp  --  anywhere             218.107.130.52      tcp dpt:smtp to:192.168.35.7:25
DNAT       tcp  --  anywhere             218.107.130.52      tcp dpt:pop3 to:192.168.35.7:110

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
SNAT       all  --  anywhere             anywhere            to:218.107.130.52

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination


再来
[root@as3 ~]# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     udp  --  dns-zhonggc.bj.cncnet.net  anywhere            udp spt:domain
ACCEPT     udp  --  dns-jinrj.bj.cncnet.net  anywhere            udp spt:domain
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:http
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:ftp
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:smtp
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:pop3
ACCEPT     tcp  --  anywhere             anywhere            tcp spt:ms-sql-s

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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