这篇文章主要讲解了“ubuntu与centos中怎么更换ip”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“ubuntu与centos中怎么更换ip”吧!
代码一
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”的内容了,经过本文的学习后,相信大家对ubuntu与centos中怎么更换ip这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!