手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >ubuntu与centos中更换ip的shell代码
ubuntu与centos中更换ip的shell代码
摘要:代码一ubuntu与centos复制代码代码如下:ubuntu:#!/bin/bashecho"ipaddr:"readlineecho$l...

代码一

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

【ubuntu与centos中更换ip的shell代码】相关文章:

Ubuntu、Linux Mint一键安装Chrome浏览器的Shell脚本分享

一个监控LINUX目录和文件变化的Shell脚本分享

Linux下一些常用的Shell脚本整理

批量转换目录下文件编码的shell脚本代码

except自动登录的几段代码分享

linux进程监控shell脚本代码

一个简单的转换输出的shell脚本代码

检测网站down掉后自动发信的shell脚本代码

Ubuntu服务器配置apache2.4的限速功能shell脚本分享

分享一个入门级可控多线程shell脚本代码

精品推荐
分类导航