学习笔记之ubuntu修改固定IP脚本
一、shell脚本编程
二、正则表达式
三、linux修改IP的方法
#!/bin/bash cd /etc/network/ stty erase '^?' write_interfaces()
{
echo "auto lo
iface lo inet loopback auto eth0
iface eth0 inet static
address $
netmask 255.255.255.0
gateway $
" > interfaces
} reboot_fun()
{
echo "reboot now?(Y/N)"
read reb_in if [[ ${reb_in} = $'Y' || ${reb_in} = $'y' ]]
then
echo "reboot now"
reboot
else
echo "pls reboot if you can not ping the IP"
fi
} ping_func()
{
ping -c $set_IP && result= || result=
if [ $result -eq ]
then
{
echo "set Ip conflict"
continue
IP_INPUT=
}
fi if [ $result -eq ]
then
{
echo "IP is ok:$set_IP" write_interfaces $set_IP $GateWay
/etc/init.d/networking reload
/etc/init.d/networking restart
echo "set ok"
IP_INPUT=
}
fi
} echo "set IP into the main.cpp"
IP_INPUT= while [ $IP_INPUT -eq ]
do
echo "input IP"
read set_IP -n if [[ $set_IP =~ ^([-]{,}|[-][-]|[-][-]|[-])\.([-]{,}|[-][-]|[-][-]|[-])\.([-]{,}|[-][-]|[-][-]|[-])\.([-]{,}|[-][-]|[-][-]|[-])$ ]]
then
echo "input gateway"
read GateWay arr_IP=${set_IP//./ }
arr_IP=($arr_IP)
arr_gw=${GateWay//./ }
arr_gw=($arr_gw) for arr in
do
if [ ${arr_IP[$arr]} == ${arr_gw[$arr]} ]
then
echo "arr_IP:${arr_IP[$arr]}"
else
echo "error IP :$set_IP"
continue
fi
done ping_func
fi
done reboot_fun
学习笔记之ubuntu修改固定IP脚本的更多相关文章
- ubuntu修改固定ip
1.vi /etc/network/interfasces,添加红框内的内容:
- ubuntu 18.04 修改 固定ip
Linux(ubuntu)下固定IP的方法 写在前面,问:为什么要固定ip.答:要知道固定IP的好处多多,随意搬动,固定共享地址,不怕断网等等 首先,我们要选取一个局域网内的IP,方法如下: 1. ...
- Linux - ubuntu 设置固定ip和设置dns
ubuntu 设置固定ip和设置dns 1.ifconfig 查看网卡名称 root@jiqing-virtual-machine:~# ifconfig ens32 Link encap:以太网 硬 ...
- CentOS 修改固定IP地址
CentOS 修改固定IP地址 参考地址:https://www.cnblogs.com/technology-huangyan/p/9146699.htmlhttps://blog.csdn.net ...
- 桌面版Ubuntu系统固定IP设置和Network-manager设置
我自己的学校是绑定MAC和IP上网的.这种方法名义上说是为了安全,不过是个搞计算机的都知道随便修改一下MAC就可以使用别人的IP了. 不提蛋疼的事情了,先来说说网络的配置吧 我用的是Ubuntu14. ...
- 【Redis数据库】命令学习笔记——发布订阅、事务、脚本、连接等命令汇总
本篇基于redis 4.0.11版本,学习发布订阅.事务.脚本.连接的相关命令. Redis 发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息. 序号 ...
- linux -- Ubuntu修改静态IP地址重启后无法上网的解决
ubuntu设置静态IP地址后,上不了网 文章中也提到,如果是在/etc/resolv.conf添加DNS,由于Ubuntu 有一个 resolvconf 服务,如果重启它,那么 /etc/resol ...
- Linux(ubuntu)下固定IP的方法
写在前面,问:为什么要固定ip.答:要知道固定IP的好处多多,随意搬动,固定共享地址,不怕断网等等 首先,我们要选取一个局域网内的IP,方法如下: 1.选取IP号段,一般是路由器DCHP以外的IP地址 ...
- Bash脚本编程学习笔记05:用户交互与脚本调试
用户交互 在<学习笔记04>中我们有提到位置参数,位置参数是用来向脚本传递参数的一种方式.还有一种方式,是read命令. [root@c7-server ~]# read name alo ...
随机推荐
- [LuoguP1053][Noip2005]篝火晚会
[LuoguP1053][Noip2005]篝火晚会(Link) 现在你有一个排成一个圈的\(N\)大小的队列,一开始的顺序是\(\{1,2,3,4...N\}\),一共有\(N\)个要求,第\(i\ ...
- jquery checkbox点选反选
<script type="text/javascript"> $(function(){ //点选反选 $("#check_all").click ...
- 用画布canvas画安卓logo
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- a、button、input点击获取焦点时出现蓝色边框,如何去掉
a,button,input{ -webkit-tap-highlight-color: rgba(0, 0, 0, 0); -webkit-user-modify: read-write-plain ...
- 浅谈ES6基础——Promise
IMAGE加载 Callback Hell function loadImg(src,callback,fail) { var img = document.createElement('img'); ...
- #leetcode刷题之路22-括号生成
给出 n 代表生成括号的对数,请你写出一个函数,使其能够生成所有可能的并且有效的括号组合. 例如,给出 n = 3,生成结果为:[ "((()))", "(()())&q ...
- 小白的Unity5之路(一)
Player移动: public float speed = 6f; Vector3 movement; Rigidbody playerRididbody; void FixedUpdate () ...
- JQuery中ajaxSubmit,在ie或360兼容,提交后台不能获得参数
问题描述:360兼容模式.IE浏览器,通过ajaxSubmit提交,后台不能获得参数值 解决办法:把options.semantic这个参数改成true 代码: var ajax_option={ s ...
- js如何获取键盘高度
在移动端或混合app开发中,js如何获取键盘高度,直接贴上代码吧 input是一个html input 标签 var timer = { id:null, run:function (callback ...
- docker入门——安装(CentOS)、镜像、容器
Docker简介 什么是docker 官方解释: Docker is the company driving the container movement and the only container ...