Ubuntu 代理设置与取消

终端命令行;

设置代理:

export http_proxy=http://172.16.2.16:3199
export https_proxy=http://172.16.2.16:3199

取消代理设置:

unset http_proxy
unset https_proxy

演示:

book@ubuntu:~/pt1416/02-hellogolang/grpcTest/client$ go run client.go 
2022/03/30 17:09:01 err where calling sayHello:rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing failed to do connect handshake, response: \"HTTP/1.1 403 Forbidden\\r\\nContent-Length: 333\\r\\nCache-Control: no-cache\\r\\nConnection: keep-alive\\r\\nContent-Type: text/html\\r\\nPragma: no-cache\\r\\n\\r\\n<!DOCTYPE html>\\n<html>\\n\\t<head> <title>COW Proxy</title> </head>\\n\\t<body>\\n\\t\\t<h1>[Error] Forbidden tunnel port</h1>\\n\\t\\t<p>HTTP Request <strong>CONNECT :9000</strong></p> <p>Please contact proxy admin.</p>\\n\\t\\t<hr />\\n\\t\\tGenerated by <i>COW 0.9.8</i> <br />\\n\\t\\tHost <i>it-cowproxy-master</i> <br />\\n\\t\\tWed Mar 30 17:09:01 2022\\n\\t</body>\\n</html>\\n\""
exit status 1
book@ubuntu:~/pt1416/02-hellogolang/grpcTest/client$ unset https_proxy
book@ubuntu:~/pt1416/02-hellogolang/grpcTest/client$ go run client.go 
2022/03/30 17:09:54 err where calling sayHello:rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing failed to do connect handshake, response: \"HTTP/1.1 403 Forbidden\\r\\nContent-Length: 333\\r\\nCache-Control: no-cache\\r\\nConnection: keep-alive\\r\\nContent-Type: text/html\\r\\nPragma: no-cache\\r\\n\\r\\n<!DOCTYPE html>\\n<html>\\n\\t<head> <title>COW Proxy</title> </head>\\n\\t<body>\\n\\t\\t<h1>[Error] Forbidden tunnel port</h1>\\n\\t\\t<p>HTTP Request <strong>CONNECT :9000</strong></p> <p>Please contact proxy admin.</p>\\n\\t\\t<hr />\\n\\t\\tGenerated by <i>COW 0.9.8</i> <br />\\n\\t\\tHost <i>it-cowproxy-master</i> <br />\\n\\t\\tWed Mar 30 17:09:54 2022\\n\\t</body>\\n</html>\\n\""
exit status 1
book@ubuntu:~/pt1416/02-hellogolang/grpcTest/client$ unset http_proxy
book@ubuntu:~/pt1416/02-hellogolang/grpcTest/client$ go run client.go 
2022/03/30 17:10:00 respond from Server :Hello from the server!
book@ubuntu:~/pt1416/02-hellogolang/grpcTest/client$ 
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu设置代理转发有多种方式,以下是其中两种常见的方法: 1. 使用 SSH 动态端口转发 如果你有一台可以访问互联网的服务器,并且该服务器可以通过 SSH 访问到需要代理的目标主机,那么可以使用 SSH 动态端口转发来实现代理转发。具体步骤如下: 1. 在本地 Ubuntu 主机上安装 SSH 客户端,如果没有安装可以使用以下命令安装: ``` sudo apt update sudo apt install openssh-client ``` 2. 在远程服务器上安装 SSH 服务端,如果没有安装可以使用以下命令安装: ``` sudo apt update sudo apt install openssh-server ``` 3. 在本地主机上通过 SSH 连接到远程服务器,并启动动态端口转发: ``` ssh -D 1080 user@remote_server ``` 其中 `user` 是远程服务器的用户名,`remote_server` 是远程服务器的 IP 地址或域名,`1080` 是本地主机上的代理端口号,你可以根据需要修改。 4. 在本地主机上设置代理服务器,将代理服务器地址设置为 `127.0.0.1`,端口号设置为 `1080`,具体方法取决于使用的应用程序。 2. 使用 Privoxy 另一种常见的方式是使用 Privoxy,它是一个可以将 HTTP 和 HTTPS 流量转发到代理服务器的代理转发工具。具体步骤如下: 1. 在本地 Ubuntu 主机上安装 Privoxy: ``` sudo apt update sudo apt install privoxy ``` 2. 修改 Privoxy 配置文件 `/etc/privoxy/config`,将以下两行取消注释并修改: ``` listen-address 127.0.0.1:8118 forward-socks5t / 127.0.0.1:1080 . ``` 其中 `127.0.0.1:8118` 是本地主机上的代理端口号,`127.0.0.1:1080` 是代理服务器的地址和端口号,你可以根据需要修改。 3. 启动 Privoxy 服务: ``` sudo service privoxy start ``` 4. 在本地主机上设置代理服务器,将代理服务器地址设置为 `127.0.0.1`,端口号设置为 `8118`,具体方法取决于使用的应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值