ifconfig(network interfaces configuring)
命令用于查询和设置 Linux 网络网络接口的命令。
介绍
ifconfig
查看网卡包、丢失等统计信息,类似的命令 netstat -i
help
ifconfig --help
Usage:
ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
[add <address>[/<prefixlen>]]
[del <address>[/<prefixlen>]]
[[-]broadcast [<address>]] [[-]pointopoint [<address>]]
[netmask <address>] [dstaddr <address>] [tunnel <address>]
[outfill <NN>] [keepalive <NN>]
[hw <HW> <address>] [mtu <NN>]
[[-]trailers] [[-]arp] [[-]allmulti]
[multicast] [[-]promisc]
[mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]
[txqueuelen <NN>]
[name <newname>]
[[-]dynamic]
[up|down] ...
<HW>=Hardware Type.
List of possible hardware types:
loop (Local Loopback) slip (Serial Line IP) cslip (VJ Serial Line IP)
slip6 (6-bit Serial Line IP) cslip6 (VJ 6-bit Serial Line IP) adaptive (Adaptive Serial Line IP)
ash (Ash) ether (Ethernet) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) rose (AMPR ROSE) tunnel (IPIP Tunnel)
ppp (Point-to-Point Protocol) hdlc ((Cisco)-HDLC) lapb (LAPB)
arcnet (ARCnet) dlci (Frame Relay DLCI) frad (Frame Relay Access Device)
sit (IPv6-in-IPv4) fddi (Fiber Distributed Data Interface) hippi (HIPPI)
irda (IrLAP) ec (Econet) x25 (generic X.25)
eui64 (Generic EUI-64)
<AF>=Address family. Default: inet
List of possible address families:
unix (UNIX Domain) inet (DARPA Internet) inet6 (IPv6)
ax25 (AMPR AX.25) netrom (AMPR NET/ROM) rose (AMPR ROSE)
ipx (Novell IPX) ddp (Appletalk DDP) ec (Econet)
ash (Ash) x25 (CCITT X.25)
# 给eth0网卡配置IP地址
ifconfig eth0 192.168.1.2
# 给eth0网卡配置IP地址,并加上子掩码
ifconfig eth0 192.168.1.2 netmask 255.255.255.0
# 给eth0网卡配置IP地址,加上子掩码,加上个广播地址
ifconfig eth0 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255
# 设置最大传输单元
ifconfig eth0 mtu 1500
# 关闭网卡
ifconfig eth0 down
# 启动网卡
ifconfig eth0 up
# 修改MAC地址
ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE
# 为网卡设置IPv6地址
ifconfig eth0 add 33ffe:3240:800:1005::2/ 64
# 为网卡删除IPv6地址
ifconfig eth0 del 33ffe:3240:800:1005::2/ 64
# 开启网卡eth0的arp协议
ifconfig eth0 arp
# 关闭网卡eth0的arp协议
ifconfig eth0 -arp
demo
$ ifconfig
...
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.248.200 netmask 255.255.240.0 broadcast 172.16.255.255
inet6 fe80::216:3eff:fe0a:2273 prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:0a:22:73 txqueuelen 1000 (Ethernet)
RX packets 162135253 bytes 26534203479 (26.5 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 200958763 bytes 458914286818 (458.9 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
# 设置网卡为混杂模式
$ ifconfig eth0 promisc
# 取消混杂模式
$ ifconfig eth0 -promisc
说明:
- UP 表示该网卡处于启动状态
- BROADCAST 表示该网卡有广播地址,可以发送广播包
- MULTICAST 表示该网卡可以发送多播包
- LOWER_UP 表示 L1 是启动的,也就是网线正插着呢
NO-CARRIER
网线连接不良或者网线故障
mtu 1500
最大传输单元 MTU 为 1500 字节,1500 是以太网的默认值
qdisc pfifo_fast
- qdisc 的全称为
queuing discipline(排队规则)
- 计算机如果需要通过网络接口发送数据包,都需要按照这个接口的排队规则进行排序
- 最简单的排序规则就是 pfifo,也即先入先出的队列形式
- pfifo_fast 在 pfifo 的基础上,分为了三个波段(数据包按照 Type of Service(服务类型)分入 band),其中 band0 的优先级最高,band2 的优先级最低