-
常用網路偵錯指令
一
. 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:Local 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:Local 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:Local 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