centos 下正向代理 原

安裝 bbr加速

使用 squid 作爲正向代理服務器

1.安裝squid

yum install squid

2.修改默認文件

vim /etc/squid/squid.conf

簡單點,將其中 http_access deny all 改爲 http_access allow all,默認訪問端口爲 3128,建議改爲其它端口。

配置示例(轉到

#############################################################################
# squid權限控制 acl和http_access
#############################################################################
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
 
# 聲明我的IP,來自我的IP,可以請求squid。注意一定要有掩碼
acl myip src 121.14.10.9/32
 
# 局域網內的IP,看情況是否考慮需要
acl localnet src 10.0.0.0/8         # 一般大型企業或者學校使用,或者虛擬機中的網絡
acl localnet src 172.16.0.0/12      # 一般很少用
acl localnet src 192.168.0.0/16     # 一般家用路由器或者虛擬機中的網絡
acl localnet src fc00::/7           # IPv6
acl localnet src fe80::/10          # IPv6
 
# 定義ssl端口、一些安全端口和http訪問的connect方法
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
acl CONNECT method CONNECT
 
 
# 推薦最小訪問權限配置
 
# 允許本機管理緩存,其他的拒絕
http_access allow manager localhost
http_access deny manager
 
# 拒絕非安全端口
http_access deny !Safe_ports
 
# 拒絕connect到非ssl 443端口(上面定義了)
http_access deny CONNECT !SSL_ports
 
# 強烈建議去除註釋。防止通過代理來訪問本代理服務器上的web程序
# 以免認爲是localhost用戶訪問web服務。
#http_access deny to_localhost
 
# 下面插入你自己的規則
#---------
# 允許我的IP訪問squid
http_access allow myip
 
 
# 允許localhost和局域網內用戶的請求,根據需要調整
http_access allow localnet
http_access allow localhost
 
# 最後,拒絕其他的對代理的訪問
http_access deny all
 
#############################################################################
##   Squid的基本配置
#############################################################################
# 默認監聽3128端口
http_port 3128
 
# 設置對外顯示的主機名
visible_hostname proxy.daoiqi.com
 
# 對於本地配置hosts的網站,沒有此配置,squid無法訪問本地的hosts。
# 但是官網文檔默認值就是/etc/hosts,我要顯示聲明纔有效。
hosts_file /etc/hosts
 
#############################################################################
###    squid緩存配置
#############################################################################
# 建議最少使用下面一行
hierarchy_stoplist cgi-bin ?
 
# 去除註釋並調整下面這行語句來增加一個磁盤緩存目錄
#cache_dir ufs /var/spool/squid 100 16 256
 
# 將核心輸出保存在第一個緩存目錄
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 .       0   20% 4320

3. 啓動及設置開機自啓

systemctl enable squid
systemctl start squid

使用 shadowsocks 作爲代理服務器

1. 安裝 shadowsocks

yum install python-setuptools && easy_install pip 
pip install shadowsocks

2. 設置監聽 443端口

sudo ssserver -p 443 -k password -m rc4-md5 –user nobody -d start

3. 安裝 Privoxy

yum install privoxy

4. 修改 /etc/privoxy/config

listen-address  :8118  
enable-remote-toggle  1  

5. 在末尾添加

forward-socks5 / 127.0.0.1:443 

6.啓動和設置開機自啓

systemctrl enable privoxy
systemctrl start privoxy

最後一步,關閉防火牆

systemctl disalbe firewalld
systemctl stop firewalld

systemctl disable iptables
systemctl stop iptables

iptables 使用

iptables -I INPUT -p tcp --dport 3306 -j ACCEPT # 開放 3306 端口

iptables -nvL  --line-numbers # 查看端口及序號

iptables -D INPUT 3 # 刪除第三條規則

sudo iptables-save > /etc/iptables/iptables.rules  # 存入配置文件中

firewalld 使用

# 開機自啓
sudo systemctl enable firewalld
sudo systemctl start firewalld

# 開放常見端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --zone=public --add-port=21/tcp --permanent
firewall-cmd --zone=public --add-port=53/udp --permanent

# 關閉端口
firewall-cmd --zone=public --remove-port=80/tcp --permanent
firewall-cmd --zone=public --remove-port=443/tcp --permanent
firewall-cmd --zone=public --remove-port=22/tcp --permanent
firewall-cmd --zone=public --remove-port=21/tcp --permanent
firewall-cmd --zone=public --remove-port=53/udp --permanent

# 批量添加區間端口
firewall-cmd --zone=public --add-port=4400-4600/udp --permanent
firewall-cmd --zone=public --add-port=4400-4600/tcp --permanent

# 重新加載配置
sudo systemctl restart firewalld

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章