轉載自:http://blog.csdn.net/evenness/article/details/7530937
一、ifconfig
用於基本接口與IP配置的ifconfig
ifconfig工具(interface configurator,接口配置器)提供了一些非常基本但是非常重要的功能。它可以打開和關閉網絡適配器,分配IP地址與netmask信息。一些常用指令如下:
查看網絡接口當前配置與接口命名:
ifconfig
打開(up)或關閉(down)適配器
ifconfig <網絡名> <up|down>
爲適配器分配IP地址:
ifconfig <網絡名> <ip地址>
爲適配器分配第二個IP地址:
ifconfig <網絡名:實例數> <ip地址>
範例:ifconfig eth0:0 192.168.1.101
二、ethtool
用於管理以太網卡的ethtool工具
Ethtool可以查看和修改以太適配器的各種設置(不包括Wi-Fi網卡),包括tx/rx,checksumming和wake-on-LAN設置。下面是一些有用的命令:
顯示某個網絡適配器的驅動信息,適用於查詢軟件兼容性的情況:
ethtool -i <接口名>
顯示網絡數據:
ethtool -S
設置適配器連接速度(Mbps)
ethtool speed <10|100|1000>
ethtool 工具有一個-E 指令, 可以通過此指令修改網卡的eeprom. 前提是此網卡驅動編寫了ethtool驅動接口,並具有eeprom.
以intel e1000系列網卡爲例
首先取得e000設備的VenID:DevID, 這個VenID:DevID就是ethtool -E 指令中magic 的參數.
可以分別通過2種方式取得
1> lspci 查看
~# lspci -nn -v |grep "Ethernet Controller"
02:05.0 Ethernet controller [0200]: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) [8086:100f] (rev 01)
命令:
ethtool -E eth0 magic 0x3A8EBEEF offset 0x10 value 0x1A
The Stargate 2 daughter card has a serial EEPROM (AT93C45A) that can store 128 bytes. The MAC address is stored at word offset 0x20 (byte offset 0x40). Ethtool displays the contents of EEPROM. For example:
[root@SG2-21 /root]#ethtool -e eth0 Offset Values ------ ------ 0x0000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0010 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0030 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0040 00 50 c2 2f 30 13 ff ff ff ff ff ff ff ff ff ff 0x0050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0060 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
Ethtool also modifies the EEPROM
[root@SG2-21 /root]#ethtool -E eth0 magic 0x3A8EBEEF offset 0x10 value 0x1A [root@SG2-21 /root]#ethtool -e eth0 Offset Values ------ ------ 0x0000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0010 1a ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0020 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0030 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0040 00 50 c2 2f 30 13 ff ff ff ff ff ff ff ff ff ff 0x0050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0060 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0x0070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
Setting the MAC Address
The MAC address is set with the script /sbin/setMAC. For example,
[root@SG2-21 /root]#setMAC 00:50:C2:2F:30:13 setmac to 00:50:C2:2F:30:13
The script is:
#!/bin/bash echo "setmac to $1" numbers=(`echo $1 | tr ':' ' '`) # echo ${numbers[1]} ethtool -E eth0 magic 0x3A8EBEEF offset 0x40 value 0x${numbers[0]} ethtool -E eth0 magic 0x3A8EBEEF offset 0x41 value 0x${numbers[1]} ethtool -E eth0 magic 0x3A8EBEEF offset 0x42 value 0x${numbers[2]} ethtool -E eth0 magic 0x3A8EBEEF offset 0x43 value 0x${numbers[3]} ethtool -E eth0 magic 0x3A8EBEEF offset 0x44 value 0x${numbers[4]} ethtool -E eth0 magic 0x3A8EBEEF offset 0x45 value 0x${numbers[5]}
The setMAC script is called by px2init during Initial File System Configuration.
三、iwconfig
iwconfig配置無線網絡
iwconfig工具可以算是無線網卡的ifconfig和ethtool。你可以檢查基本的Wi-Fi網絡設置,如SSID、channel和加密等細節。此外還可以修改一些高級設置,包括接收敏感度,RTS/CTS,碎片,以及重試數。下面介紹幾個有用的命令:
顯示當前無線設置,包括接口名稱:
iwconfig
設置ESSID(擴展服務設置識別器)或網絡名:
iwconfig <接口名> essid <網絡名>
範例:iwconfig <接口名> "my network"
範例:Example: iwconfig <接口名> any
設置radio的無線channel(1-11):
iwconfig <接口名> <channel>
輸入WEP加密密鑰(WPA和WPA1尚不支持,需要wpa_supplicant的支持):
iwconfig eth0 key <HEX格式的密鑰>
限制適配器僅能在指定MAC地址下連接到AP:
iwconfig <接口名> ap <mac地址>
範例:iwconfig eth0 ap 00:60:1D:01:23:45
設置radio的發射強度,僅在無線網卡支持的情況下有效。默認單位爲dBm,可設置爲mW:
iwconfig <接口名> txpower <強度>
範例:iwconfig eth0 txpower 15
範例:iwconfig eth0 txpower 30mW
四,tcpdump
用於嗅探網絡包的tcpdump
這不是一個簡單的工具。這是一個嗅探器/分析器。它可以捕捉你的接口中和網絡上傳輸的包。這個工具常常通過其他GUI程序進行調用,不過在terminal下也同樣有用。可以從以下幾個指令開始瞭解:
-i:設置需要捕捉的接口,如eth0或ath0。
-n:停止用主機名稱替換IP地址。
-nn:停止解析主機名或端口名。
-s:每個packet顯示的最大byte數。默認值爲68,設置爲0則顯示整個packet。
v,-vv和-vvv:顯示隨packet輸出的詳細信息,如IP packet的全長度和選項,完全解碼的SMB packet,以及telnet細節。
-x:以HEX格式顯示packet內容。
-X:以ASCII格式輸出packet內容。
五,ping
Ping,你的網絡聲納
Ping工具與微軟在Windows中提供的差不多,不過選項類型和名稱不同。另外,Linux中的Ping在默認情況下會無休止的ping,而不是Windows中的四次。
開始ping一個IP地址或主機名/域名:
ping <ip地址>
要停止ping,使用Ctrl+C。
一些有用的選項包括:
-c:爲發送的packet計數
-i:packet間等待的時間長度,單位爲秒
-s:packet大小,默認爲56
-w:執行ping的時間長度,單位爲秒
六,netstat
檢測網絡數據的netstat
netstat工具可以顯示網絡連接、接口數據、路由表、masquerade連接和multicast成員的詳細信息。常用指令如下:
查看打開的socket列表:
netstat
顯示所有網絡接口:
netstat -i
顯示每個協議的概括情況:
netstat -s
七,hostname
用於查看和修改主機名的hostname
所有管理員都知道主機名(hostname)是什麼東西。主機名是一個相比IP地址而言更加友好的網絡設備顯示方式。Linux當中提供了一個hostname工具,可以讓你暫時修改你的主機名。
查看當前主機名:
hostname
暫時更改主機名(可以維持到重啓之前):
hostname <新的主機名>
若想要永久的更改主機名,則需要編輯/etc/hostname文件或/etc/sysconfig/network文件。
Linux/Unix命令之Ethtool
描述:
Ethtool是用於查詢及設置網卡參數的命令。
概要:
ethtool ethX //查詢ethX網口基本設置
ethtool –h //顯示ethtool的命令幫助(help)
ethtool –i ethX //查詢ethX網口的相關信息
ethtool –d ethX //查詢ethX網口註冊性信息
ethtool –r ethX //重置ethX網口到自適應模式
ethtool –S ethX //查詢ethX網口收發包統計
ethtool –s ethX [speed 10|100|1000]\ //設置網口速率10/100/1000M
[duplex half|full]\ //設置網口半/全雙工
[autoneg on|off]\ //設置網口是否自協商
[port tp|aui|bnc|mii]\ //設置網口類型
[phyad N]\
[xcvr internal|exteral]\
[wol p|u|m|b|a|g|s|d...]\
[sopass xx:yy:zz:aa:bb:cc]\
[msglvl N]
舉例:
1)[root@linux /]# ethtool eth1
NIC statistics:
4)[root@linux /]# ethtool -s eth1 autoneg off speed 100 duplex full
相關:
1)[root@linux /]# which ethtool
/sbin/ethtool
2)[root@linux /]# rpm -qf /sbin/ethtool
ethtool-1.6-5
3)怎樣使ethtool設置永久保存在網絡設備中?
解決方法一:
ethtool設置可通過/etc/sysconfig/network-scripts/ifcfg-ethX文件保存,從而在設備下次啓動時激活選項。
例如:ethtool -s eth0 speed 100 duplex full autoneg off
此指令將eth0設備設置爲全雙工自適應,速度爲100Mbs。若要eth0啓動時設置這些參數, 修改文件/etc/sysconfig/network-scripts/ifcfg-eth0 ,添加如下一行:
ETHTOOL_OPTS="speed 100 duplex full autoneg off"
解決方法二:
將ethtool設置寫入/etc/rc.d/rc.local之中。
二
解決方法:
對Intel千兆網卡禁用自適應時必須指定鏈路速度和全雙工模式。當使用ethtool來禁用使用e1000網卡驅動模塊的網卡自適應特性時,必須同時指定鏈路速度和全雙工工作模式。例如: ethtool -s eth0 autoneg off
會邊比自適應,但是隻是臨時禁用,如果在命令中沒有指定鏈路速度和全雙工工作模式,驅動會自動重新打開自適應。
爲了使用ethtool工具來禁用e1000網卡驅動模塊的網卡自適應特性,使用以下步驟
1. 進入終端模式。 2. 以root身份執行 ethtool -s ethx autoneg off speed 1000 duplex full
這裏ethX是網卡的名字(例如eth0或者eth1等等),這個命令將關閉該網卡的自適應特性,並且強制設置網卡速度爲1Gb,全雙公模式。
另外ethtool比mii-tool要高級,mii-tool只支持 Port: MII的網卡.
- -h
- shows a short help message.
- -a
- queries the specified ethernet device for pause parameter information.
- -A
- change the pause parameters of the specified ethernet device.
- autoneg on|off
- Specify if pause autonegotiation is enabled.
- rx on|off
- Specify if RX pause is enabled.
- tx on|off
- Specify if TX pause is enabled.
- -c
- queries the specified ethernet device for coalescing information.
- -C
- change the coalescing settings of the specified ethernet device.
- -g
- queries the specified ethernet device for rx/tx ring parameter information.
- -G
- change the rx/tx ring parameters of the specified ethernet device.
- rx N
- Change number of ring entries for the Rx ring.
- rx-mini N
- Change number of ring entries for the Rx Mini ring.
- rx-jumbo N
- Change number of ring entries for the Rx Jumbo ring.
- tx N
- Change number of ring entries for the Tx ring.
- -i
- queries the specified ethernet device for associated driver information.
- -d
- retrieves and prints a register dump for the specified ethernet device.
- -e
- retrieves and prints an EEPROM dump for the specified ethernet device.
- -k
- queries the specified ethernet device for checksumming information.
- -K
- change the checksumming parameters of the specified ethernet device.
- rx on|off
- Specify if RX checksumming is enabled.
- tx on|off
- Specify if TX checksumming is enabled.
- sg on|off
- Specify if scatter-gather is enabled.
- -p
- initiates adapter-specific action intended to enable an operator to easily identify the adapter by sight. typically this involves blinking one or more LEDs on the specific ethernet port.
- N
- Length of time to perform phys-id, in seconds.
- -r
- restarts auto-negotiation on the specified ethernet device, if auto-negotiation is enabled.
- -S
- queries the specified ethernet device for NIC- and driver-specific statistics.
- -t
- executes adapter selftest on the specified ethernet device. Possible test modes are:
- offline|online
- defines test type: offline (default) means to perform full set of tests possibly causing normal operation interruption during the tests, online means to perform limited set of tests do not interrupting normal adapter operation.
- -s
- option allows changing some or all settings of the specified ethernet device. All following options only apply if -s was specified.
- speed 10|100|1000
- Set speed in Mb/s. ethtool with single argument will show you the supported device speeds.
- duplex half|full
- Set full or half duplex mode.
- port tp|aui|bnc|mii
- Select device port.
- autoneg on|off
- Specify if autonegotiation is enabled. In the usual case it is, but might cause some problems with some network devices, so you can turn it off.
- phyad N
- PHY address.
- xcvr internal|external
- Select transceiver type. Currently only internal and external can be specified, in the future further types might be added.
- wol p|u|m|b|a|g|s|d...
-
Set Wake-on-LAN options. Not all devices support this. The argument to this option is a string of characters specifying which options to enable.
-
-
- p
- Wake on phy activity
- u
- Wake on unicast messages
- m
- Wake on multicast messages
- b
- Wake on broadcast messages
- a
- Wake on ARP
- g
- Wake on MagicPacket(tm)
- s
- Enable SecureOn(tm) password for MagicPacket(tm)
- d
- Disable (wake on nothing). This option clears all previous options.
-
- sopass xx:yy:zz:aa:bb:cc
- Set the SecureOn(tm) password. The argument to this option must be 6 bytes in ethernet MAC hex format (xx:yy:zz:aa:bb:cc).
- msglvl N
- Set the driver message level. Meanings differ per driver
改變網絡接口的速度和協商方式的工具miitool 和ethtool
#ethtool -s eth0 duplex full
alias eth0 bcm5700 line_speed=100 full_duplex=1
options bcm5700 line_speed=100 full_duplex=1
重起!
usage: mii-tool [-VvRrwl] [-A media,... | -F media] [interface ...]
-V, --version display version information
-v, --verbose more verbose output 注:顯示網絡接口的信息;
-R, --reset reset MII to poweron state 注:重設MII到開啓狀態;
-r, --restart restart autonegotiation 注:重啓自動協商模式;
-w, --watch monitor for link status changes 注:查看網絡接口連接的狀態變化;
-l, --log with -w, write events to syslog 注:寫入事件到系統日誌;
-A, --advertise=media,... advertise only specified media 注:指令特定的網絡接口;
-F, --force=media force specified media technology 注:更改網絡接口協商方式;
media: 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD,
(to advertise both HD and FD) 100baseTx, 10baseT
Settings for eth0:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised auto-negotiation: No 注:自動協商關閉
Speed: 100Mb/s 注:速度 100Mb
Duplex: Full 注:全雙工
Port: MII
PHYAD: 32
Transceiver: internal
Auto-negotiation: off
Supports Wake-on: pumbg
Wake-on: d
Current message level: 0x00000007 (7)
Link detected: yes 注:eth0已經激活;
[ speed 10|100|1000 ] \
[ duplex half|full ] \
[ port tp|aui|bnc|mii|fibre ] \
[ autoneg on|off ] \