20220419-ifconfig
ifconfig解析
0. 具体示例说明
ifconfig
用于显示网络设备信息;执行命令后显示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:0A:0B:0C
inet addr:192.168.0.3 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:fe0a:b0c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:172220 errors:0 dropped:0 overruns:0 frame:0
TX packets:132379 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:87101880 (83.0 MiB) TX bytes:41576123 (39.6 MiB)
Interrupt:185 Base address:0x2024
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2022 errors:0 dropped:0 overruns:0 frame:0
TX packets:2022 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2459063 (2.3 MiB) TX bytes:2459063 (2.3 MiB)分析说明:
eth0 Link encap:Ethernet HWaddr 00:50:56:0A:0B:0C
eth0
:网卡名称;Link encap:Ethernet
:连接类型,这里是以太网(Ethernet);HWaddr 00:50:56:0A:0B:0C
:网卡物理地址(MAC地址);
inet addr:192.168.0.3 Bcast:192.168.0.255 Mask:255.255.255.0
:inet addr
:网卡的IPv4地址;Bcast
:广播地址;Mask
:子网掩码;
inet6 addr: fe80::250:56ff:fe0a:b0c/64 Scope:Link
:inet6 addr
:网卡的IvP6地址;
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
:UP
:表明接口已启用;BROADCAST
:表明主机支持广播;RUNNING
:表明接口在工作中;MULTICAST
:表明主机支持多播;MTU:1500
:最大传输单元为1500字节;
RX packets:172220 errors:0 dropped:0 overruns:0 frame:0
:RX packets
:接收到的正确数据包数;RX errors
:接收到的产生错误的数据包数;RX dropped
:接收到的丢弃的数据包数;RX overruns
:接收到的由于速度过快而丢失的数据包数;RX frame
:接收到的发生frame
错误而丢失的数据包数;
TX packets:132379 errors:0 dropped:0 overruns:0 carrier:0
:TX packets
:发送时正确数据包数;TX errors
:发送时产生错误的数据包数;TX dropped
:发送时的丢弃的数据包数;TX overruns
:发送时由于速度过快而丢失的数据包数;TX carrier
:发送时发生carrier
错误而丢失的数据包数;
collisions:0 txqueuelen:1000
:collisions
:冲突信息包的数目;txqueuelen
:网卡设置的传送队列长度;
RX bytes:87101880 (83.0 MiB) TX bytes:41576123 (39.6 MiB)
:RX bytes
:接收的数据量;TX bytes
:发送的数据量;
Interrupt:185 Base address:0x2024
:
1. 命令实例
ifconfig
:显示激活的网卡信息;ifconfig -a
:显示所有的网卡信息;ifconfig -s
:显示简要的网卡信息;ifconfig eth0 down
或ifdown eth0
:关闭网卡;ifconfig eth0 up
或ifup eth0
:启动网卡;为网卡配置和删除IPv6地址:
1
2ifconfig eth0 add 3ffe:3240:800:1005::2/64
ifconfig eth0 del 3ffe:3240:800:1005::2/64
修改MAC地址:
ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE
;配置IP地址:
1
2
3
4
5
6
7
8# 配置ip地址
ifconfig eth0 192.168.1.100
# 配置ip地址和子网掩码
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
# 配置ip地址、子网掩码和广播地址
ifconfig eth0 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255单网卡添加多个IP地址:
1
2ifconfig eth0:0 192.168.1.100 netmask 255.255.255.0 up
ifconfig eth0:1 192.168.2.100 netmask 255.255.255.0 up删除IP地址:
ifconfig eth0 del 192.168.1.100
;启动和关闭ARP协议:
ifconfig eth0 arp
和ifconfig eth0 -arp
;设置最大传输单元:
ifconfig eth0 mtu 1500
;启用和关闭网卡的promiscuous模式:
ifconfig eth0 promisc
和ifconfig eth0 -promisc
;启用和关闭网卡的多播模式:
ifconfig eth0 allmulti
和ifconfig eth0 -allmulti
;