ifconfig命令

发布时间:2026/10/5 21:31:00
ifconfig命令 ifconfig是我们最常用的查看当前系统的网卡和 ip 地址信息的命令。如果你的机器上还没安装ifconfig命令可以使用如下命令安装yum install net-tools安装成功以后我们就可以使用ifconfig查看机器网卡信息了[rootlocalhost ~]# ifconfig ens33: flags4163UP,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 0x20link 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: flags73UP,LOOPBACK,RUNNING mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10host 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 地址、子网掩码、广播地址等信息这里一共两个网卡分别是ens33和lo。我们可以使用-s选项显示网卡信息的精简列表[rootlocalhost ~]# 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 up和ifconfig down命令用法如下ifconfig 网卡名 up ifconfig 网卡名 down默认情况下ifconfig命令只会显示激活的网卡信息如果要显示所有的包括未激活的网卡我们可以使用-a参数。如果我们想激活或者禁用某个网卡可以使用ifconfig up和ifconfig down命令用法如下ifconfig 网卡名 up ifconfig 网卡名 down我们来演示一下[rootlocalhost ~]# ifconfig ens33: flags4163UP,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 0x20link 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: flags73UP,LOOPBACK,RUNNING mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10host 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 后默认只能看到一个网卡信息 [rootlocalhost ~]# ifconfig lo down [rootlocalhost ~]# ifconfig ens33: flags4163UP,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 0x20link 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 [rootlocalhost ~]# ifconfig -a ens33: flags4163UP,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 0x20link 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: flags8LOOPBACK 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 [rootlocalhost ~]# ifconfig lo up [rootlocalhost ~]# ifconfig ens33: flags4163UP,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 0x20link 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: flags73UP,LOOPBACK,RUNNING mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10host 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 0ifconfig还可以将一个 ip 地址绑定到某个网卡上或将一个 ip 从某个网卡上解绑使用如下命令ifconfig 网卡名 add ip地址 ifconfig 网卡名 del ip地址演示如下[rootlocalhost ~]# ifconfig ens33: flags4163UP,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 0x20link 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: flags73UP,LOOPBACK,RUNNING mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10host 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 [rootlocalhost ~]# ifconfig ens33 add 192.168.206.150 [rootlocalhost ~]# ifconfig ens33: flags4163UP,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 0x20link 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: flags4163UP,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: flags73UP,LOOPBACK,RUNNING mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10host 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可以按如下操作[rootlocalhost ~]# ifconfig ens33 del 192.168.206.150 [rootlocalhost ~]# ifconfig -a ens33: flags4163UP,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 0x20link 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: flags73UP,LOOPBACK,RUNNING mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10host 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

关于本文作者

来自尧图内容编辑团队

尧图内容编辑团队 内容团队

尧图内容编辑团队

本文由尧图网络内容编辑团队执笔。团队由资深项目经理、前端工程师与设计师组成,所有内容均来自亲手交付的真实项目,先讲清问题、再给出可落地的解法。尧图深耕北京网站建设十年,服务过京华建材集团、智造科技等各行业客户,把一线经验沉淀为可复用的行业观察。

  • 十年建站经验,覆盖建材、制造、服务、文创等
  • 项目经理把关选题与事实准确性
  • 工程师与设计师联合撰写专业细节
  • 统一编辑规范,保证文风与排版一致
  • 每月复盘转化数据,迭代选题方向

延伸阅读

相关资讯与近期热门内容

深度阅读推荐

建站决策前值得细读的三篇

网站改版的5个关键决策
2024-08-12

网站改版的5个关键决策

什么时候该改版、改到什么程度、如何避免流量掉光,京华建材集团改版复盘给出答案。

获取专属建站方案

看完文章,把您的行业与预算告诉我们,免费获取一份量身定制的官网建设方案与报价。

立即免费咨询