In Linux systems, it is sometimes necessary to modify the IP address of the network card. In many cases, our maintenance of the Linux system is managed remotely (SSH), so that when the IP address changes, the connection between us and the server will be disconnected.
One might say that we can connect the modified IP address again, because the IP address of Linux may require us to restart the NIC after it is changed in the configuration file, the new IP address will take effect.
And we are disconnected between this time and the server, which requires us to log in to the system locally (possibly the room), restart the network card. Obviously this is inefficient, I cite a script to solve the above problems: for example, want to change the IP address of the NIC Eth3 to 192.168.1.1
Vim ipchange.sh
#!/bin/bash
#进入网卡配置文件的目录
cd/etc/sysconfig/network-scripts/
#使用sed修改网卡的IP地址, output the result to a temporary file. The reason for using temporary files is that SED modified results are not saved in the original file
Sed '/ipaddr/c\ipaddr=192.168.1.1 './ifcfg-eth3 >./tmp
#用修改后的网卡配置文件能容覆盖原来的内容
\cp-f./tmp./IFCFG-ETH3
RM-RF./tmp
#重新启动网卡, and save the exit
Ifdown Eth3
Ifup Eth3
#给脚本赋予所有者可执行的权限
chmod u+x ipchange.sh
By remote execution of the above script, you can connect to the SSH server's new IP directly, do not need to restart the network card locally
This article is from the "Li Gaoquan" blog, make sure to keep this source http://lgq258.blog.51cto.com/9766325/1773933
Shell script modifies the CentOS network card IP address using the SED flow editor one click