ifconfig命令

📅 2026/6/26 16:26:46
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