在Linux環境下, 通常可用 route 指令查詢目前的routing資訊.
jason@jason-laptop:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 * 255.255.255.0 U 2 0 0 wlan0
10.110.215.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
default 10.110.215.254
jason@jason-laptop:~$
假若route程式未被編入"bin"目錄, 亦可直接自/proc/net/route取得相關資訊
jason@jason-laptop:~$ cat /proc/net/route
Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
wlan0
eth0 00D76E
eth0 0000FEA9 00000000 0001 0 0 1000 0000FFFF 00 0
eth0 00000000 FED76E
此欄位中
1) IP address用16進制表示.
如
2) Flag使用數字表示, 其含義可參照 net-tools
範例中,
1 = 1 = U
3 = 2*1 +1 = UG
(Ref.0)
Exploring the /proc/net/ Directory
(Ref.1) route --help 摘錄
route flag:
U (route is up)
H (target is a host)
G (use gateway)
R (reinstate route for dynamic routing)
D (dynamically installed by daemon or redirect)
M (modified from routing daemon or redirect)
A (installed by addrconf)
C (cache entry)
! (reject route)
(Ref.2) net-support.h 摘錄
/* Keep this in sync with /usr/src/linux/include/linux/route.h */
#define RTF_UP 0x0001 /* route usable "U" */
#define RTF_GATEWAY 0x0002 /* destination is a gateway "G" */
#define RTF_HOST 0x0004 /* host entry (net otherwise) "H" */
#define RTF_REINSTATE 0x0008 /* reinstate route after tmout */
#define RTF_DYNAMIC 0x0010 /* created dyn. (by redirect) */
#define RTF_MODIFIED 0x0020 /* modified dyn. (by redirect) */
#define RTF_MTU 0x0040 /* specific MTU for this route */
#ifndef RTF_MSS
#define RTF_MSS RTF_MTU /* Compatibility :-( */
#endif
#define RTF_WINDOW 0x0080 /* per route window clamping */
#define RTF_IRTT 0x0100 /* Initial round trip time */
#define RTF_REJECT 0x0200 /* Reject route */
沒有留言:
張貼留言