(转)Linux 远程开机(walk on lan)
时间:2010-10-19 来源:jfcat
一,什么情况下需要远程开机?
如果我们的服务器没有部署在本地(实际上通常都是这样的,我们会把服务器托管到IDC机房),
而且服务器在机房中不止一台,其中一台被关闭时,则我们可以远程连接一台没有关机的服务器上,
然后进行远程开机.
二,远程开机需要的软件
它需要wakeonlan这个软件,
从何处得到它?
它的官方站是:http://sourceforge.net/projects/wake-on-lan/
如果使用rpm包可以从这里下载:http://dag.wieers.com/rpm/packages/wol/
如果使用fedora,则可以用yum命令安装:
yum install wol
三,如何进行远程开机?
先不要急着去关闭你的linux服务器,你首先要确定它是否支持远程开机?
第一步:登录到目标服务器,用ethtool这个命令打印出网卡的信息
[root@localhost lhd]# ethtool eth0
Settings for eth0:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: MII
PHYAD: 32
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: pumbg
Wake-on: d
Current message level: 0x00000007 (7)
Link detected: yes
可以看到,ethtool把网卡的信息全部列出,我们只关心其中的这两项:
Supports Wake-on: pumbg
Wake-on: d
如果 wake-on 一项值为 d,表示禁用wake on lan
值为 g,表示启用 wake on lan
因为此机器禁用了 wake on lan,所以用下面的命令来启用它:
[root@localhost lhd]# ethtool -s eth0 wol g
再用 ethtool命令进行查看,会发现:
Wake-on: g
OK,目标机器的网卡已经支持了远程开机,下面我们得到它的本地MAC地址:
[root@localhost lhd]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:03:0D:1D:1F:97
inet addr:192.168.6.101 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:34470 errors:0 dropped:0 overruns:0 frame:0
TX packets:35377 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:31559763 (30.0 MiB) TX bytes:5340032 (5.0 MiB)
Interrupt:5 Base address:0x2c00
把HWaddr 00:03:0D:1D:1F:97这一项记录下来即可
现在你可以试着把目标机器关闭
第二步:开机
现在我们需要登录到已安装了wakeonlan软件的机器上,在上面执行开机命令:
wol 00:03:0D:1D:1F:97
稍后就会发现,目标机器已开机可以登录了
Ethernet Interface Settings
ethtool is a program that displays and changes Ethernet card settings such as auto-negotiation, port speed, duplex mode, and Wake-on-LAN. It is not installed by default, but is available for installation in the repositories.
sudo apt-get install ethtool
The following is an example of how to view supported features and configured settings of an Ethernet interface.
sudo ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full Advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 1 Transceiver: internal Auto-negotiation: on Supports Wake-on: g Wake-on: d Current message level: 0x000000ff (255) Link detected: yes
Changes made with the ethtool command are temporary and will be lost after a reboot. If you would like to retain settings, simply add the desired ethtool command to a pre-up statement in the interface configuration file /etc/network/interfaces.
The following is an example of how the interface identified as eth0 could be permanently configured with a port speed of 1000Mb/s running in full duplex mode.
auto eth0 iface eth0 inet static pre-up /usr/sbin/ethtool -s eth0 speed 1000 duplex full
|
|
---|---|
Although the example above shows the interface configured to use the static method, it actually works with other methods as well, such as DHCP. The example is meant to demonstrate only proper placement of the pre-up statement in relation to the rest of the interface configuration. |