CN104407899A - Method for restoring and starting network card after MAC address is changed under REDHAT operating system - Google Patents
Method for restoring and starting network card after MAC address is changed under REDHAT operating system Download PDFInfo
- Publication number
- CN104407899A CN104407899A CN201410725087.9A CN201410725087A CN104407899A CN 104407899 A CN104407899 A CN 104407899A CN 201410725087 A CN201410725087 A CN 201410725087A CN 104407899 A CN104407899 A CN 104407899A
- Authority
- CN
- China
- Prior art keywords
- network interface
- interface card
- mac address
- operating system
- file
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 21
- 238000013515 script Methods 0.000 claims abstract description 20
- 230000008878 coupling Effects 0.000 claims description 3
- 238000010168 coupling process Methods 0.000 claims description 3
- 238000005859 coupling reaction Methods 0.000 claims description 3
- 238000011084 recovery Methods 0.000 abstract description 6
- 238000013213 extrapolation Methods 0.000 description 5
- 238000005516 engineering process Methods 0.000 description 2
- 241000282326 Felis catus Species 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
Landscapes
- Data Exchanges In Wide-Area Networks (AREA)
- Computer And Data Communications (AREA)
Abstract
The invention discloses a method for restoring and starting a network card after changing an MAC address under a REDHAT operating system. The invention provides the fastest solution, and after the script is compiled, the network card can be successfully started only by one command, so that one-time fault recovery is completed.
Description
Technical field
The present invention relates to field of computer technology, be specifically related to a kind of method changing rear network interface card recovery startup for MAC Address of Network Card under REDHAT operating system.
Background technology
In actual application environment, when the fault such as the machine of delaying, deadlock appears in Linux system server, often need to change server master board and solve problem, or when there is network failure, the extrapolation network interface card of correspondence changed by needs.But replacing mainboard completes, network interface card, after starting the operating system, can find that network interface card service starts unsuccessfully, network is obstructed, so business can not continue, just can not successfully repair a fault at last.This just needs to expend the configuration file that the long period revises network interface card at the scene, for the slip-stick artist being unfamiliar with linux statement, extremely difficult especially.So we will provide solution the most fast, after compile script, only need an order, successfully can start network interface card, complete primary fault and recover.
Linux system can go to read network interface card information after loading trawl performance, then all network card equipments recognized are write this file :/etc/udev/rules.d/70-persistent-net.rules, and do not delete former content, so wherein contain existing content and newly recognize the mac address of network interface card.Such as, change the mainboard of a double netcard in maintenance server process, the mac address of network interface card changes thereupon, 4 network interface card information of new and old two pieces of mainboards will be comprised in this file, what still preserve in another configuration file ifcfg-ethx is original MAC Address simultaneously, so when system starts, due to mac address error, identification network card equipment that can not be correct, causes and starts network interface card failure.
Summary of the invention
The technical problem to be solved in the present invention is: the object of this invention is to provide a kind of under redhat operating system, and after network interface card mac address changes, network interface card recovers the method started
The technical solution adopted in the present invention is:
After changing MAC Address under a kind of REDHAT operating system, network interface card recovers the method started, under redhat operating system, can perform in script by the statement required for instauration net card start-up is integrated in one, wherein contain amendment configuration file, empty temporary file, restart the operations such as system.The time of fault recovery significantly can be reduced by this method.
In order to avoid server network interface card quantity differs, improve the accuracy judged, first need to judge network interface card quantity, coupling corresponding relation that could be correct.
In addition, if the extrapolation net card failure of a station server, only changed an extrapolation network interface card, so still all network interface card files have been modified after having judged, so the present invention is not by the restriction of fault network interface card quantity.
Described shell script mainly revises two files:
Ifcfg-eth [0-9]: [0-9] is general reference.MAC Address in these network card configuration files all will be revised as the MAC of current machine card of surfing Internet.
70-persistent-net.rules is the file that system generates automatically, the network interface card detected when comprising startup, determines network interface card order, can directly empty.
First check startup file/etc/sysconfig/network-scripts/ifup, comparison has been done to the MAC Address in configuration file.Comparison result is inconsistent, then start failure
Described method operation steps is as follows:
1) draw by num=$ (ifconfig-a | grep eth | wc-l) statement the network interface card number that system recognizes, decide to revise corresponding ifcfg-ethx file;
2) current all correct network interface card information is listed by ifconfig – a, and by key word " HWaddr " value MAC Address;
3) first judge whether the configuration file of this network interface card exists, then step 2 by if condition before amendment) in recognize MAC Address and write this file for standby, and add # annotation;
4) draw corresponding relation according to network interface card quantity before, the ifcfg-ethx file that amendment is corresponding, write correct MAC Address;
5) empty 70-persistent-net.rules file, and restart.Just can see network interface card full recovery startup.
Write rear increase and can perform authority: chmod 755 mac.sh;
Perform script: ./mac.sh;
Ifconfig test after wait autoboot completes.
Beneficial effect of the present invention: the invention provides solution the most fast, after compile script, only needs an order, successfully can start network interface card, completes primary fault and recovers.
Accompanying drawing explanation
Fig. 1 is script process flow diagram of the present invention.
Embodiment
Below according to Figure of description, in conjunction with specific embodiments, the present invention is further described:
As shown in Figure 1, after changing MAC Address under a kind of REDHAT operating system, network interface card recovers the method started, under redhat operating system, can perform in script by the statement required for instauration net card start-up is integrated in one, wherein contain amendment configuration file, empty temporary file, restart the operations such as system.The time of fault recovery significantly can be reduced by this method.
In order to avoid server network interface card quantity differs, improve the accuracy judged, first need to judge network interface card quantity, coupling corresponding relation that could be correct.
In addition, if the extrapolation net card failure of a station server, only changed an extrapolation network interface card, so still all network interface card files have been modified after having judged, so the present invention is not by the restriction of fault network interface card quantity.
Described shell script mainly revises two files:
Ifcfg-eth [0-9]: [0-9] is general reference.MAC Address in these network card configuration files all will be revised as the MAC of current machine card of surfing Internet.
70-persistent-net.rules is the file that system generates automatically, the network interface card detected when comprising startup, determines network interface card order, can directly empty.
First check startup file/etc/sysconfig/network-scripts/ifup, comparison has been done to the MAC Address in configuration file.Comparison result is inconsistent, then start failure.
The content of described script, such as script name is: mac.sh
#!/bin/bash
cdate=$(date '+%Y%m%d')
num=$(ifconfig -a | grep eth | wc -l)
for ((n=0;n<${num};n++))
do
j=$((n+1))
if [ -e /etc/sysconfig/network-scripts/ifcfg-eth${n} ] ; then
[ -e ifcfg-eth${n}_${cdate} ] || cp -fa /etc/sysconfig/network-scripts/ifcfg-eth${n} ./ifcfg-eth${n}_${cdate}
cat ifcfg-eth${n}_${cdate} | sed '/^#eth.*$/d' > ifcfg-eth${n}_temp
ifconfig -a | grep "HWaddr" | awk '{print "#"$1" : "$5}' >> ifcfg-eth${n}_temp
newmac=$(ifconfig -a | grep "eth" | sort | awk '{print $5}' | nl -n ln | grep "^${j}" | awk '{print $2}')
sed "s/HWADDR.*$/HWADDR=$newmac/g" ifcfg-eth${n}_temp > ifcfg-eth${n}_vi
cp -fa ifcfg-eth${n}_vi /etc/sysconfig/network-scripts/ifcfg-eth${n} && rm –f ifcfg-eth${n}_temp
else
newmac=$(ifconfig -a | grep "eth" | sort | awk '{print $5}' | nl -n ln | grep "^${j}" | awk '{print $2}')
continue
fi
done
echo > /etc/udev/rules.d/70-persistent-net.rules
reboot
Described method operation steps is as follows:
1) draw by num=$ (ifconfig-a | grep eth | wc-l) statement the network interface card number that system recognizes, decide to revise corresponding ifcfg-ethx file;
2) current all correct network interface card information is listed by ifconfig – a, and by key word " HWaddr " value MAC Address;
3) first judge whether the configuration file of this network interface card exists, then step 2 by if condition before amendment) in recognize MAC Address and write this file for standby, and add # annotation;
4) draw corresponding relation according to network interface card quantity before, the ifcfg-ethx file that amendment is corresponding, write correct MAC Address;
5) empty 70-persistent-net.rules file, and restart.Just can see network interface card full recovery startup.
Write rear increase and can perform authority: chmod 755 mac.sh;
Perform script: ./mac.sh;
Ifconfig test after wait autoboot completes.
Claims (6)
1. after changing MAC Address under a REDHAT operating system, network interface card recovers the method started, it is characterized in that: under redhat operating system, can perform in script by the statement required for instauration net card start-up is integrated in one, the operation wherein contain amendment configuration file, emptying temporary file, restart system.
2. after changing MAC Address under a kind of REDHAT operating system according to claim 1, network interface card recovers the method started, and it is characterized in that: first described method judges network interface card quantity, correct coupling corresponding relation.
3. after changing MAC Address under a kind of REDHAT operating system according to claim 2, network interface card recovers the method started, and it is characterized in that: still modify to all network interface card files after having judged.
4. after changing MAC Address under a kind of REDHAT operating system according to claim 3, network interface card recovers the method started, and it is characterized in that, described shell script mainly revises two files:
Ifcfg-eth, the MAC Address in these network card configuration files all will be revised as the MAC of current machine card of surfing Internet;
70-persistent-net.rules is the file that system generates automatically, the network interface card detected when comprising startup, determines network interface card order, directly empties.
5. after changing MAC Address under a kind of REDHAT operating system according to claim 1,2,3 or 4, network interface card recovers the method started, and it is characterized in that, described method operation steps is as follows:
1) draw by num=$ (ifconfig-a | grep eth | wc-l) statement the network interface card number that system recognizes, decide to revise corresponding ifcfg-ethx file;
2) current all correct network interface card information is listed by ifconfig – a, and by key word " HWaddr " value MAC Address;
3) first judge whether the configuration file of this network interface card exists, then step 2 by if condition before amendment) in recognize MAC Address and write this file for standby, and add # annotation;
4) draw corresponding relation according to network interface card quantity before, the ifcfg-ethx file that amendment is corresponding, write correct MAC Address;
5) empty 70-persistent-net.rules file, and restart.
6. after changing MAC Address under a kind of REDHAT operating system according to claim 5, network interface card recovers the method started, and it is characterized in that:
Write rear increase and can perform authority: chmod 755 mac.sh;
Perform script: ./mac.sh;
Ifconfig test after wait autoboot completes.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410725087.9A CN104407899A (en) | 2014-12-03 | 2014-12-03 | Method for restoring and starting network card after MAC address is changed under REDHAT operating system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410725087.9A CN104407899A (en) | 2014-12-03 | 2014-12-03 | Method for restoring and starting network card after MAC address is changed under REDHAT operating system |
Publications (1)
Publication Number | Publication Date |
---|---|
CN104407899A true CN104407899A (en) | 2015-03-11 |
Family
ID=52645532
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410725087.9A Pending CN104407899A (en) | 2014-12-03 | 2014-12-03 | Method for restoring and starting network card after MAC address is changed under REDHAT operating system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104407899A (en) |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105138368A (en) * | 2015-08-25 | 2015-12-09 | 浪潮电子信息产业股份有限公司 | Network card configuration file programming method based on LINUX system |
CN106254570A (en) * | 2016-08-01 | 2016-12-21 | 天脉聚源(北京)教育科技有限公司 | The MAC Address acquisition methods of a kind of ICE system and device |
CN107040427A (en) * | 2017-06-09 | 2017-08-11 | 上海联影医疗科技有限公司 | A kind of method and device of network card configuration |
CN107241239A (en) * | 2017-06-23 | 2017-10-10 | 郑州云海信息技术有限公司 | A kind of method for carrying out maximizing test to PCIE based on network interface card |
CN108696394A (en) * | 2018-05-18 | 2018-10-23 | 深圳市智微智能科技开发有限公司 | The means of communication and equipment of multiple PCIE network interface cards under a kind of Linux system |
CN111027104A (en) * | 2019-11-26 | 2020-04-17 | 深圳中电长城信息安全***有限公司 | Method, device and mainboard for preventing loss of network card identification data |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102063347A (en) * | 2010-12-28 | 2011-05-18 | 中国工商银行股份有限公司 | Magnetic tape data recovery method and system |
CN102427483A (en) * | 2011-11-15 | 2012-04-25 | 浪潮电子信息产业股份有限公司 | Method for binding network card name with equipment under Linux system |
-
2014
- 2014-12-03 CN CN201410725087.9A patent/CN104407899A/en active Pending
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102063347A (en) * | 2010-12-28 | 2011-05-18 | 中国工商银行股份有限公司 | Magnetic tape data recovery method and system |
CN102427483A (en) * | 2011-11-15 | 2012-04-25 | 浪潮电子信息产业股份有限公司 | Method for binding network card name with equipment under Linux system |
Non-Patent Citations (1)
Title |
---|
CZP11210: ""Linux脚本程序自动修改网卡配置文件中的MAC地址"", 《HTTP://WWW.2CTO.COM/OS/201308/236967.HTML》 * |
Cited By (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105138368A (en) * | 2015-08-25 | 2015-12-09 | 浪潮电子信息产业股份有限公司 | Network card configuration file programming method based on LINUX system |
CN106254570A (en) * | 2016-08-01 | 2016-12-21 | 天脉聚源(北京)教育科技有限公司 | The MAC Address acquisition methods of a kind of ICE system and device |
CN107040427A (en) * | 2017-06-09 | 2017-08-11 | 上海联影医疗科技有限公司 | A kind of method and device of network card configuration |
CN107241239A (en) * | 2017-06-23 | 2017-10-10 | 郑州云海信息技术有限公司 | A kind of method for carrying out maximizing test to PCIE based on network interface card |
CN108696394A (en) * | 2018-05-18 | 2018-10-23 | 深圳市智微智能科技开发有限公司 | The means of communication and equipment of multiple PCIE network interface cards under a kind of Linux system |
CN111027104A (en) * | 2019-11-26 | 2020-04-17 | 深圳中电长城信息安全***有限公司 | Method, device and mainboard for preventing loss of network card identification data |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN104407899A (en) | Method for restoring and starting network card after MAC address is changed under REDHAT operating system | |
CN106095620B (en) | A kind of development approach of built-in Linux partition holding | |
US20220317997A1 (en) | Online Upgrade Method for Household Appliance Multi-MCU System, Electronic Device and Medium | |
CN107239273B (en) | Disk drive binding method of server | |
CN105049486A (en) | Version management and file pulling control methods for static files, version management and file pulling control devices, and version control system | |
CN109542682B (en) | Data backup method, device, equipment and storage medium | |
CN104572229A (en) | Firmware upgrade method and firmware upgrade device for embedded system | |
CN102770841A (en) | Method and apparatus for generating minimum boot image | |
CN106789249B (en) | Hot updating method, client and server | |
CN110007941A (en) | A kind of the MCU firmware and upgrade method of Intelligent refuse classification recovery system | |
CN108270626A (en) | A kind of method, apparatus, equipment and the readable storage medium storing program for executing of upgrade server firmware | |
CN111258666A (en) | Reading method and device of computer file, computer system and storage medium | |
CN107908417A (en) | Firmware upgrade method and electronic equipment | |
CN113986257A (en) | Cloud platform front-end management interface deployment method and device and storage medium | |
US20050108704A1 (en) | Software distribution application supporting verification of external installation programs | |
CN111143113A (en) | Method, electronic device and computer program product for copying metadata | |
CN114995859A (en) | Page hot updating method, device, equipment and storage medium | |
CN107168719A (en) | Application program running method and device, terminal and computer readable storage medium | |
CN113360379B (en) | Program test environment creation method and program test environment creation apparatus | |
CN110716804A (en) | Method and device for automatically deleting useless resources, storage medium and electronic equipment | |
CN111400128B (en) | Log management method and device, computer equipment and storage medium | |
CN109144948B (en) | Application file positioning method and device, electronic equipment and memory | |
CN115048187A (en) | Operator-based pvc file importing method, device and storage medium | |
CN106557379B (en) | Method and device for generating silent installation package | |
CN109857380B (en) | Workflow file compiling method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20150311 |
|
RJ01 | Rejection of invention patent application after publication |