ubuntu与centos中更换ip的shell代码
代码一
ubuntu与centos
ubuntu:
#!/bin/bash
echo "ipaddr:"
read line
echo $line
sed "s/address.*$/address=${line}/g" /etc/network/interfaces
centos(未测试):
#!/bin/bash
echo "ipaddr:"
read line
echo $line
sed "s/IPADDR.*$/IPADDR=${line}/g" /etc/sysconfig/network-scipts/ifcfg-eth0
代码二
ubuntu更改IP的shell代码,自己写的,比较拙,请指正
#! /bin/sh
echo "Use gateway at 192.168.0.1 (Y) or 192.168.1.1 (N)
or detail set (O)\nPlease choose Y/N/O"
read OP
if [ "$OP" = Y ] || [ "$OP" = y ] ; then
GATEWAY=192.168.0.1
IP=192.168.0.215
elif [ "$OP" = N ] || [ "$OP" = n ] ; then
GATEWAY=192.168.1.1
IP=192.168.1.215
else
echo "Please input the ip:"
read IP
echo "Please input the gateway"
read GATEWAY
fi
echo "auto lo
iface lo inet static
auto eth0
iface eth0 inet static
netmask 255.255.255.0
address $IP
gateway $GATEWAY" > /tmp/interfaces
clear
echo "Init File interfaces Successfully!"
echo "*************************************"
cat /tmp/interfaces
echo "*************************************"
echo "Change the file in /etc/networks/interfaces?(Y/N)"
read OP
if [ "$OP" = Y ] || [ "$OP" = y ] ; then
echo "Set OK!"
cp /tmp/interfaces /etc/network/interfaces
/etc/init.d/networking restart
else
echo "Give up"
fi
rm /tmp/interfaces
echo "Whether change the DNS(/etc/resolv.conf)(Y/N)"
read OP
if [ "$OP" = Y ] || [ "$OP" = y ];then
echo "Input the DNS server IP:"
read IP
echo "Now change the DNS IP"
mv /etc/resolv.conf /etc/resolv.conf.bak
echo "nameserver $IP" >/etc/resolv.conf
echo "Done!"
fi
相关文章
linux shell中单引号、双引号、反引号、反斜杠的区别
shell可以识别4种不同类型的引字符号: 单引号字符' 双引号字符" 反斜杠字符\ 反引号字符`的区别,学习shell编程的朋友可以看下2013-01-01
使用scp获取远程linux服务器上的文件 linux远程拷贝文件
scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,scp传输是加密的,下面看一下详细使用方法吧2014-01-01
linux dev 常见特殊设备介绍与应用(loop,null,zero,full,random)
这篇文章主要介绍了linux dev 常见特殊设备介绍与应用(loop,null,zero,full,random),需要的朋友可以参考下2015-10-10
shell脚本学习指南[三](Arnold Robbins & Nelson H.F. Beebe著)
这篇文章主要介绍了shell脚本学习指南[三](Arnold Robbins & Nelson H.F. Beebe著),需要的朋友可以参考下2014-02-02


最新评论