Automatically modify the NIC ip address and mask script in Linux

Source: Internet
Author: User
Automatically modify the NIC ip address and mask script in Linux-Linux Enterprise Application-Linux server application information. For more information, see the following. For more information, see.

After reading some questions from the Internet, I wrote a simple script, which is not strictly enough. For example, I can only modify the e'h0 and cannot modify eth1, you can also add it to the script by yourself. This small shell only provides some help. I am also a beginner in shell. Please give me more instructions.

Change the ip address, IP_MODI = ××××, and mask MASK_MODI = ××××.

#! /Bin/sh
#
PROC =/bin/sed
FILE_PATH =/etc/sysconfig/network-scripts/ifcfg-eth0
IP_PRIMAL = 'grep-I ipaddr $ FILE_PATH | awk-F "=" '{printf $2 }''
MASK_PRIMAL = 'grep-I netmask $ FILE_PATH | awk-F "=" '{printf $2 }''
IP_MODI = 192.168.0.160
MASK_MODI = 255.255.255.0
$ PROC-e "s/$ IP_PRIMAL/$ IP_MODI/g"-e "s/$ MASK_PRIMAL/$ MASK_MODI/g" $ FILE_PATH> ifcfg-eth0.bak
Cp-pf./ifcfg-eth0.bak $ FILE_PATH
Cat $ FILE_PATH
# Restart network command
#/Etc/init. d/network restart>/dev/null 2> & 1
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.