由于需要配置多台树莓派设备,但需要将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 1-3` 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" " echo "sBcast="$sBcast" " echo "sMask="$sMask" " echo "sMask="$sMask" " echo "sMask="$sMask" " echo "sDomain1="$sDomain1" " echo "sDomain2="$sDomain2" " echo "sDomain3="$sDomain3" " echo "sDomain4="$sDomain4" " sudo sed -i '$a interface eth1 static ip_address='$sIP'/24 static routers='$sGWP'.1 #static domain_name_servers='$sDomain1' '$sDomain2' 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
具体