ubuntu 와 centos 에서 ip 의 셸 코드 를 바 꿉 니 다.

2090 단어 교환 하 다
코드 1 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
코드 2 ubuntu 는 IP 의 셸 코드 를 바 꾸 었 습 니 다.자신 이 쓴 것 은 비교적 졸렬 합 니 다.지적 해 주 십시오

#! /bin/sh

echo "Use gateway at 192.168.0.1 (Y) or 192.168.1.1 (N)
or detail set (O)
Please 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

좋은 웹페이지 즐겨찾기