• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ubuntu与centos中更换ip的shell代码

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
awk中查看包含某两列字符的用法发布时间:2022-02-11
下一篇:
防止ARP攻击的shell代码发布时间:2022-02-11
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap