news 2026/6/26 16:26:37

ifconfig命令

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
ifconfig命令

ifconfig是我们最常用的查看当前系统的网卡和 ip 地址信息的命令。如果你的机器上还没安装ifconfig命令,可以使用如下命令安装:

yum install net-tools

安装成功以后,我们就可以使用ifconfig查看机器网卡信息了:

[root@localhost ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.206.140 netmask 255.255.255.0 broadcast 192.168.206.255 inet6 fe80::1599:dcc4:b3e8:7fce prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ee:01:80 txqueuelen 1000 (Ethernet) RX packets 1005 bytes 77224 (75.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 349 bytes 47206 (46.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 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 4 bytes 352 (352.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4 bytes 352 (352.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

上述输出显示了机器当前激活的网卡信息及每个网卡(网络设备)的 ipv4、ipv6 地址、子网掩码、广播地址等信息,这里一共两个网卡,分别是ens33lo

我们可以使用-s选项显示网卡信息的精简列表:

[root@localhost ~]# ifconfig -s Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg ens33 1500 1086 0 0 0 379 0 0 0 BMRU lo 65536 4 0 0 0 4 0 0 0 LRU

默认情况下,ifconfig命令只会显示激活的网卡信息,如果要显示所有的(包括未激活)的网卡,我们可以使用-a参数。

如果我们想激活或者禁用某个网卡,可以使用ifconfig upifconfig down命令,用法如下:

ifconfig 网卡名 up ifconfig 网卡名 down

默认情况下,ifconfig命令只会显示激活的网卡信息,如果要显示所有的(包括未激活)的网卡,我们可以使用-a参数。

如果我们想激活或者禁用某个网卡,可以使用ifconfig upifconfig down命令,用法如下:

ifconfig 网卡名 up ifconfig 网卡名 down

我们来演示一下:

[root@localhost ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.206.140 netmask 255.255.255.0 broadcast 192.168.206.255 inet6 fe80::1599:dcc4:b3e8:7fce prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ee:01:80 txqueuelen 1000 (Ethernet) RX packets 1398 bytes 114269 (111.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 601 bytes 97657 (95.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 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 12 bytes 1056 (1.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12 bytes 1056 (1.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ## 禁用网卡 lo 后默认只能看到一个网卡信息 [root@localhost ~]# ifconfig lo down [root@localhost ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.206.140 netmask 255.255.255.0 broadcast 192.168.206.255 inet6 fe80::1599:dcc4:b3e8:7fce prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ee:01:80 txqueuelen 1000 (Ethernet) RX packets 1510 bytes 123232 (120.3 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 657 bytes 104751 (102.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~]# ifconfig -a ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.206.140 netmask 255.255.255.0 broadcast 192.168.206.255 inet6 fe80::1599:dcc4:b3e8:7fce prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ee:01:80 txqueuelen 1000 (Ethernet) RX packets 1543 bytes 125948 (122.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 675 bytes 107251 (104.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=8<LOOPBACK> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 1000 (Local Loopback) RX packets 12 bytes 1056 (1.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12 bytes 1056 (1.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ## 再次启用网卡 lo [root@localhost ~]# ifconfig lo up [root@localhost ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.206.140 netmask 255.255.255.0 broadcast 192.168.206.255 inet6 fe80::1599:dcc4:b3e8:7fce prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ee:01:80 txqueuelen 1000 (Ethernet) RX packets 1615 bytes 131924 (128.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 715 bytes 112423 (109.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 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 12 bytes 1056 (1.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12 bytes 1056 (1.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ifconfig还可以将一个 ip 地址绑定到某个网卡上,或将一个 ip 从某个网卡上解绑,使用如下命令:

ifconfig 网卡名 add ip地址 ifconfig 网卡名 del ip地址

演示如下:

[root@localhost ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.206.140 netmask 255.255.255.0 broadcast 192.168.206.255 inet6 fe80::1599:dcc4:b3e8:7fce prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ee:01:80 txqueuelen 1000 (Ethernet) RX packets 1615 bytes 131924 (128.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 715 bytes 112423 (109.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 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 12 bytes 1056 (1.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12 bytes 1056 (1.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~]# ifconfig ens33 add 192.168.206.150 [root@localhost ~]# ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.206.140 netmask 255.255.255.0 broadcast 192.168.206.255 inet6 fe80::1599:dcc4:b3e8:7fce prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ee:01:80 txqueuelen 1000 (Ethernet) RX packets 1804 bytes 145940 (142.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 781 bytes 119581 (116.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.206.150 netmask 255.255.255.0 broadcast 192.168.206.255 ether 00:0c:29:ee:01:80 txqueuelen 1000 (Ethernet) 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 12 bytes 1056 (1.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12 bytes 1056 (1.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

上述操作中,对于网卡ens33原来绑定了 ip 地址 192.168.206.140,我们使用ifconfig add命令绑定了一个新的 ip :192.168.206.150,现在我们可以使用这个新的 ip 地址来访问原来的网络了。

同理,如果要解绑这个 ip,可以按如下操作:

[root@localhost ~]# ifconfig ens33 del 192.168.206.150 [root@localhost ~]# ifconfig -a ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.206.140 netmask 255.255.255.0 broadcast 192.168.206.255 inet6 fe80::1599:dcc4:b3e8:7fce prefixlen 64 scopeid 0x20<link> ether 00:0c:29:ee:01:80 txqueuelen 1000 (Ethernet) RX packets 2127 bytes 172321 (168.2 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 953 bytes 139954 (136.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 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 18 bytes 1560 (1.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 18 bytes 1560 (1.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/26 16:25:54

【信息科学与工程学】计算机科学与自动化——第二十篇 计算机体系架构 系列三 计算机体系结构01 ISA设计、流水线、超标量、缓存一致性、SIMD/GPU、乱序执行、CPU 设计、GPU设计、性能优化

一、ISA 设计 编号 类型 领域 问题 详细的数学分析 参数列表(表达式 / 范围 / 边界 / 测量) 关联知识 1 设计 ISA 指令集正交性与编码长度最小化 信息论 + 组合优化:以操作码熵 H=−∑pᵢlog₂pᵢ 为下界,约束 ∑lᵢpᵢ ≤ L_avg,Kraft 不等式 ∑2⁻ˡⁱ≤1 保…

作者头像 李华
网站建设 2026/6/26 16:25:41

【GaussDB】权限管理模型:RBAC与ABAC

在数据库安全体系中&#xff0c;权限管理是控制用户访问数据的核心机制。GaussDB支持多种权限控制模型&#xff0c;其中最常见的是基于角色的访问控制&#xff08;RBAC&#xff09;和基于属性的访问控制&#xff08;ABAC&#xff09;。二者在设计理念、灵活性和适用场景上有显著…

作者头像 李华
网站建设 2026/6/26 16:23:42

网盘直链下载助手:一键获取真实下载地址,告别限速烦恼

网盘直链下载助手&#xff1a;一键获取真实下载地址&#xff0c;告别限速烦恼 【免费下载链接】Online-disk-direct-link-download-assistant 一个基于 JavaScript 的网盘文件下载地址获取工具。基于【网盘直链下载助手】修改 &#xff0c;支持 百度网盘 / 阿里云盘 / 中国移动…

作者头像 李华
网站建设 2026/6/26 16:23:32

DLSS Swapper终极指南:如何免费一键提升游戏帧率与画质

DLSS Swapper终极指南&#xff1a;如何免费一键提升游戏帧率与画质 【免费下载链接】dlss-swapper 项目地址: https://gitcode.com/GitHub_Trending/dl/dlss-swapper 你是否曾经在玩最新3A大作时&#xff0c;明明显卡配置不错&#xff0c;但游戏帧率就是上不去&#xf…

作者头像 李华
网站建设 2026/6/26 16:21:44

DLSS Swapper终极指南:3步释放显卡潜能,让游戏帧率飙升50%

DLSS Swapper终极指南&#xff1a;3步释放显卡潜能&#xff0c;让游戏帧率飙升50% 【免费下载链接】dlss-swapper 项目地址: https://gitcode.com/GitHub_Trending/dl/dlss-swapper DLSS Swapper是一款革命性的游戏优化工具&#xff0c;专为NVIDIA显卡用户设计&#xf…

作者头像 李华