Shell scripts use the SED flow editor to modify the CentOS network card IP address with one click

Source: Internet
Author: User
Tags ssh server

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

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.