我是新的 Squid,我正在尝试在全通透明代理的简单测试用例中使用它。
我的配置是:
Web-browser->Local_Server{eth0/port-443->(Transparent Proxy)->port-443/eth1}->{Internet}
鱿鱼版本:3.5.25
下面是
squid.conf
文件内容、iptables -nvL
和 iptables -nvL -t nat
命令输出。
当Squid运行时,我期望能够浏览到所有网站。但是,所有网站的访问都被阻止了?!
squid.conf 文件内容:
# 1) Visible hostname
visible_hostname ctct-r2
# Debugging
debug_options ALL,1 33,2 28,9
# Enable log
access_log daemon:/var/log/squid/access.log squid
# 2) Initialize SSL database
sslcrtd_program /usr/libexec/ssl_crtd -s /var/lib/ssl_db -M 4MB
# Do not use caching
# cache_dir ufs /var/volatile/log/squid/logs 100 16 256
# 3) Listen to incoming HTTP traffic
http_port 3128
# 4) Listen for incoming HTTPS traffic and intercept it
https_port 3129 intercept ssl-bump cert=/etc/squid/ssl_cert/myCA.pem generate-host-certificates=on dynamic_cert_mem_cache_size=4MB
# 5) Pass the SSL (HTTPS) traffic transparently through
ssl_bump splice all
# 6) Allow all HTTP traffic
http_access allow all
# 7) Send out all traffic to Internet via given IP address
tcp_outgoing_address 10.3.19.150
# iptables -vnL
Chain INPUT (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
1467 121K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
1 59 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0 icmptype 8 ctstate NEW
0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate INVALID
83243 15M APP_RULES all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW
83243 15M OS_RULES all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate NEW
15 3195 REJECT udp -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
64 3840 REJECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 reject-with tcp-reset
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-proto-unreachable
Chain FORWARD (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
0 0 ACCEPT all -- wlan1 wlan1 0.0.0.0/0 0.0.0.0/0
7 651 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-unreachable
Chain OUTPUT (policy ACCEPT 915 packets, 82175 bytes)
pkts bytes target prot opt in out source destination
Chain APP_RULES (1 references)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- eth1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:20
0 0 ACCEPT tcp -- eth1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:21
0 0 ACCEPT tcp -- eth1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
Chain DEV_RULES (2 references)
pkts bytes target prot opt in out source destination
2 120 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1534
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:2345
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:1534
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:2345
Chain EXTERNAL_RULES (2 references)
pkts bytes target prot opt in out source destination
83158 15M DROP all -- * * 0.0.0.0/0 0.0.0.0/0
Chain INTERNAL_RULES (2 references)
pkts bytes target prot opt in out source destination
4 269 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:53
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:67
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:68
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
Chain OS_RULES (1 references)
pkts bytes target prot opt in out source destination
85 7424 DEV_RULES all -- eth0 * 0.0.0.0/0 0.0.0.0/0
0 0 DEV_RULES all -- wlan1 * 0.0.0.0/0 0.0.0.0/0
83 7304 INTERNAL_RULES all -- eth0 * 0.0.0.0/0 0.0.0.0/0
0 0 INTERNAL_RULES all -- wlan1 * 0.0.0.0/0 0.0.0.0/0
83158 15M EXTERNAL_RULES all -- eth1 * 0.0.0.0/0 0.0.0.0/0
0 0 EXTERNAL_RULES all -- wlan0 * 0.0.0.0/0 0.0.0.0/0
# iptables -vnL -t nat
Chain PREROUTING (policy ACCEPT 55227 packets, 10M bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 10.3.19.150 0.0.0.0/0 tcp dpt:80
0 0 ACCEPT tcp -- * * 10.3.19.150 0.0.0.0/0 tcp dpt:443
21 1260 REDIRECT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:443 redir ports 3129
0 0 REDIRECT tcp -- eth0 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 redir ports 3128
Chain INPUT (policy ACCEPT 4 packets, 508 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 8 packets, 532 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 MASQUERADE all -- * eth1 192.168.168.0/24 0.0.0.0/0
0 0 MASQUERADE all -- * eth1 192.168.192.0/24 0.0.0.0/0
0 0 MASQUERADE all -- * wlan0 192.168.168.0/24 0.0.0.0/0
0 0 MASQUERADE all -- * wlan0 192.168.192.0/24 0.0.0.0/0
29 1372 MASQUERADE all -- * * 0.0.0.0/0 0.0.0.0/0
您似乎已将 Squid 设置为透明代理,但将流量重定向到 Squid 的 iptables 规则可能存在问题。让我们逐步检查您的配置,以确定任何潜在的问题: 鱿鱼配置: 您的 Squid 配置似乎已正确设置为透明代理,分别侦听端口 3128 和 3129 的 HTTP 和 HTTPS 流量。 您已使用 http_access allowed all 行允许所有 HTTP 流量,这应该允许访问所有网站。 iptables 规则(iptables -nvL 和 iptables -nvL -t nat): 您的 iptables 规则似乎将流量正确重定向到 Squid 代理端口,这很好。您将 HTTP(端口 80)和 HTTPS(端口 443)流量重定向到 Squid 的 HTTP 和 HTTPS 端口(3128 和 3129)。 nat 表中的 PREROUTING 链是重定向发生的地方,并且它似乎设置正确。 过滤器表中的 INPUT 和 OUTPUT 链也允许流量。但是,您可能希望确保 iptables 配置中的其他位置没有可能产生干扰的其他规则。 可能的问题: 确保 Squid 服务正在运行并侦听指定端口(3128 和 3129)。您可以使用 netstat 命令检查这一点。 仔细检查您的服务器上是否没有其他可能阻止访问外部网站的防火墙规则或安全软件。有时,iptables 之外的其他防火墙规则可能会导致问题。 确认您服务器上的 DNS 配置正常工作。 Squid 需要 DNS 解析才能充当透明代理。您应该确保您的 DNS 服务器配置正确并且 Squid 可以解析域名。 检查 Squid 访问日志
(/var/log/squid/access.log)
,查看是否有与拒绝请求相关的条目。这可以帮助您确定 Squid 是否正在接收请求但出于任何原因拒绝它们。
检查 Squid 缓存日志和系统日志文件中是否有任何可能指示代理设置问题的错误消息或警告。
确保您的 Squid 和 iptables 配置符合您的网络拓扑和要求。如果您的网络配置比描述的更复杂,则可能会导致意外行为。
通过仔细检查和测试配置的这些方面,您应该能够识别并解决导致访问外部网站被阻止的问题。