squid-3.1.4-1.el6.i686eth0(外網 172.17.1.221/24)、eth1(內網 192.168.1.254/24)關鍵提醒:/etc/sysconfig/network-scripts/ifcfg-eth* 中的 HWADDR 必須與虛擬機網卡 MAC 完全一致,否則網卡無法啟動。
cp /etc/squid/squid.conf /etc/squid/squid.conf.bakhttp_access allow allvisible_hostname localhost 於檔案末尾,否則服務無法啟動http_port 3128 transparentservice squid restart
建立 squid.sh 自動化 iptables 規則:
#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
modprobe iptable_nat
/sbin/iptables -t nat -A POSTROUTING -j MASQUERADE
iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to 172.16.5.133
iptables -t nat -A PREROUTING -i eth1 -p tcp -s 192.168.1.0/24 --dport 80 -j REDIRECT --to-ports 3128
執行並持久化:
chmod +x squid.sh
./squid.sh
service iptables save
service iptables restart
| 項目 | 設定值 |
|---|---|
| IP | 192.168.1.x/24 |
| 閘道 | 192.168.1.254 |
| DNS | 192.168.1.254 |
瀏覽器不設定代理直接訪問 www.jb51.net,若能打開即透明代理成功。
IE → 工具 → 網際網路選項 → 連線 → 區域網路設定 → 代理伺服器:
IP: 192.168.1.254、Port: 3128。