一. ifconfig 指令.
ifconfig 指令用來(lái)設(shè)定網(wǎng)路介面, 并可查詢目前網(wǎng)路介面的設(shè)定情形. 語(yǔ)法: 1. ifconfig [介面] 介面可以不寫, 若不寫, 則顯示目前使用中的介面. 介面可以填入: eth0, eth1 等. 若是下 2. ifconfig -a 則會(huì)列出所有的網(wǎng)路介面情形. [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 表示第一張網(wǎng)路卡 lo 表示 loopback , 即沒(méi)有連接到真實(shí)網(wǎng)路時(shí)的網(wǎng)路介面, 可用來(lái)測(cè)試網(wǎng)路的應(yīng)用軟體, 并且提供區(qū)域性的 TCP/IP 服務(wù). HWaddr 是網(wǎng)路卡的硬體位址 inet addr 是網(wǎng)路卡的 IP, Bcast 是廣播(broadcast) 的位址 Mask 是網(wǎng)路遮罩. MTU 是 Maximum Trasmission Unit 最大傳輸單元(位元組), 即此介面一次所能傳輸?shù)淖畲蠓獍? Metric 是權(quán)值之意, 路由權(quán)值, 或所需的花費(fèi), 目前尚未使用, 將來(lái)會(huì) implement. RX 是接收情形. TX 是傳送情形. collisions 是網(wǎng)路訊號(hào)碰撞的意思 txqueuelen 是傳輸緩區(qū)長(zhǎng)度大小意思 Interrupt 是 IRQ 中斷位址 Base address 是 I/O 位址 3. ifconfig 介面 [aftype] 選項(xiàng) | 位址 aftype 是位址家族之意, 預(yù)設(shè)值是 inet (TCP/IP) 其它還有 ddp(AppleTalk) ipx(Novell) 詳細(xì)情形, 請(qǐng)自行 man ifconfig 不建議各位用 ifconfig 手動(dòng)修改, 請(qǐng)用 linuxconf 較佳. 不過(guò), 在查驗(yàn)為何網(wǎng)路不通時(shí), 經(jīng)常會(huì)遇到的問(wèn)題是 netmask 設(shè)錯(cuò)了, 這時(shí), 手動(dòng)設(shè) netmask 倒是十分方便的方法. 假設(shè) netmask 應(yīng)為 255.255.255.128, 但你的網(wǎng)路卡卻是 255.255.255.0 那麼下: ifconfig eth0 netmask 255.255.255.128 即可改正過(guò)來(lái). ifconfig eth0 down 可將網(wǎng)路卡關(guān)閉, 此時(shí)下 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 可將網(wǎng)路卡打開(kāi), 下 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 指令用來(lái)偵測(cè)某一主機(jī)是否存活, 或者網(wǎng)路是否可以正常連線. 指令: 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個(gè)封包, 5個(gè)封包都接收到了, 沒(méi)有任可 loss 的情形. icmp 是 ICMP 協(xié)定的意思, seq 是序列之意. TTL 是 Time To Live , 每當(dāng)經(jīng)過(guò)一個(gè) gateway, TTL 就會(huì)減 1, 若某一站的 gateway 收到時(shí), TTL 為 0, 就會(huì)送回一個(gè) TimeOut 的訊號(hào)回來(lái). 為何只傳了5個(gè)封包? 因?yàn)槲抑虚g有按了 ^C, 將 ping 中斷了. 若你不想麻煩, 按 ^C, 可以在 ping 執(zhí)行時(shí)加 -c 選項(xiàng), 用以設(shè)定 ping 的次數(shù). 如下: ping -c 10 192.168.54.49 則只 ping 10 次. 三. netstat 指令. netstat 指令用來(lái)查看網(wǎng)路介面的使用狀況及 routing table. 指令: netstat -i 顯示網(wǎng)路卡的運(yùn)作情形: [root@ols3-note /root]# netstat -i Kernel Interface 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 是指網(wǎng)路介面 MTU 前面有介紹過(guò)! Met 是 Metric 路由權(quán)值 RX 是接收情形 TX 是傳送情形 OK 表示正常 ERR 表示錯(cuò)誤 DRP 表示被丟掉的封包數(shù) OVR 表示 TimeOut 或其它因素 Flg 是旗標(biāo)的意思, 其定義如下: A 接收 multicast B 接收 broadcast D 除錯(cuò)功能已啟動(dòng) L Loopback M 處?kù)恫贿x擇狀態(tài) N 沒(méi)有處理封包尾端部份 O ARP 已關(guān)閉 P 此介面是做為 point to point 用 R 此介面正在運(yùn)作 U 此介面已經(jīng)啟動(dòng) 記住上面標(biāo)有顏色的這四個(gè)即可. 指令: netstat -r (等同於 route -e) 查看主機(jī)的 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 所指定的介面?zhèn)鞒鋈? default 表示 default gateway 之意. Flags : U 是啟動(dòng)之意 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 指令用來(lái)顯示及設(shè)定 IP routing table. 語(yǔ)法如下: 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 |
|
來(lái)自: funronglei > 《我的圖書館》