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(未測(cè)試):
#!/bin/bash
echo "ipaddr:"
read line
echo $line
sed "s/IPADDR.*$/IPADDR=${line}/g" /etc/sysconfig/network-scipts/ifcfg-eth0
代碼二
ubuntu更改IP的shell代碼,自己寫(xiě)的,比較拙,請(qǐng)指正
#! /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日志訪問(wèn)次數(shù)最多及最耗時(shí)的頁(yè)面(慢查詢(xún))
下面是我在做優(yōu)化時(shí)候,經(jīng)常用到的一段shell 腳本。 這個(gè)也可以算是,統(tǒng)計(jì)web頁(yè)面的slowpage 慢訪問(wèn)頁(yè)面,象mysql slowquery2013-11-11如何利用 tee 命令調(diào)試shell腳本中的管道
在編寫(xiě)shell腳本時(shí),調(diào)試是個(gè)比較麻煩的事,特別是涉及到多層管道命令的時(shí)候,會(huì)產(chǎn)生多個(gè)中間結(jié)果,tee命令的作用是從標(biāo)準(zhǔn)輸入中讀取數(shù)據(jù)寫(xiě)入標(biāo)準(zhǔn)輸出或文件中,利用它可以從管道中讀取中間結(jié)果并寫(xiě)入本地臨時(shí)文件中,通過(guò)中間結(jié)果可以一步一步的定位到腳本的錯(cuò)誤2021-05-05shell自定義函數(shù)的6個(gè)特點(diǎn)總結(jié)
這篇文章主要介紹了shell自定義函數(shù)的6個(gè)特點(diǎn)總結(jié),也是使用shell自定義函數(shù)的一些注意事項(xiàng)總結(jié),以及小技巧介紹,需要的朋友可以參考下2014-07-07開(kāi)發(fā)者常用及實(shí)用Linux Shell命令備忘錄(小結(jié))
這篇文章主要介紹了開(kāi)發(fā)者常用及實(shí)用Linux Shell命令備忘錄(小結(jié)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11分享一個(gè)實(shí)用的iptables腳本(各種過(guò)濾寫(xiě)法參考)
這篇文章主要介紹了分享一個(gè)實(shí)用的iptables腳本(各種過(guò)濾寫(xiě)法參考),需要的朋友可以參考下2014-04-04