阿里云内网机器通过squids代理上访问外网资源

一、背景

代理服务器A(10.0.1.2)机器有公网地址可正常访问外网
业务服务器B(10.0.1.33)机器无公网地址不能访问外网
代理服务器A((10.0.1.2)和业务服务器B(10.0.1.33)在公一个数据中心(同一个局域网)
需要实现B访问外网通过A代理出去

二、安装

  1. 在代理服务器A(10.0.1.2)机器上安装squid
    yum install openssl squid -y
    然后启动服务
    service squid start

    2、在业务服务器B(10.0.1.33)机器宿主目录中的.bash_profile或者profile添加如下内容

    cat>>/etc/profile<<-EOF
    export http_proxy=http://10.0.1.2:3128
    export https_proxy=http://10.0.1.2:3128
    EOF
    source /etc/profile

    三、测试代理访问外网

    在业务服务器B(10.0.1.33)上随便访问一个网站如www.baidu.com

    [root@k8s-registry ~]# curl -I http://www.baidu.com
    HTTP/1.1 200 OK
    Accept-Ranges: bytes
    Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
    Content-Length: 277
    Content-Type: text/html
    Date: Tue, 31 Jul 2018 08:37:45 GMT
    ETag: "575e1f8a-115"
    Last-Modified: Mon, 13 Jun 2016 02:50:50 GMT
    Pragma: no-cache
    Server: bfe/1.0.8.18
    X-Cache: MISS from k8s-master
    X-Cache-Lookup: MISS from k8s-master:3128
    Via: 1.1 k8s-master (squid/3.5.20)
    Connection: keep-alive
    [root@k8s-registry ~]# netstat -anlp|grep 3128
    tcp        0      0 10.0.1.33:36674    10.0.1.2:3128     TIME_WAIT   -

    四、至此阿里云内网服务器通过可以访问外网的服务器代理实现访问互联网的功能

猜你喜欢

转载自blog.51cto.com/412166174/2152759