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(未测试):
#!/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
上一篇: 想要瓜子脸,,塑造小V脸的方法有哪些
下一篇: 电炖盅可以做出什么美食