2.我需要什么样的环境才能实现透明代理?
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
http_port 8080
httpd_accel virtual 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
[ ] Socket Filtering
[*] Unix domain sockets
[*] TCP/IP networking
[ ] IP: multicasting
[ ] IP: advanced router
[ ] IP: kernel level autoconfiguration
[*] IP: firewalling
[ ] IP: firewall packet netlink device
[*] IP: always defragment (required for masquerading)
5. 下面的命令针对Linux 2.2.x内核:
/sbin/ipchains -A input -j ACCEPT -i lo
#Accept my own IP, to prevent loops (repeat for each interface/alias)
/sbin/ipchains -A input -j ACCEPT -p tcp -d 192.168.11.1/32 80
#Send all traffic destined to port 80 to Squid on port 80
/sbin/ipchains -A input -j REDIRECT 8080 -p tcp -s 192.168.11.0/24 -d 0/0 80
下面的命令针对Linux 2.0.x内核:
ipfwadm -I -a accept -W lo
# Accept my own IP, to prevent loops (repeat for each interface/alias)
ipfwadm -I -a accept -P tcp -D 192.168.11.1/32 80
# Send all traffic destined to port 80 to Squid on port 3128
ipfwadm -I -a accept -P tcp -S 192.168.11.0/24 -D 0/0 80 -r 8080
b. PC的默认网关应设成squid 代理服务器
c. 防火墙重定向规则在其它的input规则的前面,注意顺序。
#!/bin/sh
# rc.firewall Linux kernel firewalling rules
FW=/sbin/ipfwadm
for i in I O F # A # If we enabled accounting too
do
${FW} -$i -f
done
${FW} -I -p rej # Incoming policy: reject (quick error)
${FW} -O -p acc # Output policy: accept
${FW} -F -p den # Forwarding policy: deny
# Loopback-interface (local access, eg, to local nameserver):
${FW} -I -a acc -S localhost/32 -D localhost/32
${FW} -I -a acc -P tcp -D default/0 80 -r 8080
${FW} -I -a acc -P all -S localnet/8 -D default/0 -W eth0
${FW} -F -a m -P tcp -S localnet/8 -D default/0
${FW} -F -a m -P udp -S localnet/8 -D default/0
local port 8080. Rules can be viewed like this:
type prot source destination ports
acc all 127.0.0.1 127.0.0.1 n/a
acc/r tcp 10.0.0.0/8 0.0.0.0/0 * -> 80 => 8080
acc all 10.0.0.0/8 0.0.0.0/0 n/a
acc tcp 0.0.0.0/0 0.0.0.0/0 * -> *