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、测试:

相关内容

热门资讯

一分钟了解!wepoker底牌... 一分钟了解!wepoker底牌透视脚本(透视)外挂透视辅助一(竟然是真的有挂);1、wepoker底...
一分钟教你!中至余干有挂吗,广... 一分钟教你!中至余干有挂吗,广西老友辅助(详细辅助攻略教程)中至余干有挂吗辅助器中分为三种模型:中至...
教程攻略!爱来510k辅助器,... 教程攻略!爱来510k辅助器,福建兄弟十三水辅助工具(详细辅助可靠技巧)您好,福建兄弟十三水辅助工具...
第4分钟了解!哈糖大菠萝破解器... 第4分钟了解!哈糖大菠萝破解器(透视)外挂透视辅助第4(都是是有挂)1、哈糖大菠萝破解器ai辅助优化...
十分钟了解!wepoker高级... 十分钟了解!wepoker高级辅助(透视)外挂透视辅助十(确实有挂)1、wepoker高级辅助系统规...
实测揭晓!陕麻圈脚本辅助,闲逸... 实测揭晓!陕麻圈脚本辅助,闲逸辅助app下载(详细辅助透明挂教程)是一款可以让一直输的玩家,快速成为...
终于清楚!潮汕汇辅助透视,创思... 终于清楚!潮汕汇辅助透视,创思维透视下载链接(详细辅助透视教程)1、很好的工具软件,可以解锁游戏的创...
6分钟了解!wepoker黑侠... 6分钟了解!wepoker黑侠破解(透视)外挂透视辅助6(好像存在有挂)1)wepoker黑侠破解辅...
2分钟细说!能否雀神挂件怎么安... 2分钟细说!能否雀神挂件怎么安装,决战卡五星辅助器下载(详细辅助wpk教程)决战卡五星辅助器下载辅助...
六分钟了解!wepoker透视... 六分钟了解!wepoker透视功能下载(透视)外挂透视辅助六(好像存在有挂)1、用户打开应用后不用登...