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

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

转载

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

https://blog.csdn.net/weixin_44455388/article/details/106299191

背景

首先有两台服务器183和184,其中184无外网,183有外网。现在184服务器是无法访问外网的,需要使用代理的方法让184通过有外网的183访问外网。

该操作一共可以分为两个部分:一、配置184代理 二、在服务器183上安装代理程序。

配置184代理

直接配置环境变量即可,可以在/etc/profile下配置: 在etc/profile中添加以下内容:

#IP为要连接的代理服务器183,端口是要代理的端口,如下的意思该服务器要通过192.168.1.183服务器的端口19191的代理来访问外网

export http_proxy=http://192.168.1.183:19191

#如果要设置https代理,应该添加如下配置,暂未尝试过

#export https_proxy=http://192.168.1.183:19191

#设置不代理的IP或者网址,如下配置,这些请求不会被代理,不支持模糊匹配

export no_proxy="127.0.0.1, localhost, 192.168.1.184,192.168.1.183"

然后source /etc/priofile,再使用指令echo $http_proxy,如果能打印出相关代理信息说明操作成功。

source /etc/profile

echo $http_proxy

[root@cdh02 etc] echo $http_proxy

http://192.168.1.183:19191

在服务器183上安装代理程序

使用squid

#安装squid,这里采用yum的安装方式

[root@cdh01 ~] yum install -y squid

#cd到配置文件目录下

[root@cdh01 ~] cd /etc/squid/

#备份原始配置文件

[root@cdh01 ~] cp squid.conf squid.conf_bak

#修改配置文件

[root@cdh01 squid]# vi squid.conf

squid.conf配置文件修改内容如下:

#将http_access deny all注释修改为http_access allow all

#http_access deny all

http_access allow all

# 修改端口为代理的端口

http_port 19191

启动squid:

#检查语法是否错误

[root@cdh01 squid] squid -k parse

#初始化缓存空间

[root@cdh01 squid] squid -z

[root@cdh01 squid] 2018/12/05 13:58:56 kid1| Set Current Directory to /var/spool/squid

2018/12/05 13:58:56 kid1| Creating missing swap directories

2018/12/13:58:56 kid1| No cache_dir stores are configured.

#启动squid

[root@cdh01 squid] service squid start

Redirecting to /bin/systemctl start squid.service

#检查端口是否开启成功

[root@cdh01 squid]# netstat -an | grep 19191

tcp6 0 0 :::10991 :::* LISTEN

测试,使用wget baidu.com或curl www.baidu.com 测试内网服务器能否访问外网

[root@cdh01 ~] wget baidu.com

--2018-12-05 14:07:48-- http://baidu.com/

Connecting to 172.19.58.201:10991... connected.

Proxy request sent, awaiting response... 200 OK

Length: 81 [text/html]

Saving to: ‘index.html.1’

100%[=================================================================================================================================>] 81 --.-K/s in 0s

2018-12-05 14:07:48 (20.7 MB/s) - ‘index.html.1’ saved [81/81]

你可能也喜欢

办个联通电话卡需要多少钱?
s365国网公司健步走app

办个联通电话卡需要多少钱?

📅 07-02 👀 5322
[世界杯]1/4决赛:克罗地亚VS巴西
亚洲365bet体育

[世界杯]1/4决赛:克罗地亚VS巴西

📅 06-29 👀 3674
《阴阳师》中石锤怪力的最佳刷怪地点(探索哪个副本有更多的石锤怪力)
快手一快币等于多少人民币?
亚洲365bet体育

快手一快币等于多少人民币?

📅 07-10 👀 2795
打印机打印重影是什么原因? 打印机打重影原因及解决方法
雅诗兰黛口红怎么样
365bet线上攻略

雅诗兰黛口红怎么样

📅 06-29 👀 4135