想上网,且不受外部限制方法很多,VPN, DNS Proxy, 这次给大家介绍一下Web Proxy。我选的是Squid代理服务器,这款之前就有想研究的冲动,
苦于一直没有时间。
准备:
OpenWrt上编译
#make menuconfig
->Network->Web Proxy->Squid。
#make
烧写固件
网络拓扑图如下
一切都进展的很顺利。
到了下面就是特别苦恼的事情了,你会遇到千奇百怪的问题,全因一纸squid.conf, 这个配置文件整对了,你离成功也就不远了。
文件有8000行左右,所以就不贴在这里,只写一些简单的启动配置。
#echo "1">/proc/sys/net/ipv4/ip_forward
#mkdir /var/logs
#chown nobody /var/logs
#squid -z
#squid -f /etc/squid/squid.conf
工作到此已经结束,检查下我们侦听的端口吧。
3128,至于是你自己配置浏览器代理还是直接把目的地址为80端口的数据导向3128这个就随你了。
我是这么做的,这样任何接入浏览器的人都可以通过我的代理服务器访问网络了。
#iptables -t nat -A PREROUTING -s 0.0.0.0/0.0.0.0 -p tcp --dport 80 -j REDIRECT --to-port 3128
#netstat -an
<span style="font-size:14px;">[email protected]:~# netstat -an Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 10.1.1.1:80 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:3128 0.0.0.0:* LISTEN tcp 0 0 10.0.2.1:3128 10.0.2.134:63925 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63921 ESTABLISHED tcp 0 0 192.168.4.159:59750 119.147.254.144:80 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63927 ESTABLISHED tcp 0 0 192.168.4.159:43126 119.147.45.109:80 TIME_WAIT tcp 0 0 10.0.2.1:3128 10.0.2.134:63918 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63828 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63940 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63936 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63843 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63901 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63903 TIME_WAIT tcp 0 0 192.168.4.159:48129 180.149.131.35:80 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63853 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63834 ESTABLISHED tcp 0 0 192.168.4.159:37466 119.147.45.109:80 TIME_WAIT tcp 0 0 10.0.2.1:3128 10.0.2.134:63824 TIME_WAIT tcp 0 0 10.0.2.1:3128 10.0.2.134:63854 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63931 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63826 TIME_WAIT tcp 0 0 192.168.4.159:59014 119.147.254.73:80 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63844 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63896 TIME_WAIT tcp 0 0 10.0.2.1:3128 10.0.2.134:63876 ESTABLISHED tcp 0 0 10.0.2.1:3128 10.0.2.134:63841 ESTABLISHED tcp 0 0 192.168.4.159:33369 119.147.45.109:80 TIME_WAIT tcp 0 0 :::53 :::* LISTEN tcp 0 0 :::22 :::* LISTEN udp 0 0 0.0.0.0:53 0.0.0.0:* udp 0 0 0.0.0.0:3130 0.0.0.0:* udp 0 0 0.0.0.0:67 0.0.0.0:* udp 0 0 0.0.0.0:54346 0.0.0.0:* udp 0 0 0.0.0.0:4827 0.0.0.0:* udp 0 0 :::547 :::* udp 0 0 :::53 :::* raw 0 0 ::%4253704:58 :::* 58 raw 0 0 ::%4253704:58 :::* 58 Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 8 [ ] DGRAM 2521 /dev/log unix 2 [ ACC ] STREAM LISTENING 241 /var/run/ubus.sock unix 2 [ ] DGRAM 9769 unix 3 [ ] STREAM CONNECTED 2523 unix 3 [ ] STREAM CONNECTED 2593 unix 2 [ ] DGRAM 2641 unix 3 [ ] STREAM CONNECTED 3047 unix 3 [ ] STREAM CONNECTED 2619 unix 2 [ ] DGRAM 4021 unix 3 [ ] STREAM CONNECTED 689 unix 3 [ ] STREAM CONNECTED 2524 /var/run/ubus.sock unix 2 [ ] DGRAM 2675 unix 3 [ ] STREAM CONNECTED 2620 /var/run/ubus.sock unix 2 [ ] DGRAM 3071 unix 2 [ ] DGRAM 9767 unix 3 [ ] STREAM CONNECTED 690 /var/run/ubus.sock unix 3 [ ] STREAM CONNECTED 2594 /var/run/ubus.sock unix 3 [ ] STREAM CONNECTED 3048 /var/run/ubus.sock unix 2 [ ] DGRAM 2622 [email protected]:~# [email protected]:~# ps PID USER VSZ STAT COMMAND 1 root 1344 S /sbin/procd 2 root 0 SW [kthreadd] 3 root 0 SW [ksoftirqd/0] 4 root 0 SW [kworker/0:0] 5 root 0 SW< [kworker/0:0H] 6 root 0 SW [kworker/u2:0] 7 root 0 SW< [khelper] 8 root 0 SW [kworker/u2:1] 64 root 0 SW< [writeback] 66 root 0 SW< [bioset] 68 root 0 SW< [kblockd] 99 root 0 SW [kswapd0] 144 root 0 SW [fsnotify_mark] 169 root 0 SW [spi32766] 208 root 0 SW< [deferwq] 212 root 0 SW< [kworker/0:1H] 213 root 0 SW [kworker/0:2] 245 root 0 SW [khubd] 269 root 0 SWN [jffs2_gcd_mtd5] 315 root 916 S /sbin/ubusd 316 root 1480 S /bin/ash --login 639 root 1432 S /sbin/logd 653 root 1520 S /sbin/netifd 671 root 1188 S /usr/sbin/odhcpd 737 root 1148 S /usr/sbin/dropbear -F -P /var/run/dropbear.1.pid -p 22 886 root 1528 S /usr/sbin/uhttpd -f -h /www -r YSWiFi -x /cgi-bin -u /ubus -t 60 -T 30 -k 20 -A 1 -n 3 -N 100 -R -p 10.1.1.1 80 996 root 0 SW [RtmpCmdQTask] 997 root 0 SW [RtmpWscTask] 1042 root 1480 S /usr/sbin/ntpd -n -p time.asia.apple.com 0.openwrt.pool.ntp.org 1.openwrt.pool.ntp.org 2.openwrt.pool.ntp.org 1138 root 1484 S udhcpc -p /var/run/udhcpc-eth0.2.pid -s /lib/netifd/dhcp.script -f -t 0 -i eth0.2 -C 1601 nobody 984 S /usr/sbin/dnsmasq -C /var/etc/dnsmasq.conf -k 1976 root 5408 S squid -f /etc/squid/squid.conf 1978 nobody 14320 S {squid} (squid) -f /etc/squid/squid.conf 1979 nobody 768 S {unlinkd} (unlinkd) 1985 root 1240 S /usr/sbin/dropbear -F -P /var/run/dropbear.1.pid -p 22 1986 root 1488 S -ash 2009 root 1212 R /usr/sbin/dropbear -F -P /var/run/dropbear.1.pid -p 22 2010 root 1500 S -ash 2017 root 1476 R ps 2018 root 0 SW [kworker/0:1] [email protected]:~# </span>
缺点:
占用内存多,配置太复杂。
需要进一步优化啊,革命尚未成功,尔等仍需努力。
时间: 2024-10-31 19:15:27