squid实现内网访问外网

安装squid

在能够访问外网的机器上安装squid

brew install squid
yum install -y squid

修改squid配置

vim /opt/homebrew/etc/squid.conf # mac

如果只是临时使用,可以修改http_access deny allhttp_access allow all
如果不修改,内网机器curl www.baidu.com会出现403

启动停止squid

# 启动
$ squid
# 启动成功后
$ lsof -i :3128
COMMAND   PID      USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
squid   10857 xxx   14u  IPv6 0xe374a5f501996b2b      0t0  TCP *:ndl-aas (LISTEN)
$ curl  -xlocalhost:3128 www.baidu.com -I
HTTP/1.1 200 OK
...

# 停止
$ squid -k shutdown

# 前台启动暂停可以使用:
$ squid  -N -d1 
# -N  主进程在前台运行作为工作进程,并且没有子进程
# -d1 debugging日志打印,等级1

内网机器配置http_proxy

export https_proxy=http://外网机器IP:3128
export http_proxy=http://外网机器IP:3128

$ curl www.baidu.com -I
HTTP/1.1 200 OK
...

# 不使用的时候unset
unset https_proxy
unset http_proxy
posted @ 2024-05-29 16:57  angelophenia  阅读(106)  评论(0)    收藏  举报