设置静态ip的脚本代码

制作原因:频繁的设置静态IP会耽误很多时间,尤其是这种重复性很强的工作,所以写了一个这样的脚本。

具体的配置说明在这个网址:http://blog.csdn.net/qq_16095853/article/details/77743984

1.进入root

#sudo -i 

2. 创建一个文件

#vi create_ip.sh

3.复制以下内容,到create_ip.sh

#!/bin/bash
rm /etc/network/interfaces
read -p "Input your static_ip:" youname
echo "# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).


# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address $youname 
netmask 255.255.255.0
gateway 192.168.0.1">>/etc/network/interfaces
rm /etc/resolv.conf
echo "nameserver 192.168.0.1
nameserver 8.8.8.8">>/etc/resolv.conf
/etc/init.d/networking restart
rm /etc/rc.local
version="echo \"nameserver 192.168.0.1
nameserver 8.8.8.8\">>/etc/resolv.conf"
echo "#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
$version
exit 0">>/etc/rc.local
reboot
4.赋予权限

#chmod 777 create_ip.sh

5.运行

# ./create_ip.sh

之后按回车就行了。
6.连接

重新ssh  链接自己写的静态ip 地址就行了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值