zoukankan      html  css  js  c++  java
  • 【树莓派】Linux自动配置IP

    由于需要配置多台树莓派设备,但需要将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

    具体

  • 相关阅读:
    [NOIP2011提高组]聪明的质监员
    NOIP 2010 关押罪犯
    题目:埃及分数
    用scanf输入long long 型的数
    poj 1014 Dividing
    Cactus
    SQLite数据库的增删改查代码
    UltraGrid常用方法属性代码
    维护数据表常用SQL语句
    C#备份收藏夹代码
  • 原文地址:https://www.cnblogs.com/haochuang/p/6340746.html
Copyright © 2011-2022 走看看