linux:ip link 用法详解
2023-12-21 00:06:23
1. 描述
该命令用于管理和查看网络接口,link 表示 link layer 的意思,即链路层
2. 语法
ip link help
# 以下是输出:
Usage: ip link add [link DEV] [ name ] NAME
[ txqueuelen PACKETS ]
[ address LLADDR ]
[ broadcast LLADDR ]
[ mtu MTU ] [index IDX ]
[ numtxqueues QUEUE_COUNT ]
[ numrxqueues QUEUE_COUNT ]
type TYPE [ ARGS ]
ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ]
ip link set { DEVICE | dev DEVICE | group DEVGROUP }
[ { up | down } ]
[ type TYPE ARGS ]
[ arp { on | off } ]
[ dynamic { on | off } ]
[ multicast { on | off } ]
[ allmulticast { on | off } ]
[ promisc { on | off } ]
[ trailers { on | off } ]
[ carrier { on | off } ]
[ txqueuelen PACKETS ]
[ name NEWNAME ]
[ address LLADDR ]
[ broadcast LLADDR ]
[ mtu MTU ]
[ netns { PID | NAME } ]
[ link-netns NAME | link-netnsid ID ]
[ alias NAME ]
[ vf NUM [ mac LLADDR ]
[ vlan VLANID [ qos VLAN-QOS ] [ proto VLAN-PROTO ] ]
[ rate TXRATE ]
[ max_tx_rate TXRATE ]
[ min_tx_rate TXRATE ]
[ spoofchk { on | off} ]
[ query_rss { on | off} ]
[ state { auto | enable | disable} ]
[ trust { on | off} ]
[ node_guid EUI64 ]
[ port_guid EUI64 ] ]
[ { xdp | xdpgeneric | xdpdrv | xdpoffload } { off |
object FILE [ section NAME ] [ verbose ] |
pinned FILE } ]
[ master DEVICE ][ vrf NAME ]
[ nomaster ]
[ addrgenmode { eui64 | none | stable_secret | random } ]
[ protodown { on | off } ]
[ protodown_reason PREASON { on | off } ]
[ gso_max_size BYTES ] | [ gso_max_segs PACKETS ]
ip link show [ DEVICE | group GROUP ] [up] [master DEV] [vrf NAME] [type TYPE]
ip link xstats type TYPE [ ARGS ]
ip link afstats [ dev DEVICE ]
ip link property add dev DEVICE [ altname NAME .. ]
ip link property del dev DEVICE [ altname NAME .. ]
ip link help [ TYPE ]
TYPE := { bareudp | bond | bond_slave | bridge | bridge_slave |
dummy | erspan | geneve | gre | gretap | ifb |
ip6erspan | ip6gre | ip6gretap | ip6tnl |
ipip | ipoib | ipvlan | ipvtap |
macsec | macvlan | macvtap |
netdevsim | nlmon | rmnet | sit | team | team_slave |
vcan | veth | vlan | vrf | vti | vxcan | vxlan | xfrm }
2.1 参数
ip link set DEVICE { up | down | arp { on | off } | name NEWNAME | address LLADDR }
可选的 option:
- dev DEVICE:指定要操作的设备名
- up and down:启动或停用该设备
- arp on or arp off:启用或禁用该设备的arp协议
- name NAME:修改指定设备的名称,建议不要在该接口处于运行状态或已分配IP地址时重命名
- address LLADDRESS:设置指定接口的MAC地址
ip [ -s | -h | -d ] link show [dev DEV]
可选的 option:
-s[tatistics]:将显示各网络接口上的流量统计信息;
-h[uman-readable]:以人类可读的方式显式,即单位转换;
-d[etails]:显示详细信息
(选项说明可以通过ip help查看)
2.2 例子
停用 eth1网卡:
~ # ip link set eth1 down
启用 eth1网卡:
~ # ip link set eth1 up
等价于:
~ # ifconfig eth1 down 或 ifconfig eth1 up
~ # ip -s -h -d link show dev eth0
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:2c:3c:e0 brd ff:ff:ff:ff:ff:ff promiscuity 0 minmtu 46 maxmtu 16110 addrgenmode none numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535
RX: bytes packets errors dropped missed mcast
507M 1.47M 0 0 0 0
TX: bytes packets errors dropped carrier collsns
370M 1.24M 0 0 0 0
~ #
字段含义:
BROADCAST:支持广播
MULTICAST:支持组播
UP:代表网卡开启状态;如果是关闭状态则不显示UP(重要)
LOWER_UP:代表网卡的网线被接上
mtu 1500:网络接口的最大传输单元(Maximum Transmission Unit ):1500字节。是包或帧的最大长度,一般以字节记。
qdisc:排队规则
state UNKNOWN :
mode DEFAULT :
group default :
qlen 1000:
link/ether 00:0c:29:2c:3c:e0 表示物理网卡地址
brd ff:ff:ff:ff:ff:ff
文章来源:https://blog.csdn.net/qq_36803941/article/details/135118111
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!