由于需要配置多台树莓派设备,但需要将IP配置为静态IP,而一台一台手动执行比较慢,所以写了一份脚本,sudo 执行即可。
将下面内容复制在家目录下,命名为auto.sh
然后执行 sudo sh auto.sh 即可;
#!/bin/sh sIP=`sudo ifconfig eth1 | grep inet | awk 'NR==1{print $2}'| awk -F ':' '{print $2}'`
sBcast=`sudo ifconfig eth1 | grep inet | awk 'NR==1{print $3}'| awk -F ':' '{print $2}'`
sMask=`sudo ifconfig eth1 | grep inet | awk 'NR==1{print $4}'| awk -F ':' '{print $2}'`
sGWP=`sudo ifconfig eth1 | grep inet | awk 'NR==1{print $2}'| awk -F ':' '{print $2}' | cut -d . -f -`
sDomain1="223.5.5.5"
sDomain2="223.6.6.6"
sDomain3="218.30.19.40"
sDomain4="61.134.1.4" # sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.default.bak
echo "IP="$sIP"\n"
echo "sBcast="$sBcast"\n"
echo "sMask="$sMask"\n"
echo "sMask="$sMask"\n"
echo "sMask="$sMask"\n"
echo "sDomain1="$sDomain1"\n"
echo "sDomain2="$sDomain2"\n"
echo "sDomain3="$sDomain3"\n"
echo "sDomain4="$sDomain4"\n" sudo sed -i '$a interface eth1\n static ip_address='$sIP'/24\n static routers='$sGWP'.1\n #static domain_name_servers='$sDomain1' '$sDomain2'\n static domain_name_servers='$sDomain3' '$sDomain4'' /etc/dhcpcd.conf
# sudo sed -i '$a # static domain_name_servers='$sDomain3'' /etc/dhcpcd.conf
sudo sed -i '/interface eth1/i\\' /etc/dhcpcd.conf
具体