制作原因:频繁的设置静态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 地址就行了