魷魚代理伺服器配置

魷魚代理伺服器配置

我已經在遠端伺服器(ubuntu 12.04)上安裝了squid3伺服器,我想將其用作代理伺服器。我需要進行哪些配置才能在每台具有互聯網連接的電腦上使用它?

答案1

我只需要更改一項預設設定; http_port 行。聽起來你想做我設定的事情;透過squid作為透明代理自動分流流量。為此,該行應為:

http_port 3128 transparent

我還在我的系統中使用 dansguardian,因此我的 iptables 規則可能不適合您,但您需要使用它來引導通過魷魚從網絡流入並流出到互聯網的流量。像這樣的事情:

#!/bin/sh
# squid server IP
SQUID_SERVER="10.0.0.1"
# Interface connected to Internet
INTERNET="bond0"
# Interface for 10.0.0.1
LAN_IN="bond1"
# Dansguardian port
DG_PORT="8080"
#DG_PORT="3128"

echo "Applying proxy rules for packets routing through $LAN_IN -> $SQUID_SERVER:$DG_PORT"

# DO NOT MODIFY BELOW
# Clean old firewall
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X

iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT

# Unlimited access to loop back
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Allow UDP, DNS and Passive FTP
iptables -A INPUT -i $INTERNET -m state --state ESTABLISHED,RELATED -j ACCEPT

# set this system as a router for Rest of LAN
iptables --table nat --append POSTROUTING --out-interface $INTERNET -j MASQUERADE
iptables --append FORWARD --in-interface $LAN_IN -j ACCEPT

# unlimited access to LAN
iptables -A INPUT -i $LAN_IN -j ACCEPT
iptables -A OUTPUT -o $LAN_IN -j ACCEPT

# port forwarding

# HTTP (example)
iptables -t nat -A PREROUTING -i $INTERNET -p tcp --dport 80 -j DNAT --to 10.0.0.1:80
iptables -A INPUT -p tcp -m state --state NEW --dport 80 -i $INTERNET -j ACCEPT

# Divert traffic for external web pages through squid (dansguardian)
iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j DNAT --to $SQUID_SERVER:$DG_PORT
iptables -A OUTPUT -p tcp -o $LAN_IN --dport 80 -j ACCEPT

我的 /etc/network/if-up.d/proxyrules 中有該腳本的(更充實的)版本。一些調整應該可以讓您愉快地啟動並運行。

您可能需要擺弄的另一個 Squid 設定是 ACL;允許人們存取您的代理伺服器。我的確實可以使用預設值,但您可能需要修改此部分以解決 Squid“存取被拒絕”錯誤。

相關內容