Linux内网服务器通过代理访问外网服务器
创始人
2025-01-20 08:03:38
0

目录

一、环境介绍

二、安装squid

三、配置代理

扩展一、JAVA应用通过代理访问外网

扩展二、通过nginx代理实现yum跳转

扩展三、代理harbor镜像方式访问


一、环境介绍

192.168.7.131可以通外网

192.168.7.129不通外网

需要通过代理的方式实现192.168.7.129可以访问外网

二、安装squid

 1、在192.168.7.131主机(可以访问外网)使用yum安装squid

yum -y install squid

  2、编辑/etc/squid/squid.conf配置文件

 默认端口为3128,可根据实际需求更改

 3、启动squid服务并实现开机自启

systemctl start squid  systemctl enable squid

三、配置代理

1、在不通外网的主机192.168.7.129进行测试curl www.baidu.com

2、在/etc/profile中添加以下内容

[root@jh-newa-node09 ~]# tail -2 /etc/profile export http_proxy=http://192.168.7.131:3128 export https_proxy=https://192.168.7.131:3128 [root@jh-newa-node09 ~]# source /etc/profile

3、配置后再次测试

扩展一、JAVA应用通过代理访问外网

bin/setenv.sh文件中添加

-Dhttp.proxyHost=192.168.7.131 -Dhttp.proxyPort=3128 -Dhttps.proxyHost=192.168.7.131 -Dhttps.proxyPort=3128 

扩展二、通过nginx代理实现yum跳转

1、在通外网的主机上配置nginx

#nginx配置文件中添加如下参数,暴露本机的8082 8083端口,将请求转发至mirrors.aliyun.com [root@ecs-37b3-0729076 ~]# vim /etc/nginx/nginx.conf     server {         listen       192.168.7.131:8083;         server_name  mirrors.cloud.aliyuncs.com;          location / {           proxy_pass  http://mirrors.aliyun.com;           # index  index.html index.htm;         }         error_page   500 502 503 504  /50x.html;         location = /50x.html {             root   html;         }  }     server {         listen       192.168.7.131:8082;         server_name  epel.com;          location / {           proxy_pass http://mirrors.aliyun.com;           # index  index.html index.htm;         }         error_page   500 502 503 504  /50x.html;         location = /50x.html {             root   html;         }  } [root@ecs-37b3-0729076 ~]# systemctl start nginx

2、在不通外网主机/etc/yum.repos.d/目录下替换yum源

[root@jh-newa-node09 ~]# cd /etc/yum.repos.d/ [root@jh-newa-node09 yum.repos.d]# ls CentOS.repo  epel-7.repo  repo [root@jh-newa-node09 yum.repos.d]# sed -i s/mirrors.aliyun.com/192.168.7.131:8083/g CentOS.repo [root@jh-newa-node09 yum.repos.d]# sed -i s/mirrors.aliyun.com/192.168.7.131:8082/g epel-7.repo

3、测试:

[root@jh-newa-node09 yum.repos.d]# yum  -y install squid

扩展三、代理harbor镜像方式访问

1、确保外网主机到镜像仓库网络可达

 2、内网主机docker配置文件中添加如下参数

mkdir  /etc/systemd/system/docker.service.d vim /etc/systemd/system/docker.service.d/http-proxy.conf [Service] Environment="HTTP_PROXY=http://192.168.7.131:3128" Environment="HTTPS_PROXY=http://192.168.7.131:3128" systemctl daemon-reload systemctl restart docker

3、测试:

相关内容

热门资讯

第9分钟精通!宁夏划水辅助,佛... 第9分钟精通!宁夏划水辅助,佛手大菠萝13道挂哪里,专业教程(有挂神器)-哔哩哔哩;1、点击下载安装...
教程书外挂!智星德州可以透视吗... 教程书外挂!智星德州可以透视吗,we poker游戏下,新2026教程(有挂秘籍)-哔哩哔哩>>您好...
6分钟发现!八闽掌上辅助软件(... 6分钟发现!八闽掌上辅助软件(外挂)原来真的有挂平台(推荐开挂辅助器);八闽掌上辅助软件AI智能教程...
第4分钟带你科普!衢州都莱辅助... 第4分钟带你科普!衢州都莱辅助器免费,丽水都莱脚本辅助,专业教程(有挂详细)-哔哩哔哩 【无需打开直...
第九分钟开挂!wepoker透... 第九分钟开挂!wepoker透视有没有,wepoker免费脚本咨询,2026教程(有挂攻略)-哔哩哔...
法门外挂!hhpoker辅助器... hhpoker辅助器视频 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大理...
2分钟了解!黑科技透视工具(外... 《2分钟了解!黑科技透视工具(外挂)原来真的是有挂脚本(了解开挂软件)》 黑科技透视工具软件透视开挂...
6分钟带你发现!功夫川辅助,j... 大家好,今天小编来为大家解答jj斗地主麻将外g挂这个问题咨询软件客服可以免费测试直接加微信(1367...
第1分钟掌握!wepoker私... 第1分钟掌握!wepoker私人局俱乐部,wepoker如何设置透视,2026新版(有挂功能)-哔哩...
手段外挂!wepoker养号规... 手段外挂!wepoker养号规律,uupoker透视,必胜教程(有人有挂)-哔哩哔哩;打开点击测试直...