394 字
2 分钟
使用Linux搭建proxy和dns服务器进行测试
如何使用coreDNS和Squid搭建一个自托管的代理服务器。
使用Squid搭建http proxy
安装Squid
# Ubuntu/Debiansudo apt update && sudo apt install squid apache2-utils# CentOS/RHELsudo yum install squid httpd-tools配置Squid
准备认证的用户
sudo touch /etc/squid/passwdssudo htpasswd -c /etc/squid/passwds username # 按照提示设置密码修改Squid配置文件
创建/etc/squid/squid.conf文件,如果已经存在则编辑它。
sudo cp /etc/squid/squid.conf /etc/squid/squid-http.confsudo vim /etc/squid/squid-http.conf编辑/etc/squid/squid.conf文件,添加以下配置:
http_port 3128auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwordsauth_param basic children 5acl auth_users proxy_auth REQUIREDhttp_access allow auth_users开启防火墙
# Ubuntu/Debiansudo ufw allow 3128/tcpsudo ufw reload# CentOS/RHELsudo firewall-cmd --permanent --add-port=3128/tcpsudo firewall-cmd --reload启动Squid
sudo squid -f /etc/squid/squid-http.conf使用coreDNS搭建dns服务器
下载coreDNS
从这里下载最新版本的coreDNS,并解压缩。
wget https://github.com/coredns/coredns/releases/latest/download/coredns_1.12.2_linux_arm.tgztar -zxvf coredns_1.12.2_linux_arm.tgz配置coreDNS
创建配置文件
创建Corefile配置文件:
sudo vim Corefile注意这里的ip要与需要测试的机器处于同一网络段。
.:53 { hosts { 10.254.7.38 http-proxy.test fallthrough } forward . 114.114.114.114 log errors}开启防火墙
# Ubuntu/Debiansudo ufw allow 53/tcpsudo ufw allow 53/udpsudo ufw reload# CentOS/RHELsudo firewall-cmd --permanent --add-port=53/tcpsudo firewall-cmd --permanent --add-port=53/udpsudo firewall-cmd --reload启动coreDNS
sudo ./coredns -conf Corefile测试
测试Squid代理
使用任意软件测试,代理填好后,如果成功连接,代理的日志会有相应的输出。
测试coreDNS
不设置DNS服务器
可以使用使用nslookup命令进行测试:
nslookup http-proxy.test 10.254.7.38设置DNS服务器
在Windows或Linux上设置DNS服务器为10.254.7.38,然后使用nslookup或dig命令测试解析。
nslookup http-proxy.test如果配置正确,应该会返回10.254.7.38。
使用Linux搭建proxy和dns服务器进行测试
https://blog.xiaobaizhang.top/posts/self-hosted-proxy/