linux 內核里的 netconsole 可以將內核的 printk 消息通過 udp 發送到遠程主機上,而且還可以將
這樣的消息發送到遠程主機的syslogd里。
netconsole的用法:
如果 netconsole 被編譯成模塊,可以用下面的命令啟用 netconsole
=============================================================================
2.4內核語法:
modprobe netconsole [dev=srcdev] [source_port=srcport] [target_port=dstport] target_ip=<hex mode of dst ip addr> [\
target_eth_byte0=<dst mac addr hex byte 0> \
target_eth_byte1=<dst mac addr hex byte 1> \
target_eth_byte2=<dst mac addr hex byte 2> \
target_eth_byte3=<dst mac addr hex byte 3> \
target_eth_byte4=<dst mac addr hex byte 4> \
target_eth_byte5=<dst mac addr hex byte 5> ]
srcdev: 網絡接口
srcport: udp 源端口 (缺省為6665)
dstport: udp 目標端口 (缺省為6666)
hex mode of dst ip addr: 十六進制表示的目標 ip 地址
dst mac addr hex byte [0-6]: 十六進制表示的目標 mac 地址的第一到六位
#modprobe netconsole dev=eth0 target_port=514 target_ip=0xc0a86b01 \
target_eth_byte0=0x00 \
target_eth_byte1=0x0D \
target_eth_byte3=0x60 \
target_eth_byte4=0x2C \
target_eth_byte0=0x05 \
target_eth_byte0=0xB2
上面這條命令會將本機的 kernel printk msg 發送到主機 192.168.107.1 的 udp 端口 514 (syslogd 缺省監聽的端口),
發送給 mac 地址為00:0D:60:2C:05:B2的接口。
=============================================================================
2.6內核語法:
modprobe netconsole netconsole=[srcport]@[srcip]/[srcdev],[dstport]@dstip/[dstmac]
srcport: udp 源端口 (缺省為6665)
srcip: 源ip地址 (缺省為接口地址)
srcdev: 網絡接口
dstport: udp 目標端口 (缺省為6666)
dstip: 目標ip地址
dstmac: 目標主機接口的 MAC 地址
#modprobe netconsole netconsole=@/,514@192.168.107.1/00:0D:60:2C:05:B2
上面這條命令會將本機的 kernel printk msg 發送到主機 192.168.107.1 的 udp 端口 514 (syslogd 缺省監聽的端口),
發送給 mac 地址為00:0D:60:2C:05:B2的接口。
如果那臺主機的 syslogd 配置成為接收遠程的 syslog 消息,來自 netconsole 的消息就可以記錄在那臺主機的系統日志里。
在沒有syslogd在運行的主機上可以用命令接收來自遠程主機的消息:
# netcat -u -l -p
參見:
1. /usr/src/linux/Documentation/networking/netconsole.txt
2. man 8 syslogd
3. man 1 netcat
原文轉自:http://www.anti-gravitydesign.com