LinuxSir.cn,穿越时空的Linuxsir!

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

关于 redhat AS 4.0 透明代理一直不能解决的问题.

[复制链接]
发表于 2005-2-25 09:22:56 | 显示全部楼层 |阅读模式
小弟在 8.0 9.0 as 3.0 下做透明代理都成功了. 能实现正常上网的功能.

但在as 4.0下, 也能成功,但是有小问题.

以前我们在做透明代理的时候,大部分都把iptables的语法,放在/etc/rc.d/rc.local里,以便开机能自动运行或在/etc/rc.d目录下新建一个firewall文件把iptables语法放在firewall里, 在给firewall一个可以执行的权限然后在/etc/rc.d/rc.local里加上/etc/rc.d/firewall这个文件的路径就可以了.
大部分是这两种方法吧.
可是我在AS 4.0下遇到了问题:
我是按着第二种方法做的.先编辑/etc/rc.d/rc.local文件,在在/etc/rc.d目录下建立firewall文件,加上iptables的语法. 以给firewall文件可执行的权限.
以下是rc.local文件的内容:
[root@rhlinux rc.d]# less rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/etc/rc.d/firewall


以下是firewall的内容:

[root@rhlinux rc.d]# less firewall
#!/bin/bash
echo "Enable IP Forwarding..."
echo "1">/proc/sys/net/ipv4/ip_forward
echo "Starting iptables rules..."
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp -s 192.168.1.0/24 --dport 80 -j REDIRECT --to-ports 3128
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to x.x.x.x

可是当我运行/etc/rc.d/firewall时,提示没有那个文件.具体如下:[root@rhlinux rc.d]# ./firewall
: No such file or directory
执行/etc/rc.d/rc.local时,也是如此.
[root@rhlinux rc.d]# ./rc.local
: No such file or directory

那么这样的话,我只能在开机后加上iptables的语法,才能实现透明代理,可是要是重启机器的话, iptables 的语法就没有了.

请问这个问题怎么解决呀,有没有用过AS 4.0 做透明代理的哥们呀.

以下是的显示可以看出,我的透明代理正常运行:
[root@rhlinux rc.d]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- 192.168.1.0/24 anywhere tcp dpt:http redir ports 3128

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
SNAT all -- 192.168.1.0/24 anywhere to:218.9.119.59

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@rhlinux rc.d]#

注意, 我是实现了透明代理,只是不明白,为什么不能运行rc.local 和 firewall
发表于 2005-2-25 09:37:23 | 显示全部楼层
应该不会吧,关注。我试一下看看。。。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-25 09:49:39 | 显示全部楼层

没有人遇到这样的问题吗. 在AS 4.0 下

我刚才又试了,在/etc/rc.d新建一个文件名为df的文件,chmod +x df ,给它可运行的权限.
df文件的内容为df -h


[root@rhlinux rc.d]# less df
df -h


[root@rhlinux rc.d]# ll
total 152
-rwxr-xr-x 1 root root 5 Feb 24 23:29 df

[root@rhlinux rc.d]# ./df
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
73G 6.2G 63G 9% /
/dev/hda1 99M 12M 82M 13% /boot
none 252M 0 252M 0% /dev/shm
[root@rhlinux rc.d]#

看, 这个df就可以运行.


[root@rhlinux rc.d]# ll |grep firewall
-rwxr-xr-x 1 root root 334 Feb 24 22:54 firewall

[root@rhlinux rc.d]# ./firewall
: No such file or directory
[root@rhlinux rc.d]#

这个firewall就是运行不了,


firewall文件的内容如下:


[root@rhlinux rc.d]# less firewall
#!/bin/bash
echo "Enable IP Forwarding..."
echo "1">/proc/sys/net/ipv4/ip_forward
echo "Starting iptables rules..."
/sbin/iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp -s 192.168.1.0/24 --dport 80 -j REDIRECT --to-ports
3128
/sbin/iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to 218.9.119.59


没有人遇到我这样的问题吗.
QQ 11217404
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-25 09:50:57 | 显示全部楼层

高手们,这个问题怎么办呀,

我把iptables的命令指向目录了也不好用.

firewall命令如下:

[root@rhlinux rc.d]# less firewall
#!/bin/sh
echo "Enable IP Forwarding..."
echo "1">/proc/sys/net/ipv4/ip_forward
echo "Starting iptables rules..."
/sbin/iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp -s 192.168.1.0/24 --dport 80 -j REDIRECT --to-ports
3128
/sbin/iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to 218.9.119.59


我试过了, 开始以为是环境变量的事, 所以把firewall改为如下:
[root@rhlinux rc.d]# less firewall
#!/bin/bash
echo "Enable IP Forwarding..."
echo "1">/proc/sys/net/ipv4/ip_forward
echo "Starting iptables rules..."
/sbin/iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp -s 192.168.1.0/24 --dport 80 -j REDIRECT --to-ports
3128
/sbin/iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to 218.9.119.59

发现,改为bash也不好用.所以, 又让我给改成sh了.

哥们们, 这个问题你们就没有遇到过吗, 要是解决不了, 那么你们是怎么样在 AS 4.0 下做的透明代理呢.

我晕倒.

QQ 11217404
回复 支持 反对

使用道具 举报

发表于 2005-2-25 13:03:13 | 显示全部楼层
晕菜!不会是shell教本格式不允许吧?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-25 16:16:32 | 显示全部楼层
大哥们, 有没有用过AS 4.0 做过透明代理的呀.我已经是不行了, 解决不了了.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-25 16:17:48 | 显示全部楼层
yuri-master  

             谢谢你的回答,真心的想让你帮着把这个贴子置顶. 帮我把这个问题解决了.
回复 支持 反对

使用道具 举报

发表于 2005-2-26 06:06:36 | 显示全部楼层
在你对iptables更改以后
应该可以用
service iptables save 这个语句
这样每次开机你的iptable表就不回到初始状态了
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-26 08:48:44 | 显示全部楼层
我知道有那条语法呀,service iptables save 可是, "echo "1">/proc/sys/net/ipv4/ip_forward "
这条语法,怎么办呀, 能保证每次打开内核转发吗?  
还有,这不是一个最好的解决的方法呀.  
QQ11217404
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-2-26 08:51:15 | 显示全部楼层
yuri-master
              谢谢版主帮着置顶.  真的好晕呀, 有时间好好交流一下, 跟你多学学.
回复 支持 反对

使用道具 举报

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

本版积分规则

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