Linux互联网主机代理内网主机访问互联网

互联网主机

1、安装squid

squid代理内网主机访问互联网

yum -y install squid
cat /etc/squid/squid.conf

#
# Recommended minimum configuration:
#

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 192.66.1.0/24  # RFC1918 possible internal network      内网地址
acl localnet src 192.66.0.0/24  # RFC1918 possible internal network
acl localnet src 192.66.255.120 # RFC1918 possible internal network
acl localnet src 192.66.255.130 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT

#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
#http_access deny all                                             #注释
http_access allow all                                             #添加

# Squid normally listens to port 3128
http_port 3128

# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256

# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid

#
# Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320

2、重启服务

systemctl restart squid
netstat -an | grep 3128

内网主机

1、配置环境变量

cat ~/.profile
# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n 2> /dev/null || true


alias proxy='export http_proxy=http://192.67.0.67:3128;export https_proxy=http://192.67.0.67:3128'
alias unproxy='unset http_proxy https_proxy'
# IP为要连接的代理服务器B,端口是要代理的端口,如下的意思该服务器要通过172.20.100.201服务器的端口8898的代理来访问外网
注意:
centos修改 vi ~/.bash_profile
ubuntu修改 vi   ~/.profile

2、配置代理

source ~/.profile
proxy
echo $http_proxy

3、配置apt源

cp /etc/apt/sources.list /etc/apt/sources.list-bak
cat > /etc/apt/sources.list << EOF
deb http://192.168.0.201/ubuntu/ focal main restricted universe multiverse
deb-src http://192.168.0.201/ubuntu/ focal main restricted universe multiverse

deb http://192.168.0.201/ubuntu/ focal-security main restricted universe multiverse
deb-src http://192.168.0.201/ubuntu/ focal-security main restricted universe multiverse

deb http://192.168.0.201/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://192.168.0.201/ubuntu/ focal-updates main restricted universe multiverse

deb http://192.168.0.201/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://192.168.0.201/ubuntu/ focal-backports main restricted universe multiverse
EOF

apt update

参考

使用squid 解决内网服务器通过设置代理访问外网
Ubuntu 20.04 与22.04 内网apt源搭建

posted @   *一炁化三清*  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
历史上的今天:
2024-01-16 Linux-搭建内网yum源
点击右上角即可分享
微信分享提示