Ubuntu静态ip与动态ip联网

本人的系统是Ubuntu14.04 LTS 64-bit,现将自己联网过程中纠结过的事情记录下来。

1.静态ip联网

在办公室使用的是静态ip,联网方式为:

(1).安装mentohust(http://code.google.com/p/mentohust);
(2).在图形化界面下配置,或者直接修改配置文件 /etc/network/interfaces,

/etc/resolv.conf以及/etc/resolvconf  /resolv.conf.d/base(可参考http://www.ha97.com/4895.html);

很容易就通过mentohust连上网了,还得感谢为mentohust无私贡献的诸位前辈。


2.动态ip联网

宿舍的网络是采用动态ip的有线网,利用办公室的联网方式会存在问题,以下是我的处理方式:

(1).将原来的静态ip转换为动态ip;

通过图形界面的方式,修改的/etc/network/interfaces:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopbackc

/etc/resolv.conf:去掉原先存在的静态DNS信息,不用填写额外的信息。

(2).设定好第一步之后,现在有两种方式:第一种方式a存在问题,第二种方法b可行,仅供参考。

(a).通过mentohust联网(此方式还存在问题);

安装好mentohust之后,运行如下命令:

mentohust -uUsername -pPassword -neth0 -d0/1/2/3 -a/0/1 &

其中,-d为dhcp选项,-a为组播地址选项,几种方式我都试了一下,结果如下:


此种方式存在问题,希望看到的人能够避免或者解决这个问题。

(b)通过rjsupplicant.sh实现联网(此方式可行)

接着第一步,在华中科技大学官方校园网服务平台下载Su for Linux V1.31.tar.gz,此软件为绿色软件,解压缩之后就可以用了,解压缩之后(注意:Linux的文件路径中不能存在空格,最好将源文件重命名解之后再解压),cd到rjsupplicant.sh所在的目录,用命令:

./rjsupplicant.sh -d1 -sinternet -uUsername -pPassword &

就可以实现联网了。


3.编写脚本文件联网

接着通过rjsuppliant.sh实现动态ip的联网方式,也可以通过shell脚本实现联网自动化,方法如下:

(1).编写脚本internet_connect:

#!/bin/bash
rjpath=/usr/local/src/rjsupplicant  #the path of rjsupplicant.sh
cd $rjpath
./rjsupplicant.sh -d1 -sinternet -uUsername -pPassword &
exit 0 

编写脚本internet_quit:

#!/bin/bash
rjpath=/usr/local/src/rjsupplicant   #the path of rjsupplicant.sh
cd $rjpath
./rjsupplicant.sh  -q &
exit 0

(2)将rjsuppliant.sh、internet_connect和internet_quit添加可执行的权限

chmod a+x rjsuppliant.sh internet_connect internet_quit

(3)将internet_connect和internet_quit添加到$PATH所在的全局路径,例如

cp internet_connect  internet_quit  /usr/local/bin/

然后就可以实现每次在命令行中通过脚本文件名联网了。


总结:根据我现在的操作,在办公室的静态ip使用mentohust联网,在宿舍的动态ip使用rjsuppliant.sh联网。





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值