admin 管理员组

文章数量: 1086864

android 静态ip shell,用shell实现将动态ip修改成静态ip,静态ip修改成其它静态ip

(1) 将动态ip修改成静态ip的思路shell

① 修改ip以前,先备份ifcfg-eth0文件bash

②  进入网卡配置目录  /etc/sysconfig/network-scripts/ifcfg-eth0ide

③  修改BOOTPROTO=staticspa

④  修改ONBOOT=yesrest

⑤  配置静态ip地址 IPADDRip

⑥  配置DNS  NETMASKit

⑦  配置网关  GATEWAYtable

⑧  重启网卡验证配置,验证配置结果   service   network  restartclass

(2) 将静态ip修改成其它静态ip的思路sed

☆  先判断是不是静态ip   grep "dhcp" /etc/sysconfig/network-scripts/ifcfg-eth0/

if[$?  -ne   0]; then

sed -i `s/^IPADDR/#IPADDR/g` ifcfg-eth0

read  -p   "please Enter  ip:"IPADDR

echo "IPADDR="$IPADDR">>/etc/sysconfig/network-scripts/

fi

☆  重启网卡验证配置结果   service network  restart

代码示例:

#!/bin/bash

#2017年12月17日19:34:40

#by author daqi

#change ip  shell

NET_FILE="/etc/sysconfig/network-scripts"

NET_DIR="ifcfg-eth0"

cd $NET_FILE/

#change ip static for static:

grep "dhcp" $NET_DIR

if [ $? -ne 0 ];then

sed -i s/^IPADDR/#IPADDR/g $NET_DIR

read -p "Please enter ip Address,example 192.168.0.11 ip:"  IPADDR

echo "IPADDR=$IPADDR">>$NET_DIR

echo "NETMASK=255.255.255.0">>$NET_DIR

echo "GATEWAY=192.168.2.254">>$NET_DIR

service network restart

else

#change ip dhcp for static

sed -i s/dhcp/static/g $NET_DIR

sed -i s/ONBOOT=no/ONBOOT=yes/g $NET_DIR

read -p "Please enter ip Address,example 192.168.0.11 ip:"   IPADDR

cat>>$NET_FILE/$NET_DIR <

IPADDR=$IPADDR

NETMASK=255.255.255.0

GATEWAY=192.168.2.1

EOF

service network restart

fi

本文标签: android 静态ip shell 用shell实现将动态ip修改成静态ip,静态ip修改成其它静态ip