无线网卡的查看与配置——iw,iwconfig,ethtool

时间:2023-03-09 00:21:49
无线网卡的查看与配置——iw,iwconfig,ethtool

摘要:在linux上,我们经常需要把一台笔记本设置成一个共享wifi上网的路由器。如果我们需要把本机配置成一台无线AP,就需要查看网卡的相关信息和进行对应配置。其中iw、iwconfig和ethtool三个命令可以有效帮助我们完成这些问题。

1. iw

命令简介: iw - show / manipulate wireless devices and their configuration

用法:

$ iw wlan0 info
Interface wlan0
ifindex 3
type managed
wiphy 2

其中,wlan0这个无限网卡,设备索引号是3,链接类型是managed(单点对ap的连接模式),wiphy类型是2.

2.iwconfig

命令简介: iwconfig - configure a wireless network interface

用法:

用法: iwconfig interface [essid {NN|on|off}]
[nwid {NN|on|off}]
[mode {managed|ad-hoc|...}
[freq N.NNNN[k|M|G]]
[channel N]
[ap {N|off|auto}]
[sens N]
[nick N]
[rate {N|auto|fixed}]
[rts {N|auto|fixed|off}]
[frag {N|auto|fixed|off}]
[enc {NNNN-NNNN|off}]
[power {period N|timeout N}]
[retry {limit N|lifetime N}]
[txpower N {mW|dBm}]
[commit]

示例:

essid设置:#iwconfig eth0 essid any 允许任何ESSID,也就是混杂模式

nickname设置:#iwconfig eth0 nickname "My Linux Node"

工作模式设置:#iwconfig eth0 mode Managed(注意,不是所有的网卡都能支持所有的工作模式)

3、ethtool

命令简介: ethtool - query or control network driver and hardware settings

命令用法:

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]

使用实例:

举例:
0)查看网卡驱动等信息:
hyk@hyk-linux:~
$ ethtool -i wlan0
driver: iwlwifi
version: 3.10.9
firmware-version: 39.31.5.1 build 35138
bus-info: 0000:08:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
1)[root@linux /]# ethtool eth1
Settings for eth1:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: umbg
Wake-on: d
Link detected: yes
2)[root@linux /]# ethtool -i eth1
driver: e1000
version: 5.0.43-k1
firmware-version: N/A
bus-info: 06:08.1
3)[root@linux /]# ethtool -S eth1
NIC statistics:
rx_packets: 58068300
tx_packets: 87124083
rx_bytes: 1589713008
tx_bytes: 2165825901
rx_errors: 0
tx_errors: 0
rx_dropped: 0
tx_dropped: 0
multicast: 0
collisions: 0
rx_length_errors: 0
rx_over_errors: 0
rx_crc_errors: 0
rx_frame_errors: 0
rx_fifo_errors: 0
rx_missed_errors: 0
tx_aborted_errors: 0
tx_carrier_errors: 0
tx_fifo_errors: 0
tx_heartbeat_errors: 0
tx_window_errors: 0
4)[root@linux /]# ethtool -s eth1 autoneg off speed 100 duplex full