主頁 > 知識(shí)庫 > ubuntu與centos中更換ip的shell代碼

ubuntu與centos中更換ip的shell代碼

熱門標(biāo)簽:AI電銷 Linux服務(wù)器 地方門戶網(wǎng)站 網(wǎng)站排名優(yōu)化 服務(wù)外包 百度競價(jià)排名 呼叫中心市場需求 鐵路電話系統(tǒng)

代碼一
ubuntu與centos

復(fù)制代碼 代碼如下:

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代碼,自己寫的,比較拙,請(qǐng)指正
復(fù)制代碼 代碼如下:

#! /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

您可能感興趣的文章:
  • Ubuntu16.04 靜態(tài)IP地址設(shè)置(NAT方式)
  • 詳解ubuntu14.04如何設(shè)置靜態(tài)IP的方法
  • ubuntu 設(shè)置靜態(tài)IP的實(shí)現(xiàn)方法
  • 基于Ubuntu 16.04設(shè)置固定IP的方法教程

標(biāo)簽:蘭州 湘潭 銅川 湖南 衡水 崇左 仙桃 黃山

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ubuntu與centos中更換ip的shell代碼》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266