Code A
Ubuntu and CentOS
Copy Code code 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/network-scipts/ifcfg-eth0
Code Two
Ubuntu Change the IP shell code, write it yourself, the more humble, please correct me
Copy Code code 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" 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