The shell code _linux shell for the replacement of IP in Ubuntu and CentOS

Source: Internet
Author: User
Tags centos

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.