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
相關(guān)文章
shell腳本分析 nginx日志訪問次數(shù)最多及最耗時的頁面(慢查詢)
下面是我在做優(yōu)化時候,經(jīng)常用到的一段shell 腳本。 這個也可以算是,統(tǒng)計web頁面的slowpage 慢訪問頁面,象mysql slowquery2013-11-11如何利用 tee 命令調(diào)試shell腳本中的管道
在編寫shell腳本時,調(diào)試是個比較麻煩的事,特別是涉及到多層管道命令的時候,會產(chǎn)生多個中間結(jié)果,tee命令的作用是從標(biāo)準(zhǔn)輸入中讀取數(shù)據(jù)寫入標(biāo)準(zhǔn)輸出或文件中,利用它可以從管道中讀取中間結(jié)果并寫入本地臨時文件中,通過中間結(jié)果可以一步一步的定位到腳本的錯誤2021-05-05開發(fā)者常用及實用Linux Shell命令備忘錄(小結(jié))
這篇文章主要介紹了開發(fā)者常用及實用Linux Shell命令備忘錄(小結(jié)),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11