溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Squid透明代理安裝與設(shè)置

發(fā)布時間:2020-06-26 10:44:21 來源:網(wǎng)絡(luò) 閱讀:1088 作者:rong341233 欄目:移動開發(fā)

環(huán)境如下:

操作系統(tǒng):CentOS 6.4

eth0:192.168.100.1 (LAN口)

eth2:200.168.10.1   (WAN口)


一.iptables的配置

1.啟動ip_forward(IP轉(zhuǎn)發(fā))

修改/etc/sysctl.conf

將net.ipv4.ip_forward = 1

并運行sysctl -p,使之生效

[root@nagios~]# vim /etc/sysctl.conf


[root@nagios ~]# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296



2.清空iptables所有表的規(guī)則并查看nat表

[root@nagios ~]# iptables -F
[root@nagios ~]# iptables -t nat -F
[root@nagios ~]# iptables -t mangle -F
[root@nagios ~]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination



3.設(shè)置端口重定向

[root@nagios ~]# iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3128


#在NAT表的PREROUTING鏈加目標動作REDIRECT,將入站的數(shù)據(jù)包進行重定向,將80端口重定向到3128端口

4.設(shè)置iptables路由DNS數(shù)據(jù)

[root@nagios~]#iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -p udp --dport 53 -d 202.96.128.86 -j SNAT --to-source 200.168.10.1
[root@nagios~]#iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -p tcp --dport 53 -d 202.96.128.86 -j SNAT --to-source 200.168.10.1


說明:可以看出上面DNS是通過服務(wù)器的NAT功能來實現(xiàn),202.96.128.86是外部DNS服務(wù)器地址,而200.168.10.1是我們WAN口的IP。如果外部DNS服務(wù)器經(jīng)常變更的話,可以直接將DNS忽略掉:

iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -p tcp --dport 53  -j SNAT --to-source 200.168.10.1

iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -p udp --dport 53  -j SNAT --to-source 200.168.10.1

5.保存iptables設(shè)置及重啟iptables服務(wù)

[root@Nagios ~]# service iptables save
[root@Nagios ~]# service iptables restart
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[root@Nagios ~]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
REDIRECT   tcp  --  192.168.10.0/24     anywhere            tcp dpt:http redir             ports 3128
Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
SNAT       udp  --  192.168.10.0/24     202.96.128.86       udp dpt:domain to:200.168.10.1
SNAT       tcp  --  192.168.10.0/24      202.96.128.86        tcp dpt:domain to:200.168.10.1
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination



二.Squid的安裝與配置

我們使用yum來安裝Squid:

[root@nagios ~]# yum -y install squid


備份squid的配置文件,防止因為配置錯誤

[root@nagios ~]# cp /etc/squid/squid.conf /etc/squid/squid.conf_bak


配置squid.conf

找到

http_port 3128修改成http_port 192.168.100.10:3128 transparent

并添加

visible_hostname squid
acl innet src 192.168.10.0/24
http_access allow innet
http_access deny all



下面就運行squid -z進行初始化

[root@nagios ~]# squid -z
2013/05/29 13:41:43| Creating Swap Directories


啟動squid代理服務(wù)器

[root@nagios ~]# service squid start


重新啟動iptables服務(wù)

[root@nagios ~]# service iptables restart


并將squid及iptables設(shè)置成開機啟動

[root@nagios ~]# chkconfig --level 35 squid on
[root@nagios ~]# chkconfig --level 35 iptables on




客戶端網(wǎng)絡(luò)設(shè)置: DNS設(shè)置為轉(zhuǎn)發(fā)的DNS IP
Squid透明代理安裝與設(shè)置


其他設(shè)置:

隱藏錯誤頁面Squid版本

httpd_suppress_version_string on


不記錄訪問日志

cache_store_log none
cache_access_log /dev/null
cache_log /dev/null


隱藏Header頭部信息(3.0以后版本)

request_header_access Via deny all
request_header_access Server deny all
request_header_access X-Cache deny all
request_header_access X-Cache-Lookup deny all


如果是2.8之前的版本

header_access Via deny all
header_access Server deny all
header_access X-Cache deny all
header_access X-Cache-Lookup deny all


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI