

Linux ifconfig命令
source link: https://www.myfreax.com/linux-ifconfig-command/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

ifconfig
(interface configuration)是一种网络管理工具。它用于在 Linux 操作系统中配置和查看网络接口的状态。使用ifconfig
,您可以分配 IP 地址、启用或禁用网络接口、管理ARP 缓存、路由等。
在本文中,我们将探讨如何使用ifconfig
命令。
如何安装 ifconfig
ifconfig
命令已弃用并替换为ip
在较新的 Linux 发行版,并且可能不包含在该发行版中。
如果您收到一条错误消息“ifconfig: command not found”,则表示您的系统上未安装包含该命令的软件包。
ifconfig
在 Ubuntu/Debian 上安装
在基于 Ubuntu 和基于 Debian 的 Linux 发行版上,运行以下命令进行安装ifconfig
:
sudo apt install net-tools -y
ifconfig
在 Centos 上安装
要在CentOS和其他基于RHEL的Linux发行版上安装ifconfig
,请键入:
sudo dnf install net-tools -y
如何使用ifconfig
命令
ifconfig
命令的基本语法如下所示:
ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
interface
- 是网络接口的名称。address
- 是您要分配的 IP 地址。
使用ifconfig
命令设置的配置不是持久的。系统重新启动后,所有更改都将丢失。要使更改永久化,您需要编辑特定于发行版的配置文件或将命令添加到启动脚本中。
只有root或具有sudo权限的用户才能配置网络接口。
显示网络接口信息
不带任何选项调用时,ifconfig
显示所有网络接口和关联ip地址的配置信息:
ifconfig -a
输出包括有关所有活动和非活动网络接口的信息:
docker0 Link encap:Ethernet HWaddr 56:84:7a:fe:97:99
inet addr:172.17.42.1 Bcast:0.0.0.0 Mask:255.255.0.0
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:4198 errors:0 dropped:0 overruns:0 frame:0
TX packets:4198 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:498729 (498.7 KB) TX bytes:498729 (498.7 KB)
eth0 Link encap:Ethernet HWaddr 4c:bb:58:9c:f5:55
inet addr:172.20.10.3 Bcast:172.20.10.15 Mask:255.255.255.240
inet6 addr: 2401:4900:1d65:40a1:4ebb:58ff:fe9c:f555/64 Scope:Global
inet6 addr: 2401:4900:1d65:40a1:f1c9:6a90:2d99:924e/64 Scope:Global
inet6 addr: fe80::4ebb:58ff:fe9c:f555/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:84110 errors:0 dropped:0 overruns:0 frame:0
TX packets:59727 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:70667629 (70.6 MB) TX bytes:20886290 (20.8 MB)
要显示任何特定网络接口的配置信息,请在命令后写入接口名称:
ifconfig eth0
输出将如下所示:
eth0 Link encap:Ethernet HWaddr 4c:bb:58:9c:f5:55
inet addr:172.20.10.3 Bcast:172.20.10.15 Mask:255.255.255.240
inet6 addr: 2401:4900:1d65:40a1:4ebb:58ff:fe9c:f555/64 Scope:Global
inet6 addr: 2401:4900:1d65:40a1:f1c9:6a90:2d99:924e/64 Scope:Global
inet6 addr: fe80::4ebb:58ff:fe9c:f555/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:84110 errors:0 dropped:0 overruns:0 frame:0
TX packets:59727 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:70667629 (70.6 MB) TX bytes:20886290 (20.8 MB)
为网络接口分配IP地址和网络掩码
使用该ifconfig
命令,您可以为网络接口分配 IP 地址和网络掩码。
使用以下语法分配 IP 地址和网络掩码:
ifconfig [interface-name] [ip-address] netmask [subnet-mask]
例如,要将 IP 地址192.168.0.101
和掩码255.255.0.0
分配给eth0
,您可以运行:
ifconfig eth0 192.168.0.101 netmask 255.255.0.0
您还可以使用接口别名为网络接口分配辅助 IP 地址:
ifconfig eth0:0 192.168.0.102 netmask 255.255.0.0
启用和禁用网络接口
有时,您可能需要重置网络接口。在这种情况下,该ifconfig
命令可用于启用或禁用网络接口。
要禁用活动网络接口,请输入设备名称后跟down
标志:
ifconfig eth0 down
要启用非活动网络接口,请使用以下up
标志:
ifconfig eth0 up
启用和禁用混杂模式
混杂模式允许网络接口访问和查看网络中的所有数据包。您可以使用ifconfig
命令在特定网络设备上启用和禁用混杂模式。
要在网络接口上启用混杂模式,请在设备名称后输入标志promisc
:
ifconfig eth0 promisc
要禁用混杂模式,请使用-promisc
标志
ifconfig eth0 -promisc
更改网络接口的 MTU
MTU“最大传输单元”允许您限制在接口上传输的数据包的大小。
您可以使用以下语法更改 MTU 值:
ifconfig [interface-name] mtu [mtu-value]
例如,设置一个网络接口的MTU值eth0
到500
,运行下面的命令:
ifconfig eth0 mtu 500
更改网络接口的 MAC 地址
MAC“媒体访问控制”是唯一标识网络上设备的物理地址。
要更改网络接口的 MAC 地址,请使用该hw ether
标志来设置新的 MAC 地址:
ifconfig eth0 hw ether 00:00:2d:3a:2a:28
我们已经向您展示了如何使用该ifconfig
命令来配置和显示有关网络接口的信息。有关更多信息ifconfig
,请访问ifconfig 命令手册页 。
如果您有任何问题,请在下方留言。
Recommend
-
29
导读 Linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者。使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务。ifconfig是net-tools中已被废弃使用的一个命令,许多年前就已经没有维...
-
41
作者简介: 大家好,我叫张昺华,中间那个字和“饼”字一个读音。 2014年我毕业于广东省惠州学院,我从小酷爱理科,当看到陈莉君老师在《Linux内核之旅》上发的学生在课堂上用课本剧的方式来诠释技术时,想到了自己初中的时候老...
-
10
Linux maintains bugs: The real reason ifconfig on Linux is deprecated
-
6
ifconfig vs ip usage guide on LinuxSearch ComputingForGeeksWelcome to ifconfig vs ip usage guide on Linux. i...
-
11
How To Install Ifconfig on RHEL 8Do you get 'Ifconfig' Command Not Found in your RHEL 8 / CentOS 8 minimal server installation?. The minimal installation of RHEL 8 / CentOS 8 doesn’t come with the ifconfig comman...
-
13
How To Install ifconfig on Ubuntu 20.04 (Focal Fossa)I discovered that Ubuntu 20.04 (Focal Fossa) Server edition doesn’t have ifconfig command pre-installed. How then can you install ifconfig on Ubuntu 20.04 (Focal Fossa)?. if you get a messa...
-
7
How to Fix the "ifconfig: command not found" Error in Linux By Debarshi Das Published 10 hours ago If you encounter the co...
-
6
迷途小书童的Note ifconfig 命令用于查看和配置网络参数。使用 ifconfig 命令配置...
-
7
【踩坑】安装ifconfig命令 2023-02-07 ...
-
13
Linux 中如何启用和禁用网卡?|ifconfig|ifdown/up|ip|nmcli|nmtui|NetworkManager VPS小白 >
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK