Script for automatically modifying the nic name shell in CentOS 7

Source: Internet
Author: User
Tags centos


Code directly!

#! /Bin/sh
 
[-F/etc/init. d/functions] &./etc/init. d/functions
### Modify the Nic configuration file name
Function net (){
B0 =-1
Cat/proc/net/dev | grep ':' | grep-v 'Lo' | cut-d:-f1 | sort>/tmp/net_name.txt
Do
C0 = $ line
B0 = 'expr $ b0 + 1'
Mv/etc/sysconfig/network-scripts/ifcfg-$ c0/etc/sysconfig/network-scripts/ifcfg-eth $ b0
# Change the Nic mode to static
Sed-I's/dhcp/static/g'/etc/sysconfig/network-scripts/ifcfg-eth $ b0
# Delete a row containing IPV6
Sed-I '/IPV6/D'/etc/sysconfig/network-scripts/ifcfg-eth $ b0
# Change the Nic DEVICE to eth.
Sed-I's/'$ c0'/eth '$ b0'/g'/etc/sysconfig/network-scripts/ifcfg-eth $ b0
Done </tmp/net_name.txt
}
### Reconfigure grub and update the kernel
Function grub (){
Sed-I's/crashkernel = auto rhgb quiet/crashkernel = auto net. ifnames = 0 biosdevname = 0 rhgb quiet/g'/etc/default/grub
Grub2-mkconfig-o/boot/grub2/grub. cfg
}
 
### Modifying the naming rules for Nic creation
Function rules (){
B0 =-1
/Sbin/lspci | awk '/net/|/less/{print $1}' | sort | while read line
Do
C0 = $ line
B0 = 'expr $ b0 + 1'
Echo 'action = "add", SUBSYSTEM = "net", BUS = "pci", ID = "0000: '$ c0 '", NAME = "eth '$ b0'"'>/etc/udev/rules. d/70-persistent-net.rules
Done
}
Net
Grub
Rules

The above is a shell code that can quickly modify the name of the NIC. I hope the article will help you.

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.