主页 > 知识库 > ubuntu与centos中更换ip的shell代码

ubuntu与centos中更换ip的shell代码

热门标签:AI电销 Linux服务器 地方门户网站 网站排名优化 服务外包 百度竞价排名 呼叫中心市场需求 铁路电话系统

代码一
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

您可能感兴趣的文章:
  • Ubuntu16.04 静态IP地址设置(NAT方式)
  • 详解ubuntu14.04如何设置静态IP的方法
  • ubuntu 设置静态IP的实现方法
  • 基于Ubuntu 16.04设置固定IP的方法教程

标签:兰州 湘潭 铜川 湖南 衡水 崇左 仙桃 黄山

巨人网络通讯声明:本文标题《ubuntu与centos中更换ip的shell代码》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266