如果是笔记本电脑,经常更换网络环境的话,配置网络是比较麻烦的。其实操作也就那么几步,但是每次都要做重复工作确实很头痛,特别是在其实网络环境就那么几个的情况下(例如:寝室、实验室和图书馆)。如果每个地方都是用 DHCP 的方式自动配置网络,那自然好,但是有些地方又是需要手工配置的。不过幸好程序员都是懒惰的,于是就有了懒惰的工具(还要多谢 dlzcn 告诉我这个好用的工具!)。
在 Debian 下可以用 guessnet 来自动猜测网络环境,并根据结果进行自动配置。你事先定义一系列的条件,它并发地测试各个条件,最先满足的会被选中,并以此来配置网络。还等什么呢?赶快
aptitude install guessnet 吧!
guessnet 的配置文件集成在 ifup/ifdown 的配置文件里面,就是
/etc/network/interfaces 。下面是一个示例:
mapping eth0
# Too bad there's no way to pass commandline options to script
# script /usr/sbin/guessnet -i
script /usr/sbin/guessnet-ifupdown
# List of stanzas guessnet should scan for
# If none is specified, scans for all stanzas
map lab
# Profile to select when all tests fail
map default: dorm
# If no test succeed after this amount of seconds,
# then guessnet selects the default profile.
# Default is 5, but some network drivers need more.
#map timeout: 10
# Uncomment if something goes wrong:
#map verbose: true
#map debug: true
# Home network configuration
iface dorm inet dhcp
# At Lab
iface lab inet static
address 10.2.xx.xx
netmask 255.255.255.0
gateway 10.2.xx.xx
dns-nameservers 202.101.xx.xx
test peer address 10.2.xx.xx mac 00:0A:EB:xx:xx:xx
注释很详细,
man guessnet 就可以得到类似的示例配置。注意上面我把一些 ip 地址用 xx.xx 代替了,自己配置的时候当然要写自己的 ip 。其中
test peer address 10.2.xx.xx mac 00:0A:EB:xx:xx:xx
就是 guessnet 要测试的条件。可以把自己网关的 ip 和 MAC 地址对应起来,当然还可以使用其他方式,详细可以参考 guessnet 的 man-page 。另外,如果要想让
dns-nameservers 202.101.xx.xx
这一句能够自动生成
/etc/resolv.conf 的话,还需要安装
resolvconf 包。
No comments.