V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
decken
V2EX  ›  问与答

openwrt通过代理联网,如何使LAN的流量也经过代理?

  •  
  •   decken · 2013-09-21 00:17:17 +08:00 · 13035 次点击
    这是一个创建于 3895 天前的主题,其中的信息可能已经有所发展或是发生改变。
    具体是这样的:
    有一台装着openwrt的路由器,在/etc/profile的末尾写入
    http_proxy=http://172.28.82.8:7007
    https_proxy=http://172.28.82.8:7007
    export http_proxy
    export https_proxy
    (其中172.28.82.8:7007是通过squid搭建的代理服务器)

    重启之后就能使用 opkg update 和安装软件,能用elink(openwrt的网页浏览器,不支持中文字符)浏览英文网页无压力,但是不能ping通百度,好像ubuntu设置全局代理之后也不能ping百度。

    既然在路由器里面能上网,那为什么电脑连接路由器的时候却不能通过这个代理上网?

    我的想法是想通过路由器设置这个代理,然后让我的电脑也通过这个代理上网。

    大家可能会问我为什么要这样做,我想告诉告诉大家的是我们学校限流量,但是这个代理是免流量的。勿喷,现实已经是如此了,只有靠大家帮忙才能让我摆脱这种困境,先谢谢大家了。
    14 条回复    1970-01-01 08:00:00 +08:00
    tywtyw2002
        1
    tywtyw2002  
       2013-09-21 00:41:56 +08:00
    /etc/profile 只对本地有效

    如果要lan的流量过squid,iptables

    iptables -t nat -I PREROUTING -p tcp --dport 80 -j DNAT --to 172.28.82.8
    tywtyw2002
        2
    tywtyw2002  
       2013-09-21 00:43:33 +08:00   ❤️ 1
    iptables -t nat -I PREROUTING -p tcp --dport 80 -j DNAT --to 172.28.82.8:7007

    还需要在squid的conf 里面协商

    http_port 7007 transparent
    编译的时候需要开启 netfilter的支持
    treo
        3
    treo  
       2013-09-21 09:09:08 +08:00
    http proxy不支持ICMP,能ping通才怪。。
    decken
        4
    decken  
    OP
       2013-09-21 12:23:35 +08:00
    @tywtyw2002 是在代理172.28.82.8:7007里设置 http_port 7007 transparent 吗?
    还是就是在代理服务器还是在路由器里开启netfilter?
    decken
        5
    decken  
    OP
       2013-09-21 12:25:10 +08:00
    @treo 如果要ping通的话该用什么代理呢?
    decken
        6
    decken  
    OP
       2013-09-21 16:10:07 +08:00
    @tywtyw2002 按照你的方法试了一下。会提示如下内容:
    ----------------------------------------------------------------------------------------------------------------------------
    ERROR
    The requested URL could not be retrieved

    The following error was encountered while trying to retrieve the URL: /?wd=DD&tn=cnopera&ie=utf-8

    Invalid URL

    Some aspect of the requested URL is incorrect.

    Some possible problems are:


    Missing or incorrect access protocol (should be "http://" or similar)


    Missing hostname


    Illegal double-escape in the URL-Path


    Illegal character in hostname; underscores are not allowed.

    Your cache administrator is webmaster.


    Generated Sat, 21 Sep 2013 08:03:14 GMT by localhost (squid/3.1.20)
    ----------------------------------------------------------------------------------------------------------------------------

    按照提示,应该是不能取回内容,是不是要写一下iptables回调的规则呢?
    jasontse
        7
    jasontse  
       2013-09-21 16:16:07 +08:00 via iPad
    @decken ICMP 是三层协议,要想 ping 通只能用 VPN。
    tywtyw2002
        8
    tywtyw2002  
       2013-09-22 12:20:35 +08:00
    @decken 你代理是什么?
    squid做的吗?
    然后环境是什么?

    是 lan->router->squid这样的架构吗? squid 是在wan口的外面?

    The following error was encountered while trying to retrieve the URL: /?wd=DD&tn=cnopera&ie=utf-8
    这个明显就是squid的问题,
    没work在转发模式上吧。
    ooxxcc
        9
    ooxxcc  
       2013-09-22 12:48:56 +08:00
    改dnsmasq设置,然后网络内计算机接受dhcp推送来的代理服务器设置就行

    以前见过,lz可以搜一下
    decken
        10
    decken  
    OP
       2013-09-22 13:52:17 +08:00
    @tywtyw2002 代理服务器是用squid3.1搭建的,ip为172.28.82.8:7007,squid在wan口外面。
    你的意思是说路由器也建一个squid,然后工作在转发模式吗?
    tywtyw2002
        11
    tywtyw2002  
       2013-09-22 14:59:30 +08:00
    不用 外网的squid里面开一个端口, 模式改成 transparent就好了。

    在路由器上用iptables -t nat -I PREROUTING -p tcp --dport 80 -j DNAT --to 172.28.82.8:7007 做规则
    这样就应该没问题了
    decken
        12
    decken  
    OP
       2013-09-22 15:09:29 +08:00
    @tywtyw2002 但是用了iptables,https怎么办呢
    treo
        13
    treo  
       2013-09-22 22:50:57 +08:00
    直接在服务器上搭个vpn server吧,路由器去拨vpn
    推荐SoftEther VPN
    decken
        14
    decken  
    OP
       2013-09-22 23:38:54 +08:00
    @treo 如果路由器拨vpn的话还需要用iptables吗?
    路由上不是很流行用openvpn的吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1805 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:31 · PVG 00:31 · LAX 09:31 · JFK 12:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.