Linux ifconfig命令示例

时间:2020-02-23 14:39:48  来源:igfitidea点击:

Linux ifconfig是一种网络管理工具,可帮助您检查Linux系统的IP地址以及配置网络接口。
让我们深入了解如何使用此常用命令。

没有任何选项的Linux ifconfig命令

不带任何参数的ifconfig命令显示与Linux系统关联的所有网络接口的状态。

$ifconfig

以短格式显示ifconfig输出

要以短格式显示ifconfig输出,请使用-s选项。

$ifconfig -s

单个网络接口的显示状态

如果要检查特定网络接口的状态,请使用以下语法:

$ifconfig [interface_name]

例如,要显示接口" enp0s3"的状态,请运行:

$ifconfig enp0s3

使用ifconfig启用/禁用网络接口

有时,您可能想重置网络接口。
Linux ifconfig命令可用于禁用或者启动网络接口。

要关闭网络接口,请运行以下命令

$ifconfig [interface_name] down

例如,要关闭接口enp0s3,请执行以下命令:

$ifconfig enp0s3 down

当您使用" ifconfig"命令检查统计信息时,禁用的界面将不会出现在输出中。
例如,不会显示" enp0s3"界面。

要调出接口,请执行:

$ifconfig enp0s3 up

这次,该界面将在运行ifconfig命令时显示。

使用" ifconfig -a"选项查看所有网络接口

使用ifconfig命令,您可以查看所有接口的状态,无论它们处于打开状态还是关闭状态。
为此,请使用-a选项,如图所示

$ifconfig -a

在网络接口上启用和禁用混杂模式

混杂模式是指允许网络适配器访问和查看网络中所有数据包的操作模式。
在这种模式下,适配器不过滤数据包。

要启用混杂模式,请使用以下语法:

$ifconfig [network_interface] promisc

例如:

$ifconfig enp0s3 promisc

要禁用混杂模式,请执行:

$ifconfig enp0s3 -promisc

配置网络接口的IP地址和网络掩码

Linux ifconfig命令还可用于临时配置网络适配器的IP地址和网络掩码。
语法如下所示:

$ifconfig [network_interface] [IP-address] netmask [subnet mask]

例如,

$ifconfig enp0s3 192.168.43.100 netmask 255.255.255.0

您以后可以使用" ifconfig"命令来确认。

使用ifconfig更改MTU值

您可以使用以下语法更改mtu(最大传输单位)值:

$ifconfig [interface_name] mtu [mtu-value]

例如:

$ifconfig enp0s3 mtu 800