C缘网
Would you like to react to this message? Create an account in a few clicks or log in to continue.

常用网路侦错指令

向下

常用网路侦错指令 Empty 常用网路侦错指令

帖子 由 eyke0519 周四 5 一月 2012 - 13:10

一. ifconfig 指令.
  
  ifconfig 指令用来设定网路介面, 并可查询目前网路介面的设定情形.

  
  语法:
  
  1. ifconfig [介面] 
  
  介面可以不写, 若不写,
则显示目前使用中的介面.
  
  介面可以填入: eth0, eth1 等.
  
  若是下 
  
  2.
ifconfig -a
  
  则会列出所有的网路介面情形.
  
  [root@ols3-note /root]#
ifconfig -a
  eth0   Link encap:Ethernet HWaddr 00:80:C8:8F:B8:F4

       inet addr:192.168.54.51 Bcast:192.168.54.63 Mask:255.255.255.240

       UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
       RX
packets:234 errors:0 dropped:0 overruns:0 frame:0
       TX packets:65
errors:0 dropped:0 overruns:0 carrier:0
       collisions:0 txqueuelen:100

       Interrupt:3 Base address:0x320
  
  lo    Link encap常用网路侦错指令 Sweatocal Loopback
       inet addr:127.0.0.1 Mask:255.0.0.0

       UP LOOPBACK RUNNING MTU:3924 Metric:1
       RX packets:0
errors:0 dropped:0 overruns:0 frame:0
       TX packets:0 errors:0 dropped:0
overruns:0 carrier:0
       collisions:0 txqueuelen:0
  
  其中 :

  
  eth0 表示第一张网路卡
  
  lo 表示 loopback , 即没有连接到真实网路时的网路介面,
可用来测试网路的应用软体, 并且提供区域性的 TCP/IP 服务.
  
  HWaddr 是网路卡的硬体位址
  
  inet
addr 是网路卡的 IP,
  
  Bcast 是广播(broadcast) 的位址
  
  Mask 是网路遮罩.

  
  MTU 是 Maximum Trasmission Unit 最大传输单元(位元组), 即此介面一次所能传输的最大封包.

  
  Metric 是权值之意, 路由权值, 或所需的花费, 目前尚未使用, 将来会 implement.
  
  RX
是接收情形.
  
  TX 是传送情形.
  
  collisions 是网路讯号碰撞的意思

  
  txqueuelen 是传输缓区长度大小意思
  
  Interrupt 是 IRQ 中断位址

  
  Base address 是 I/O 位址
  
  3. ifconfig 介面 [aftype] 选项 | 位址

  
  aftype 是位址家族之意, 预设值是 inet (TCP/IP)
  
  其它还有 ddp(AppleTalk)
ipx(Novell) 
  
  详细情形, 请自行 man ifconfig
  
  不建议各位用 ifconfig
手动修改, 请用 linuxconf 较佳.
  
  不过, 在查验为何网路不通时, 经常会遇到的问题是 netmask 设错了, 这时,
手动设 netmask 倒是十分方便的方法.
  
  假设 netmask 应为 255.255.255.128, 但你的网路卡却是
255.255.255.0
  
  那麽下:
  
  ifconfig eth0 netmask 255.255.255.128

  
  即可改正过来.
  
  ifconfig eth0 down 可将网路卡关闭, 此时下 ifconfig 将只看到
lo.
  
  [root@ols3-note /root]# ifconfig
  lo    Link encap常用网路侦错指令 Sweatocal Loopback
       inet addr:127.0.0.1 Mask:255.0.0.0

       UP LOOPBACK RUNNING MTU:3924 Metric:1
       RX packets:0
errors:0 dropped:0 overruns:0 frame:0
       TX packets:0 errors:0 dropped:0
overruns:0 carrier:0
       collisions:0 txqueuelen:0
  
  ifconfig
eth0 up 可将网路卡打开, 下 ifcofnig 又可看到 eth0 及 lo 了.
  
  [root@ols3-note
/root]# ifconfig
  eth0   Link encap:Ethernet HWaddr 00:80:C8:8F:B8:F4

       inet addr:192.168.54.51 Bcast:192.168.54.63 Mask:255.255.255.240

       UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
       RX
packets:234 errors:0 dropped:0 overruns:0 frame:0
       TX packets:65
errors:0 dropped:0 overruns:0 carrier:0
       collisions:0 txqueuelen:100

       Interrupt:3 Base address:0x320
  
  lo    Link encap常用网路侦错指令 Sweatocal Loopback
       inet addr:127.0.0.1 Mask:255.0.0.0

       UP LOOPBACK RUNNING MTU:3924 Metric:1
       RX packets:0
errors:0 dropped:0 overruns:0 frame:0
       TX packets:0 errors:0 dropped:0
overruns:0 carrier:0
       collisions:0 txqueuelen:0
  
  二. ping
指令. 
  
  ping 指令用来侦测某一主机是否存活, 或者网路是否可以正常连线.
  
  指令: 

  
  ping IP
  
  ping HOSTNAME
  
  例: ping 192.168.54.49

  
  [root@ols3-note /root]# ping 192.168.54.49
  PING 192.168.54.49
(192.168.54.49): 56 data bytes
  64 bytes from 192.168.54.49: icmp_seq=0
ttl=128 time=0.8 ms
  64 bytes from 192.168.54.49: icmp_seq=1 ttl=128
time=0.7 ms
  64 bytes from 192.168.54.49: icmp_seq=2 ttl=128 time=0.7 ms

  64 bytes from 192.168.54.49: icmp_seq=3 ttl=128 time=0.7 ms
  64 bytes
from 192.168.54.49: icmp_seq=4 ttl=128 time=0.7 ms
  ^C
  ---
192.168.54.49 ping statistics ---
  5 packets transmitted, 5 packets
received, 0% packet loss
  round-trip min/avg/max = 0.7/0.7/0.8 ms

  
  上面表示: 传递5个封包, 5个封包都接收到了, 没有任可 loss 的情形.
  
  icmp 是 ICMP
协定的意思, seq 是序列之意.
  
  TTL 是 Time To Live , 每当经过一个 gateway, TTL 就会减 1,
若某一站的 gateway 收到时, TTL 为 0, 就会送回一个 TimeOut 的讯号回来.
  
  为何只传了5个封包?
因为我中间有按了 ^C, 将 ping 中断了.
  
  若你不想麻烦, 按 ^C, 可以在 ping 执行时加 -c 选项, 用以设定
ping 的次数.
  
  如下:
  
  ping -c 10 192.168.54.49
  
  则只
ping 10 次.
  
  三. netstat 指令. 
  
  netstat 指令用来查看网路介面的使用状况及
routing table.
  
  指令:
  
  netstat -i 
  
  显示网路卡的运作情形:

  
  [root@ols3-note /root]# netstat -i
  Kernel Inte***ce table

  Iface  MTU Met  RX-OK RX-ERR RX-DRP RX-OVR  TX-OK TX-ERR TX-DRP TX-OVR Flg

  eth0  1500  0   682   0   0   0   179   0   0   0 BRU
  lo   3924 
0    0   0   0   0    0   0   0   0 LRU
  
  Iface 是指网路介面
  MTU
前面有介绍过!
  Met 是 Metric 路由权值
  RX 是接收情形
  TX 是传送情形
  OK 表示正常

  ERR 表示错误
  DRP 表示被丢掉的封包数
  OVR 表示 TimeOut 或其它因素
  Flg 是旗标的意思,
其定义如下:
  
  A 接收 multicast 
  B 接收 broadcast 
  D 除错功能已启动 

  L Loopback 
  M 处於不选择状态 
  N 没有处理封包尾端部份 
  O ARP 已关闭 
  P
此介面是做为 point to point 用 
  R 此介面正在运作 
  U 此介面已经启动 

  
  记住上面标有颜色的这四个即可.
  
  
  指令:
  
  netstat -r (等同於
route -e)
  
  查看主机的 routing table.
  
  [root@ols3-note /root]#
netstat -r
  Kernel IP routing table
  Destination   Gateway    
Genmask     Flags  MSS Window irtt Iface
  192.168.54.48  *       
255.255.255.240 U    0 0     0 eth0
  127.0.0.0    *        255.0.0.0   
U    0 0     0 lo
  default     192.168.54.62 0.0.0.0     UG    0 0     0
eth0
  Gateway 若是打 *, 表示 ip 位址由 Iface 所指定的介面传出去.
  
  default 表示
default gateway 之意.
  
  Flags :
  
  U 是启动之意
  
  G 是
Gateway
  
  MSS : TCP Maximum Segment Size 之意
  
  Window : TCP
window size for connections over this route.
  
  irtt : initial round
trip time for TCP connections over this route to ? milliseconds (1-12000). This
is typically only used on AX.25 network.
  
  四. route 指令. 

  
  route 指令用来显示及设定 IP routing table.
  
  语法如下:
  route
[-CFvnee]
  
      route [-v] [-A family] add [-net|-host] target
[netmask
         Nm] [gw Gw] [metric N] [mss M] [window W] [irtt I]

         [reject] [mod] [dyn] [reinstate] [[dev] If]
  
     
route [-v] [-A 
eyke0519
eyke0519
Admin

帖子数 : 10619
注册日期 : 08-12-15

http://eyke.1ercn.com

返回页首 向下

返回页首


 
您在这个论坛的权限:
不能在这个论坛回复主题