求一个 可以 永久修改ip的脚本 就是写文件的那种

sh/bash/dash/ksh/zsh等Shell脚本
回复
tianmaxj
帖子: 6
注册时间: 2009-09-05 16:47

求一个 可以 永久修改ip的脚本 就是写文件的那种

#1

帖子 tianmaxj » 2009-09-05 17:21

求一个 可以 永久修改ip的脚本 就是写文件的那种
谢谢了!!各位
头像
adagio
论坛版主
帖子: 22110
注册时间: 2008-02-17 23:47
来自: 美丽富饶的那啥星球

Re: 求一个 可以 永久修改ip的脚本 就是写文件的那种

#2

帖子 adagio » 2009-09-05 17:26

代码: 全选

#!/bin/bash
ifconfig eth0 192.168.0.10 netmask 255.255.255.0 getway 192.168.0.1
你对付用吧,不用谢
明天就换大三八!
——8核CPU、8G内存、8T硬盘……
8卡交火,80寸大屏放8个……
IPv8的光纤要8条……

---------------------------------------------------------------------------------
[图片版]新手当自强(续)FAQ
[新手进阶]挂载、fstab、调整linux分区
[图片版]E17桌面环境配置手把手
头像
O_O_BOT
帖子: 2461
注册时间: 2009-05-20 19:32

Re: 求一个 可以 永久修改ip的脚本 就是写文件的那种

#3

帖子 O_O_BOT » 2009-09-05 17:37

irc <fvw_> say: /etc/network/interfaces -> example in /usr/share/doc/
irc 聊天室
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录

http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
头像
daf3707
论坛版主
帖子: 12731
注册时间: 2007-06-13 15:57
来自: 在他乡

Re: 求一个 可以 永久修改ip的脚本 就是写文件的那种

#4

帖子 daf3707 » 2009-09-05 17:39

adagio 写了:

代码: 全选

#!/bin/bash
ifconfig eth0 192.168.0.10 netmask 255.255.255.0 getway 192.168.0.1
你对付用吧,不用谢
:em04
tianmaxj
帖子: 6
注册时间: 2009-09-05 16:47

Re: 求一个 可以 永久修改ip的脚本 就是写文件的那种

#5

帖子 tianmaxj » 2009-09-06 13:11

adagio 写了:

代码: 全选

#!/bin/bash
ifconfig eth0 192.168.0.10 netmask 255.255.255.0 getway 192.168.0.1
你对付用吧,不用谢
啊!!老大 ifconfig 每次重启都得重新设置啊!
影响效率!!!!
头像
O_O_BOT
帖子: 2461
注册时间: 2009-05-20 19:32

Re: 求一个 可以 永久修改ip的脚本 就是写文件的那种

#6

帖子 O_O_BOT » 2009-09-06 14:27

O_O_BOT 写了:irc <fvw_> say: /etc/network/interfaces -> example in /usr/share/doc/
:em06
irc 聊天室
ubuntu-cn 的irc 频道为
irc.ubuntu.com 8001 #ubuntu-cn
UTF8编码 可用 irssi xchat pidgin weechat 登录

http://webchat.freenode.net/?channels=ubuntu-cn
[url]irc://irc.freenode.net/ubuntu-cn[/url]
sunsoft1021
帖子: 5
注册时间: 2009-08-19 10:21

Re: 求一个 可以 永久修改ip的脚本 就是写文件的那种

#7

帖子 sunsoft1021 » 2009-09-09 10:58

#改变ip,如果出错,回滚至原ip地址
chip(){
sed -i "s/$old_ip/$new_ip/" /etc/network/interfaces
/etc/init.d/networking restart &>/dev/null
ping -c 2 www.google.com
if [ $? != 0 ];then
cp ./tmp/interfaces /etc/network/interfaces
/etc/init.d/networking restart &>/dev/null
else
echo "change ip success" >> $old_ip.log
fi
}
头像
BigSnake.NET
帖子: 12522
注册时间: 2006-07-02 11:16
来自: 廣州
联系:

Re: 求一个 可以 永久修改ip的脚本 就是写文件的那种

#8

帖子 BigSnake.NET » 2009-09-09 19:09

LANG=C perl <(zcat /usr/share/doc/ifupdown/examples/generate-interfaces.pl.gz )
^_^ ~~~
要理解递归,首先要理解递归。

地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
头像
mickeywaley
帖子: 1427
注册时间: 2009-03-19 9:19
系统: ubuntu
来自: 江苏
联系:

Re: 求一个 可以 永久修改ip的脚本 就是写文件的那种

#9

帖子 mickeywaley » 2009-09-09 19:18

代码: 全选

sudo gedit /etc/network/interfaces

代码: 全选

auto lo
iface lo inet loopback


auto dsl-provider # 开机自动拨号
iface dsl-provider inet ppp
pre-up /sbin/ifconfig eth0 up # line maintained by pppoeconf
provider dsl-provider

auto eth0
iface eth0 inet static
address 192.168.1.1  #设置eth0内网地址inet 地址
netmask 255.255.255.0 #设置eth0掩码地址
gateway 192.168.1.254 #设置eth0广播地址

代码: 全选

auto lo
iface lo inet loopback


auto dsl-provider
iface dsl-provider inet ppp
pre-up /sbin/ifconfig eth0 up # line maintained by pppoeconf
provider dsl-provider

auto eth0
iface eth0 inet dhcp
#iface eth0 inet static
address 192.168.1.6
netmask 255.255.255.0
gateway 192.168.1.1

代码: 全选

auto lo
iface lo inet loopback


auto dsl-provider
iface dsl-provider inet ppp
pre-up /sbin/ifconfig eth0 up # line maintained by pppoeconf
provider dsl-provider

auto eth0
iface eth0 inet static
address 192.168.1.6
netmask 255.255.255.0
gateway 192.168.1.1
回复