如何强制所有客户端在热点上使用 Squid 代理服务器

如何强制所有客户端在热点上使用 Squid 代理服务器

我有两个 wifi 接口,一个是内置的,另一个是 USB 适配器。作为研究,我想使用 hostapd 启动热点并使用 dnsmasq 为用户提供 IP 地址。我按照本指南使用了 nftableshttps://wiki.archlinux.org/title/Internet_sharing与客户共享互联网。

这是我的 Squid 配置条目

http_access deny blockedsites

acl localnet src 0.0.0.1-0.255.255.255  # RFC 1122 "this" network (LAN)
acl localnet src 10.0.0.0/8     # RFC 1918 local private network (LAN)
acl localnet src 100.64.0.0/10      # RFC 6598 shared address space (CGN)
acl localnet src 169.254.0.0/16     # RFC 3927 link-local (directly plugged) machines
acl localnet src 172.16.0.0/12      # RFC 1918 local private network (LAN)
acl localnet src 192.168.0.0/16     # RFC 1918 local private network (LAN)
acl localnet src fc00::/7           # RFC 4193 local private network range
acl localnet src fe80::/10          # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port 443
acl Safe_ports port 80      # http
acl Safe_ports port 21      # ftp
acl Safe_ports port 443     # https
acl Safe_ports port 70      # gopher
acl Safe_ports port 210     # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280     # http-mgmt
acl Safe_ports port 488     # gss-http
acl Safe_ports port 591     # filemaker
acl Safe_ports port 777     # multiling http
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
include /etc/squid/conf.d/*.conf
http_access allow localhost
http_access allow all
http_port 3128
coredump_dir /var/spool/squid
refresh_pattern ^ftp:       1440    20% 10080
refresh_pattern ^gopher:    1440    0%  1440
refresh_pattern -i (/cgi-bin/|\?) 0 0%  0
refresh_pattern \/(Packages|Sources)(|\.bz2|\.gz|\.xz)$ 0 0% 0 refresh-ims
refresh_pattern \/Release(|\.gpg)$ 0 0% 0 refresh-ims
refresh_pattern \/InRelease$ 0 0% 0 refresh-ims
refresh_pattern \/(Translation-.*)(|\.bz2|\.gz|\.xz)$ 0 0% 0 refresh-ims
refresh_pattern .       0   20% 4320
shutdown_lifetime 10 seconds

所有客户端都连接到WLAN1互联网连接的接口。如何强制所有客户端请求都通过 Squid 代理服务器?我习惯使用 iptables 或其他类似的包

答案1

如果您熟悉使用 iptables,您可以自己回答您的问题。以 DNAT 作为简单端口的示例。

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination <proxy IP>

(所有端口都需要)

免责声明:

  1. 您想要做的就是透明代理。所有流量都必须通过执行 iptables 重定向的 (ubuntu-) 服务器。
  2. 这对于 http 非常有效,但对于 https 则不然——因为你实施了某种中间人攻击。但这是一个不同的问题,不是你的问题的一部分 :-)

相关内容