5. 下面的命令针对linux 2.2.x内核: # Accept all on lookback /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内核:
# Accept all on loopback 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
6.应注意的问题:
a. 这种透明代理只能针对http协议,不能针对FTP协议来源:www.examda.com b. PC的默认网关应设成squid 代理服务器 c. 防火墙重定向规则在其它的input规则的前面,注意顺序。 如: /etc/rc.d/rc.firewall:
#!/bin/sh # rc.firewall linux kernel firewalling rules FW=/sbin/ipfwadm
# Flush rules, for testing purposes for i in I O F # A # If we enabled accounting too do ${FW} -$i -f done
# Loopback-interface (local access, eg, to local nameserver): ${FW} -I -a acc -S localhost/32 -D localhost/32
# Local Ethernet-interface:
# Redirect to Squid proxy server: ${FW} -I -a acc -P tcp -D default/0 80 -r 8080
# Accept packets from local network: ${FW} -I -a acc -P all -S localnet/8 -D default/0 -W eth0
# Only required for other types of traffic (FTP, Telnet):
# Forward localnet with masquerading (udp and tcp, no icmp!): ${FW} -F -a m -P tcp -S localnet/8 -D default/0 ${FW} -F -a m -P udp -S localnet/8 -D default/0
Here all traffic from the local LAN with any destination gets redirected to the local port 8080. Rules can be viewed like this:
IP firewall input rules, default policy: reject 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 * -> *