最近家里的電腦除了個(gè)怪問題.家里用的是東方有線的網(wǎng)絡(luò),系統(tǒng)是ubuntu 6 server,系統(tǒng)開機(jī)后一段時(shí)間,網(wǎng)絡(luò)就自動(dòng)斷了.ifconfig查看網(wǎng)卡信息,ip地址是對(duì)的.但ping不通外面的網(wǎng)絡(luò).然后再過一段時(shí)間,網(wǎng)絡(luò)又重新回復(fù),查看syslog,message等日志,只發(fā)現(xiàn)這樣的日志:
Apr 20 22:26:10 localhost dhclient: DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 7
Apr 20 22:26:10 localhost dhclient: DHCPOFFER from 10.119.16.1
Apr 20 22:26:10 localhost dhclient: DHCPREQUEST on eth0 to 255.255.255.255 port 67
Apr 20 22:26:10 localhost dhclient: DHCPACK from 10.119.16.1
Apr 20 22:26:10 localhost dhclient: bound to xxx.xxx.xxx.xxxx(我的ip地址) -- renewal in 1595 seconds.
初步分析應(yīng)該是ubuntu的dhclient有問題,暫時(shí)解決不了.
先寫個(gè)腳本解決下問題吧.(bash不怎么熟悉,只好用perl了)
fixnetwork.pl:
#/usr/bin/perl
use Net::Ping;
my $ip = "xxx.xxx.xxx.xxx";#隨便寫個(gè)公網(wǎng)上能ping通的ip地址
my $p = Net::Ping->new("tcp", 4);
while (1) {
if ($p->ping($ip)) {
print "$ip answered\n";
} else {
print "$ip did not answer\n";
system("ifdown eth0");
system("ifup eth0");
}
sleep(1);
}
然后執(zhí)行:sudo fixnetwork.pl > fixnetwork.log &
現(xiàn)在暫時(shí)網(wǎng)絡(luò)是能用了,但不知道這個(gè)dhclient的問題什么時(shí)候能解決:(