代码拉取完成,页面将自动刷新
#!/bin/bash
#-------------------------------------------------
#颜色函数
sdone() { (echo -e "\033[32;1m$*\033[0m";) }
sinfo() { (echo -e "\033[34;1m$*\033[0m";) }
swarn() { (echo -e "\033[33;1m$*\033[0m";) }
serro() { (echo -e "\033[31;1m$*\033[0m";) }
snote() { (echo -e "\033[35;1m$*\033[0m";) }
sshow() { (echo -e "\033[36;1m$*\033[0m";) }
#-------------------------------------------------
dstip=$1
dstnif=$2
dstmtc=$3
if [ -z "$dstip" -o -z "$dstnif" ]; then
serro "Please input: $0 [ip] [ifname] <metric>"
exit 1
fi
if [ -z "$dstmc" ]; then
export dstmc=150
fi
sudo bash -c "echo source-directory /etc/network/interfaces.d > /etc/network/interfaces"
sudo bash -c "mkdir -p /etc/network/interfaces.d > /dev/null 2>&1"
sudo bash -c "rm -rf /etc/network/interfaces.d/* > /dev/null 2>&1"
netno=0
sshow "Config static ip GO"
netif=$(ls /sys/class/net/)
export ret=0
echo "dstip:$dstip"
echo "dstnif:$dstnif"
for afile in $netif
do
sshow "check $afile ..."
if [ "xlo" == "x$afile" ]; then
sshow "config lo ..."
sudo bash -c "echo 'auto $afile' > /etc/network/interfaces.d/${netno}_setup_$afile"
sudo bash -c "echo 'iface $afile inet loopback' >> /etc/network/interfaces.d/${netno}_setup_$afile"
else
echo "check x$afile == x$dstnif ?"
if [ "x$afile" == "x$dstnif" ]; then
sdone "find nif: $afile "
sudo bash -c "echo 'auto $afile' > /etc/network/interfaces.d/${netno}_setup_$afile"
sudo bash -c "echo 'iface $afile inet static' >> /etc/network/interfaces.d/${netno}_setup_$afile"
sudo bash -c "echo 'metric $dstmc' >> /etc/network/interfaces.d/${netno}_setup_$afile"
sudo bash -c "echo 'address $dstip' >> /etc/network/interfaces.d/${netno}_setup_$afile"
sudo bash -c "echo 'netmask 255.255.255.0' >> /etc/network/interfaces.d/${netno}_setup_$afile"
sudo bash -c "echo 'gateway 192.168.1.1' >> /etc/network/interfaces.d/${netno}_setup_$afile"
#223/Aali,119/TengXun,180/Baidu
sudo bash -c "echo 'dns-nameservers 223.5.5.5 119.29.29.29 180.76.76.76'>> /etc/network/interfaces.d/${netno}_setup_$afile"
echo "cat /etc/network/interfaces.d/${netno}_setup_$afile"
cat /etc/network/interfaces.d/${netno}_setup_$afile
export ret=1
break
fi
fi
let netno=netno+1
done
if [ "x$ret" == "x1" ]; then
echo "sudo /etc/init.d/networking restart&"
sudo /etc/init.d/networking restart&
sdone DONE
else
serro "find nif: $afile ERROR]"
fi
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。