ubuntu设置代理服务器

发布于:2025-02-10 ⋅ 阅读:(36) ⋅ 点赞:(0)

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: active

To                         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

网站公告

今日签到

点亮在社区的每一天
去签到