嵌入式网络调试命令 ifconfig 介绍及使用方法

发布于:2024-08-08 ⋅ 阅读:(155) ⋅ 点赞:(0)

网络调试命令

1、ifconfig 命令

作用:linux 中用于显示或配置网络接口(网卡、网络设备)信息的命令。

**介绍:**在 linux 系统中,网卡的命名规则:eth0 为第一块以太网卡(Ethernet Card),eth1 为第二块。

lo (loopback) 为回环接口,IP 地址固定为 127.0.0.1,掩码255.0.0.0 (8位)。它是一个虚拟的网络接口,通常用于对本机的网络测试。

虚拟网络接口:并非真实存在,并不真实的从外界接受和发送数据包,而是在系统内部接受和发送数据包,因此虚拟网络接口不需要驱动程序。

(1)查看网络接口信息,启用禁用网络接口(以 eth0 为例)

**ifconfig -a:**显示所有的网络接口信息,不管是否激活。

**ifconfig:**这个命令显示所有激活的网络接口的信息。

**ifconfig eth0 :**查看网络接口 eth0 信息。

ifconfig eth0 up 启用网络接口 eth0

**ifconfig eth0 down :**禁用网络接口 eth0

# 查看所有网络接口信息
ifconfig
# 查看网络接口 eth0 信息
ifconfig eth0
# 启用网络接口 eth0
ifconfig eth0 up
# 禁用网络接口 eth0
ifconfig eth0 down

使用 ifconfig -a 示例:

ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:00:00:00:00:00 
          BROADCAST MULTICAST  MTU:1500  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:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:62 Base address:0x4000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  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 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

参数解释:
eth0:网络接口
link encap:网络类型
HWaddr:网卡物理地址
Inet addr :IP地址
Bcast:广播地址
Mask:子网掩码
UP:正在使用的网络接口
RX packets,TX packets接收和传输的数据包个数
RX byte,TX byte表示接搜和传输的具体数目
Interrupt:终端信息
Base address:内存地址

(2)设置 IP 地址、MAC 地址和子网掩码

ifconfig eth0 192.168.1.100 为网络接口 eth0 设置 IP 地址

ifconfig eth0 netmask 255.255.255.0 为网络接口 eth0 设置子网掩码

**ifconfig eth0 broadcast 192.168.1.255:**为网络接口 eth0 设置广播地址

**ifconfig eth0 hw ether 00:1a:2b:3c:4d:5e:**为网络接口 eth0 设置 MAC 地址

ifconfig eth0 192.168.1.100
ifconfig eth0 netmask 255.255.255.0
ifconfig eth0 broadcast 192.168.1.255
ifconfig eth0 hw ether 00:1a:2b:3c:4d:5e

网站公告

今日签到

点亮在社区的每一天
去签到