Ubuntu Server批量ping选择最快源

在虚拟机上操作shell实在不方便,索性把虚拟机做成服务器,用putty连上去玩...学了一下基础的Linux脚本编程,正好拿来检测最快源,备份一下方法。

之前我在Ubuntu Server下用 sudo passwd root 启用了 root 用户,如果你没有启用,记得在命令前加"sudo"。

1、备份源列表文件 cp /etc/apt/sources.list /etc/apt/sources.list.bak

2、用vim打开源列表文件 vim sources.list

3、按下Esc,然后全选并删除(ggdG),把新的源粘贴上去,保存退出(:wq)。我挨个ping了一下,觉得下面这2个最适合我,保存记录一下。"intrepid"是8.04的代号,如果是9.04的话改成"jaunty"就行了。

deb intrepid main multiverse restricted universe
deb intrepid-backports main multiverse restricted universe
deb intrepid-proposed main multiverse restricted universe
deb intrepid-security main multiverse restricted universe
deb intrepid-updates main multiverse restricted universe
deb-src intrepid main multiverse restricted universe
deb-src intrepid-backports main multiverse restricted universe
deb-src intrepid-proposed main multiverse restricted universe
deb-src intrepid-security main multiverse restricted universe
deb-src intrepid-updates main multiverse restricted universe

deb intrepid main restricted universe multiverse
deb intrepid-security main restricted universe multiverse
deb intrepid-updates main restricted universe multiverse
deb intrepid-backports main restricted universe multiverse
deb intrepid-proposed main restricted universe multiverse
deb-src intrepid main restricted universe multiverse
deb-src intrepid-security main restricted universe multiverse
deb-src intrepid-updates main restricted universe multiverse
deb-src intrepid-backports main restricted universe multiverse
deb-src intrepid-proposed main restricted universe multiverse

5、更新一下源 apt-get update

6、更新一下已安装的软件包 apt-get upgrade ,当然如果你想更新整个系统到最新发行版也可以 apt-get dist-upgrade

唔,为了方便以后测试源速度,干脆写一个脚本批量检测好了。

vim ping.sh 新建一个文件,写入以下脚本并保存。

#!/bin/sh
for ip in `cat testlist`
do
 ping -c 5 -q $ip;
done
新建一个testlist文件保存源域名 vim testlist

nz.archive.ubuntu.com
archive.ubuntu.com
mirrors.163.com
cn.archive.ubuntu.com
mirror.lupaworld.com
ubuntu.realss.cn
ubuntu.uestc.edu.cn

ftp.sjtu.edu.cn
debian.ustc.edu.cn
ubuntu.csie.ntu.edu.tw
mirror.rootguide.org
tw.archive.ubuntu.com

这里要先 chmod 755 ping.sh 给它执行权限,然后运行 ./ping.sh 即可,结果会显示在屏幕上。为了简单我给ping命令加了 -q 参数只显示最后的统计结果,连续 ping 5次。

linux

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wyfzyy.html