LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1465|回复: 6

请问修改IP的脚本如何写?

[复制链接]
发表于 2004-8-6 19:20:38 | 显示全部楼层 |阅读模式
大家晚上好!

   我想写一个修改IP的脚本. 我的思路是这样的:
   1. 先用命令ifconfig eth0 202.38.248.179
   2. 接着修改/etc/hosts文件,在最后加上一句
        202.38.248.179          iverison
  即/etc/hosts修改后变为
  # Do not remove the following line, or various programs
  # that require network functionality will fail.
  127.0.0.1               iversion localhost.localdomain localhost
  202.38.248.179          iverison
  
  即脚本为
  #! /bin/bash
  echo "please input your IP"
  read ip
  ipstring=$(echo ""$ip" iversion")
  echo ipstring >> /etc/hosts
  ifconfig eth0 202.38.248.179
  echo "finish"
但是我重启计算机以后我的IP还是原来那个,都没有变,这是怎么回事啊?
请问应该怎样写才对呢?

请各位指教!!
发表于 2004-8-6 19:27:18 | 显示全部楼层
把脚本命令
echo "202.38.248.179" >> /etc/hosts
/sbin/ifconfig eth0 202.38.248.179
添加到/etc/rc.local中
 楼主| 发表于 2004-8-6 19:56:30 | 显示全部楼层
那我只用ifconfig eth0 202.38.248.179这个命令来修改怎么样?
其实我不大明白/etc/hosts文件的作用,好奇怪我之前在网络设置里设好了IP,
hosts文件里面都没有202.38.248.179          iverison.这句话.那我现在加上去好像没有什么意义喔.

还有就是楼上这种改法就不能够实现动态修改IP啦,我写这个脚本的目的是为了只需执行这个脚本就可以修改IP.
那请问还有没有更好的方法?
发表于 2004-8-6 20:02:48 | 显示全部楼层
动态IP是每次自动获取的,能修改么? :ask
 楼主| 发表于 2004-8-6 20:08:23 | 显示全部楼层
不,我的意思是设置静态的ip
发表于 2004-8-6 20:20:18 | 显示全部楼层
最初由 iversion 发表
不,我的意思是设置静态的ip

静态IP的修改方法,用aaccdd兄的是没问题的!
 楼主| 发表于 2004-8-6 20:51:21 | 显示全部楼层
那还有一个问题 /etc/hosts文件开始是只有下面几句:
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 iversion localhost.localdomain localhost
那我还要不要再在其后加上 202.38.248.179  iversion呢?
好像hosts文件是和DNS,域名解析有关喔:ask
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表