Blogger Information
Blog 16
fans 0
comment 3
visits 16923
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Linux 任务计划修改IP
Altura的博客
Original
702 people have browsed it

chmod u+x ip.sh给.sh文件添加x执行权限

at 06:00 6/20/2017 任务在2017年6月20号6点执行 

centos

#!/bin/bash

#进入网卡配置文件的目录

cd /etc/sysconfig/network-scripts/

#使用sed直接修改网卡的IP地址

sed  -i 's/^IPADDR=\S\+/IPADDR=192.168.1.1/' ./ifcfg-eth0

#使用sed直接修改网卡的子网掩码

sed  -i 's/^NETMASK=\S\+/NETMASK=255.255.255.0/' ./ifcfg-eth0

#使用sed直接修改网卡的网关

sed  -i 's/^GATEWAY=\S\+/GATEWAY=192.168.1.1/' ./ifcfg-eth0

#重新启动网卡

/etc/init.d/network restart



Ubuntu

sed -i 's/\r//g' ip.sh  #修改格式


#!/bin/bash

#进入网卡配置文件的目录

cd /etc/network/

#使用sed直接修改网卡的IP地址

sed  -i 's/^address \S\+/address 192.168.1.1/' ./interfaces

#使用sed直接修改网卡的子网掩码

sed  -i 's/^netmask \S\+/netmask 255.255.255.0/' ./interfaces

#使用sed直接修改网卡的网关

sed  -i 's/^gateway \S\+/gateway 192.168.1.1/' ./interfaces

#重新启动网卡

/etc/init.d/networking restart

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post