Code 1
Ubuntu and centos
Copy codeThe Code is as follows: ubuntu:
#! /Bin/bash
Echo "ipaddr :"
Read line
Echo $ line
Sed "s/address. * $/address =$ {line}/g"/etc/network/interfaces
Centos (not tested ):
#! /Bin/bash
Echo "ipaddr :"
Read line
Echo $ line
Sed "s/IPADDR. * $/IPADDR =$ {line}/g"/etc/sysconfig/net-scipts/ifcfg-eth0
Code 2
Modify the shell code of the IP address in ubuntu. It is self-written. please correct me.Copy codeThe Code is as follows :#! /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