IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    服务器使用旁路由上网

    logic发表于 2023-09-30 05:44:00
    love 0
    AI摘要:在部署服务时,发现使用git clone项目速度太慢。尝试过使用软路由加速GitHub访问,但不稳定且影响其他设备。最终选择了旁路由方案。旁路由部署有两种方式,一是将主路由的网关设置为旁路由的IP,二是在需要通过旁路由上网的设备中设置网关为旁路由。作者使用了R2S旁路由,刷入稳定的openwrt镜像后设置好加速服务即可。在Debian服务器上,需要将网络联网的配置文件`/etc/network/interfaces`中的DHCP设置改为静态IP地址,并将网关设置为旁路由的IP。修改配置文件后重启网络服务即可。

    Powered by AISummary.

    在服务器上部署服务时,发现 git clone项目时速度实在是太慢了,尽管网上有很多github镜像网站或者加速站,但用起来还是很麻烦。

    以前折腾软路由,曾经试过用它作为主路由加速GitHub访问,但是加速服务不是很稳定,会影响到家里其他上网设备;直接在debian服务器上部署加速服务的话,一是没有直观的管理页面,二是我技术不精,看不懂网上的部署教程,配置了半天也没能搞定;最后还是选择了旁路由这个保险的方案。

    旁路由部署有两种方式:一是在主路由中将网关设置为旁路由的IP,局域网下所有设备都由旁路由分配IP,这样的话,旁路由出问题,局域网下的上网设备都会无法联网;二是主路由不做任何设置,而是在需要通过旁路由上网的设备中设置网关为旁路由,这样旁路由出问题的话,其他上网设备仍可正常联网。

    旁路由我用的是前两年退役的R2S,从恩山论坛随便找了个稳定的openwrt镜像刷入,上电设置好加速服务即可

    进入主路由,查看旁路由和服务器的IP
    旁路由IP:192.168.31.99
    服务器IP:192.168.31.156

    Debian设置网络联网的配置文件是 /etc/network/interfaces
    该文件原本的内容是:

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    source /etc/network/interfaces.d/*
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    allow-hotplug enp1s0
    iface enp1s0 inet dhcp

    lo那两行是设置回环地址,这部分不用改,enp1s0那两行则是以太网口的设置
    allow-hotplug enp1s0意思是允许该网口网线热插拔,也不用管
    iface enp1s0 inet dhcp意思是该网口联网自动分配IP地址,由于要通过旁路由上网,旁路由并不提供DHCP服务,所以要将服务器设为静态IP地址,这一行需要注释掉,改为以下的内容:

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    source /etc/network/interfaces.d/*
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    allow-hotplug enp1s0
    #iface enp1s0 inet dhcp
    
    #auto enp1s0
    iface enp1s0 inet static
    address 192.168.31.156
    netmask 255.255.255.0
    gateway 192.168.31.99

    enp1s0是网口名称,static是分配指定的静态IP,address是指定的静态IP地址,netmask是掩码,通常情况都是设为255.255.255.0,gateway即是网关IP地址,设为旁路由的IP即可,设置好该配置文件后,执行 sudo systemctl restart networking重启网络服务即可



沪ICP备19023445号-2号
友情链接