欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 游戏 > ubuntu设置代理服务器

ubuntu设置代理服务器

2025/2/24 13:21:06 来源:https://blog.csdn.net/qq_50003999/article/details/145211047  浏览:    关键词:ubuntu设置代理服务器

Motivation:实验室有很多服务器,每台都只能连校内网,校外网需要手动开启,很麻烦,现在想把其中一台服务器作为代理服务器连外网。
Reference:参考1、参考2

1、设置代理服务器

首先安装Squid库:

sudo apt install squid

然后配置Squid:

#首先备份
sudo cp /etc/squid/squid.conf{,.orginal}

创建需要用到代理服务器的IP list 文件:

/etc/squid/allowed_ips.txt

文件内写入需要用到的服务器ip地址:

192.168.33.1
# All other allowed IPs

然后编辑Squid的config:

sudo vim /etc/squid/squid.conf

按照下面这样改:

# ...
acl allowed_ips  src "/etc/squid/allowed_ips.txt"
# ...
#http_access allow localnet
http_access allow localhost
http_access allow allowed_ips
# And finally deny all other access to this proxy
http_access deny all

重启Squid来使得上述config生效:

sudo systemctl restart squid

2、设置防火墙

首先安装UFW:

sudo apt-get install ufw

然后开启UFW:

sudo ufw enable
sudo ufw allow 'Squid'

然后验证UFW状态:

sudo ufw status
tatus: activeTo                         Action      From
--                         ------      ----
22/tcp                     ALLOW       Anywhere
Squid                      ALLOW       Anywhere
22/tcp (v6)                ALLOW       Anywhere (v6)
Squid (v6)                 ALLOW       Anywhere (v6)

3、其他服务器设置代理

export http_proxy=http://192.168.13.114:3128

不想每次运行这个指令就写到自己的~/.bashrc里面。

4、Problem Shooting

以上步骤完了以后发现服务器远程ssh不上了,但是可以ping通,发现是原本的SSH端口被关闭了,这一部分参考这个:

#先查看对应端口(例如9090)是否开启
lsof -i :9090
#没有开启就开启
sudo apt-get install iptables
#安装完成,开放需要开放的端口,例如开放80端口
iptables -I INPUT -p tcp --dport 80 -j ACCEPT

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词