2 Star 6 Fork 5

吉客固件(dugiware)/dugitools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
015.setup_staticnet_ip.nif.sh 2.40 KB
一键复制 编辑 原始数据 按行查看 历史
大吉客 提交于 2024-08-28 16:05 . 1.在015中新增metric选项
#!/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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/dugiware/dugitools.git
[email protected]:dugiware/dugitools.git
dugiware
dugitools
dugitools
master

搜索帮助