squid-3.1.1 と linux-2.6.32.8 で透過型プロクシ
なかなかうまくいかなかったのだけど, ようやく動いたっぽいのでまとめ. と言いた
いけどいろいろ忘れてしまっているので中途半端.
カーネルは
CONFIG_IP_NF_TARGET_REDIRECT=y
あたりが必要.
CONFIG_IP_NF_TARGET_REDIRECT=y
まわりでいろいろ必要だったけど忘却. まあなんとかなるでしょう.
squid は --enable-linux-netfilter つけてビルドしないと透過型にならない. ここ
ではまった. prefix が /usr/local/squid なので気に入らないなら変えておく.
squid.conf は
acl localhost src 127.0.0.1 acl eth0 src 192.168.0.2-192.168.0.3 http_access allow localhost http_access allow eth0 http_access deny all http_port 8080 transparent hierarchy_stoplist cgi-bin ? cache_mem 50 MB cache_dir ufs /var/cache/squid 100 16 256 access_log /var/log/squid/access.log squid cache_log /var/log/squid/cache.log cache_store_log /var/log/squid/store.log logfile_rotate 2 url_rewrite_program /usr/local/bin/squidGuard -c /usr/local/squidGuard/squidGuard.conf url_rewrite_children 5 refresh_pattern ^ftp: 1440 20% 10080 refresh_pattern ^gopher: 1440 0% 1440 refresh_pattern (cgi-bin|\?) 0 0% 0 refresh_pattern . 0 20% 4320 cache_effective_user squid cache_effective_group squid visible_hostname hage coredump_dir /var/cache/squid
iptables は
iptables -t nat -A OUTPUT -p tcp --dport 80 -m owner ! --uid-owner 23 -j REDIRECT --to-port 8080 #iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
コメントのやりかたでも動くと思うけど, よくわからん.
/etc/rc.d/init.d/squid は dhcp での ip アドレスを起動時にとりたいので
. /etc/sysconfig/rc . ${rc_functions} bindir=/usr/local/sbin ifconfig=/sbin/ifconfig grep=/bin/grep sed=/bin/sed gawk=/usr/bin/gawk squidconf=/usr/local/etc/squid.conf ip=`$ifconfig | $grep -A 1 "^eth0" | $grep "inet addr:" | $gawk -F: '{print $2};'| $gawk '{print $1}'` case "${1}" in start) boot_mesg "Start Squid" $sed -i "s/^acl\s\+eth0.*$/acl eth0 src $ip/" $squidconf $bindir/squid -s > /tmp/squidstart 2>&1 #$bindir/squid -sY > /dev/null 2>&1 evaluate_retval ;; stop) boot_mesg "Stop Squid" $bindir/squid -k kill #killall squid #rm /opt/squidGuard/log/* rm /var/log/squid/* evaluate_retval ;; reload) boot_mesg "Reload Squid" $bindir/squid -k reconfigure evaluate_retval ;; restart) ${0} stop sleep 1 ${0} start evaluate_retval ;; status) $bindir/squid -k check >& /dev/null evaluate_retval ;; *) echo "Usage: ${0} {start|stop|reload|restart|status}" exit 1 ;; esac
起動時のパスを知らないので常にフルパス.