Linux 内网服务器通过代理访问外网

服务器1 不通外网,通过服务器2代理,访问外网

1. 在服务器2上安装 squid

1.1 安装 squid(博主是deepin系统)

javascript 复制代码
sudo apt update
sudo apt install squid

检查是否安装成功:

javascript 复制代码
squid -v

1.2 修改 squid 配置

备份原配置:

javascript 复制代码
cd /etc/squid/
sudo cp squid.conf squid.conf_bak

编辑 配置文件,增加如下内容:

javascript 复制代码
# 基本配置
http_port 3128

# 定义ACL规则 - 允许服务器1的IP访问
# 假设服务器1的内网IP是 192.168.1.100
acl server1 src xxxx具体ip/32

# 如果有多台服务器需要代理,可以配置网段
# acl internal_network src 192.168.1.0/24

# 定义安全端口
acl Safe_ports port 80          # http
acl Safe_ports port 443         # https
acl Safe_ports port 21          # ftp
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

# 访问控制规则
# 允许服务器1使用代理
http_access allow server1

# 允许本地访问
http_access allow localhost
http_access allow all

# 拒绝其他所有
#http_access deny all

# 缓存设置(可选)
cache_dir ufs /var/spool/squid 100 16 256
maximum_object_size 4 MB

# 日志设置
access_log /var/log/squid/access.log squid
cache_log /var/log/squid/cache.log

检查语法是否正确:

javascript 复制代码
sudo squid -k parse

没有FATAL 提示就没问题,有提示 按照提示修改

1.3 启动 squid

javascript 复制代码
sudo systemctl restart squid

1.4 查看端口

javascript 复制代码
sudo netstat -tlnp | grep 3128

1.5 测试是否配置正确

javascript 复制代码
curl -x http://xxx服务器1地址:3128 http://www.baidu.com
  1. 在服务器1上 配置代理

2.1 修改 /etc/profile

在末尾追加如下:

javascript 复制代码
export http_proxy="http://服务器1地址:3128"
export https_proxy="http://服务器1地址:3128"
export ftp_proxy="http://服务器1地址:3128"
export no_proxy="localhost,127.0.0.1,192.168.1.0/24"

2.2 让配置生效

javascript 复制代码
source /etc/profile

检查配置:

javascript 复制代码
echo $http_proxy

如果打印:http://服务器1地址:3128

就OK了

2.3 测试是否配置成功

javascript 复制代码
curl www.baidu.com
相关推荐
木头左16 小时前
【Nginx】内网服务源 IP 白名单实战:动态域名解析放行网段 + 端口接管零改造
运维·nginx·白名单·反向代理
Linux-lucky16 小时前
45-Linux学习之旅之防火墙与WEB加固
linux·前端·网络·学习·ubuntu
禁默16 小时前
启元 Q1 二次开发实践:Ubuntu 部署与仿真验证,从 PrimeConsole 到 ROS 2 Humble + RViz
linux·运维·ubuntu
skywalk816317 小时前
把 去也网站 从 Ubuntu 搬到 FreeBSD:一次 Service Jail + nginx 的部署实录
linux·运维·nginx·ubuntu·freebsd
翔云12345618 小时前
RocksDB中,客户端每写入一次数据,需要访问几次磁盘
运维·数据库·mysql
爱莉希雅&&&19 小时前
GitLab 完整学习笔记
linux·运维·服务器
风笙97819 小时前
[文件系统]文件系统挂载与卸载详解
linux
GeW19 小时前
新质生产力路线图解读:数据库性能优化与Linux调优专场
linux·数据库
小杨爱科普20 小时前
制造业上自动化改造,改造部分的专利到底归谁
运维·经验分享·自动化
陈希12321 小时前
Linux 服务器性能排查手册(2026):CPU、内存、磁盘IO、网络四大瓶颈定位
linux·服务器·网络