In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to set up the script under Linux IP, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Examples of IP setup script under Linux and solutions to problems encountered
Background
A Java web project has a function to modify IP. The IP modification script for Linux is as follows:
#! / bin/bash # useing parameter ip:netmask:gateway:dns1 # system version:centos6,7/redhat6,7 # read parameter ipaddr= `echo $1 | cut-d ":"-f 1`gateway= `echo $1 | cut-d ":"-f 2`echo `echo $1 | cut-d ":"-f 3`dns1= `echo $1 | cut-d ":"-f 4`dns2= `echo $1 | cut-d ":"-f 5`targetDevice=$2 # get device (active) name-centos6 and centos7 DEVICE= `dmesg | grep Link | grep Up | cut-d ":"-f 3r 4 | cut-d "- f 2 | cut-d D ":"-f 1 | uniq | head-n 1` # if parameter has device name Use it, else use first alive device if ["$targetDevice"! = ""] Then DEVICE=$targetDevice echo 'device use target device:' $DEVICE fi # backup net_file mv / etc/sysconfig/network-scripts/'ifcfg-'$DEVICE / etc/sysconfig/network-scripts/'ifcfg-'$DEVICE'.bak'-f # config (net_file) cat / etc/sysconfig/network-scripts/'ifcfg-'$DEVICE DEVICE=$DEVICE ONBOOT=yes TYPE=Ethernet BOOTPROTO=none IPV6INIT=no DEFROUTE=yes IPADDR=$ipaddr GATEWAY=$gateway NETMASK=$netmask DNS1=$dns1 DNS2=$dns2 end # update / etc/hosts cat / sensor/bin/standardhosts > / etc/hosts echo '127.0.0. 1'$(hostname) > > / etc/hosts # grant the net_file chmod 755 / etc/sysconfig/network-scripts/'ifcfg-'$DEVICE # restart network / etc/init.d/network restart
In fact, there are several problems encountered in the execution of this shell script, which are the configuration problems related to the network services of the target server. There are four different kinds of errors, sorted out below for later use. The essence of the script is to write the destination IP information to the network card file ifcfg-eth3 file. (eth3 is the name of the communication network card on the test machine), which needs to be passed to the script as an argument.
Question one
Test the problems encountered during the execution of this script on a virtual machine. VirtualBox is installed locally and nodes of 5 virtual machines are replicated. Based on this background, after the execution of the script is completed, the service network restart command to restart the Nic service always fails and the failure message prompts:
Error:No suitable device found: no device found for connection "System eth0"
This is because the virtual machine replicates the network card during the replication process, but in fact ifconfig-a shows only one network card. Solution:
The first step is to execute ifconfig-a to check the name of the network card of the current system. My current virtual machine node is eth3,lo.
The second step is to keep the ifcfg-eth3,ifcfg-lo in / etc/sysconfig/network-scripts. Other Nic files that do not exist need to be deleted. What is copied is the eth0,rm-rf ifcfg-eth0 file.
The third step is to ifcfg-eth3 the contents of the file to ensure that the name of the DEVICE=eth3 parameter is the same as the name of the file.
The fourth step is to modify the network card policy file vi / etc/udev/rules.d/70-persistent-net.rules to find the configuration of the eth3 network card, and modify the MAC address to be the same as the MAC address of eth3.
Step 5, verify: execute service network restart to verify that the Nic restarts successfully.
Question two
Nm_object_array_demarshal: couldn't create object for / org/freedesktop/NetworkManager/ActiveConnection/39Error: Obtaining active connection for'/org/freedesktop/NetworkManager/ActiveConnection/39' failed. [FAILED]
Question three
See 'systemctlstatus network.service' and' journalctl-xn' for details
For this problem, execute journalctl-xe > / home/journalctl.log
Look in the log file and find that the real error is it:
Bringing up interface enp4s0f0: RTNETLINK answers: File exists
Question 4
Bringing up interface eth0: Device eth0 does not seem to be present,delaying initialization.
The root cause of the second, third and fourth problems in centos is that there is a conflict between the two services that start the network: / etc/init.d/network and / etc/init.d/NetworkManager.
Solution: turn off the NetworkManager service and do it by commanding service NetworkManager stop. Then perform service network restart verification to restart the Nic service normally.
Conclusion
Verify the IP setup script, providing two parameters, one is the IP information and the name of the Nic, execute the following command:
Sh reset_ip.sh 192.168.10.170 eth3 255.255.255.255.0 eth3 can modify the virtual machine IP address. A simple IP setup script, the implementation of the process of almost the network card-related problems, encountered. Various attempts have finally found the reason, and the main root cause is the problem of the NetworkManage service.
The above is all the contents of the article "how to set up the script for IP under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.