如何在CentOS 8/RHEL 8上配置Squid代理服务器
时间:2020-03-21 11:43:03 来源:igfitidea点击:
首先,我们在了解透明代理服务器之前先了解代理服务器。
代理服务器用于与客户端共享Internet连接。
可以将代理服务器配置为透明代理服务器。
共享Internet连接和缓存Web服务器。
首先将网页存储在本地以提高性能。
代理防火墙可控制对Internet的访问。
Squid代理是使用最广泛的开源代理,这些软件用于透明代理服务器。
透明代理服务器的工作原理
Squid代理服务器快速关键点
- 软件包– squid * .rpm
- 端口号– 3128(默认)
- 配置文件– /etc/squid/squid.conf
- 服务/守护程序–Squid
Squid代理服务器安装和配置
首先在步骤一中(安装Squid代理软件包)
# yum install squid*
其次在第二步(编辑配置文件)
# vi /etc/squid/squid.conf
首先修改以下参数
http_port 3128 transparent visible_hostname linux?squid cache_dir ufs /var/spool/squid 100 16 256 acl our_networks src 192.168.0.0/24 acl business_hours time S M T W H F A 09:00?17:30 acl test url_regex www.yahoo.com http_access allow our_networks business_hours test
第三步之后(运行Natting脚本)
# vim transparent_proxy.sh
然后添加给定的行
#!/bin/sh SQUID_SERVER="192.168.0.12" # Interface connected to Internet INTERNET="eth0" # Interface connected to LAN LAN_IN="eth1" # Squid port SQUID_PORT="3128" # 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 # Load IPTABLES modules for NAT and IP conntrack support modprobe ip_conntrack modprobe ip_conntrack_ftp # For win xp ftp client #modprobe ip_nat_ftp echo 1 > /proc/sys/net/ipv4/ip_forward # Setting default filter policy 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 # Load IPTA # DNAT port 80 request comming from LAN systems to squid 3128 ($SQUID_PORT) aka transparent proxy iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j DNAT --to $SQUID_SERVER:$SQUID_PORT # if it is same system iptables -t nat -A PREROUTING -i $INTERNET -p tcp --dport 80 -j REDIRECT --to-port $SQUID_PORT # DROP everything and Log it iptables -A INPUT -j LOG iptables -A INPUT -j DROP
之后,运行脚本
# bash transparent_proxy.sh
最后在步骤IV中(重新启动squid服务)
# service squid restart
Linux客户端配置
首先在步骤一中(刷新网络)
# netconfig
在第II步中认真(以Gateway ip作为代理)
最后在步骤III中(打开浏览器并开始浏览)
我们已经在CentOS和RHEL上配置了Squid代理服务器。