ifconfig, ping, ethtool, iperf的使用
root@imx8mpevk:~# ifconfig -a
can0: flags=128<NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 231
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.100.20 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::204:9fff:fe08:55ee prefixlen 64 scopeid 0x20<link>
ether 00:04:9f:08:55:ee txqueuelen 1000 (Ethernet)
RX packets 108581 bytes 140666934 (134.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 36147 bytes 8210634 (7.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=-28669<UP,BROADCAST,MULTICAST,DYNAMIC> mtu 1500
ether 00:04:9f:08:55:ef txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 223
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 1549 bytes 96683 (94.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1549 bytes 96683 (94.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Can0是CAN接口的网卡。可以看到网络接口有三个网卡:eth0,eth1和lo,当前使用的是eth0,其ip地址为192.168.100.20,MAC地址为00:04:9f:08:55:ee,eth1没有插网线,所以没有显示ip地址,lo是回环测试网卡。如果系统启动后eth0没有网址(比如用busybox制作的文件系统),可以使用ifconfig eth0 xxxx命令来设置或修改网址。
2. ping命令验证网络接口
首先cat /proc/cmdline查看主机ip地址
root@imx8mpevk:~# cat /proc/cmdline
console=ttymxc1,115200 root=/dev/nfs ip=dhcp nfsroot=192.168.100.250:/opt/REAL/NFS/IMX8MPEVK-4-root,v3,tcp
可以看到主机ip地址为192.168.100.250,使用ping命令如下:
root@imx8mpevk:~# ping 192.168.100.250
PING 192.168.100.250 (192.168.100.250) 56(84) bytes of data.
64 bytes from 192.168.100.250: icmp_seq=1 ttl=64 time=1.06 ms
64 bytes from 192.168.100.250: icmp_seq=2 ttl=64 time=1.37 ms
64 bytes from 192.168.100.250: icmp_seq=3 ttl=64 time=1.37 ms
^C
--- 192.168.100.250 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 1.063/1.265/1.367/0.143 ms
可以看到收发包的统计,说明板子和主机是通信成功的(板子启动是通过nfs,所以板子和主机网络是通的,因为板子没有连接外网,所以ping外网会失败)
3. ethtool获取或修改以太网卡的信息或修改参数配置
root@imx8mpevk:~# ethtool eth0
Settings for eth0:
Supported ports: [ TP MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: Symmetric
Supports auto-negotiation: Yes
Supported FEC modes: Not reported
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: Symmetric
Advertised auto-negotiation: Yes
Advertised FEC modes: Not reported
Link partner advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Link partner advertised pause frame use: No
Link partner advertised auto-negotiation: Yes
Link partner advertised FEC modes: Not reported
Speed: 1000Mb/s
Duplex: Full
Auto-negotiation: on
master-slave cfg: preferred slave
master-slave status: slave
Port: Twisted Pair
PHYAD: 1
Transceiver: external
MDI-X: Unknown
Supports Wake-on: g
Wake-on: d
Link detected: yes
ethtool eth0可以看到输出信息中Speed: 1000Mb/s表明这是一个千兆网卡,Auto-negotiation: on说明和主机之间是自动协商的状态。ethtool常用命令:
ethtool -i eth0 显示网卡driver名字,对于Linux内核版本等信息。
ethtool -S eth0 查看网卡在接收/发送数据时,有没有出错等。
ethtool -s eth0 speed 10 duplex full autoneg on修改网卡设置,此命令设置速度为10M、全双工、打开自动协商
4. 使用iperf往主机端发送网路流:
Iperf是服务器端和客户端收发数据流的测试工具。下面以板子做客户端,主机做服务器端为例:
iperf -c 192.168.100.33 -t 600 -i 1 -u -b 1000M
-c: 指定要连接的服务器端ip地址
-t : 测试时间
-i : 时间间隔
-u: 测试udp
-b: 最大测试带宽
root@imx8mpevk:~# iperf -c 192.168.100.33 -t 600 -i 1 -u -b 1000M
------------------------------------------------------------
Client connecting to 192.168.100.33, UDP port 5001
Sending 1470 byte datagrams, IPG target: 11.22 us (kalman adjust)
UDP buffer size: 12.0 MByte (default)
------------------------------------------------------------
[ 3] local 192.168.100.20 port 37634 connected with 192.168.100.33 port 5001
[ ID] Interval Transfer Bandwidth
[ 3] 0.0- 1.0 sec 125 MBytes 1.05 Gbits/sec
[ 3] 1.0- 2.0 sec 125 MBytes 1.05 Gbits/sec
[ 3] 2.0- 3.0 sec 125 MBytes 1.05 Gbits/sec
[ 3] 3.0- 4.0 sec 125 MBytes 1.05 Gbits/sec
[ 3] 4.0- 5.0 sec 125 MBytes 1.05 Gbits/sec
[ 3] 5.0- 6.0 sec 125 MBytes 1.05 Gbits/sec
[ 3] 6.0- 7.0 sec 125 MBytes 1.05 Gbits/sec
^C[ 3] WARNING: did not receive ack of last datagram after 10 tries.
[ 3] 0.0- 7.6 sec 950 MBytes 1.05 Gbits/sec
[ 3] Sent 677488 datagrams