“ifconfig”(接口配置)是一个网络管理工具。它用于配置和查看 Linux 操作系统中网络接口的状态。使用“ifconfig”,您可以分配 IP 地址、启用或禁用接口、管理 ARP 缓存、路由等。
在本文中,我们将探讨如何使用“ifconfig”命令。
文章目录
ifconfig安装
‘ifconfig’ 命令已弃用并替换为 ip,并且可能不包含在较新的 Linux 发行版中。
如果您收到一条错误消息,指出“ifconfig:找不到命令”,则表示您的系统上未安装包含该命令的软件包。
ifconfig
在基于 Ubuntu 和基于 Debian 的 Linux 发行版上,运行以下命令以安装 ‘ifconfig’:
sudo apt install net-tools -y
ifconfig
要在 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)
使用“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”命令在特定网络设备上启用和禁用混合。
要在网络接口上启用混合模式,请在设备名称后输入“混合”标志:
ifconfig eth0 promisc
要禁用混杂模式,请使用“-promisc”标志
ifconfig eth0 -promisc
您可以使用以下语法更改 MTU 值:
ifconfig [interface-name] mtu [mtu-value]
例如,将网络接口“eth0”的 MTU 值设置为“500”,运行以下命令:
ifconfig eth0 mtu 500
MAC“媒体访问控制”是唯一标识网络上设备的物理地址。
要更改网络接口的 MAC 地址,请使用“hw ether”标志设置新的 MAC 地址:
ifconfig eth0 hw ether 00:00:2d:3a:2a:28
以上就是ifconfig所有用法了。
Sonara是一款开创性的AI求职自动化平台Shadowsocks分支的全面指南Debian系统上使用Vi编辑器修改V2Ray的config.json配置文件Cisco Shadowsocks:完整使用指南Firefox与v2ray inbound http ssl代理设置教程wilson球拍clash真假: 如何鉴别真假与常见问题解决解决shadowrocket封锁问题的终极指南极路由安装v2ray教程安卓冲浪板 Surfboard 2.22.9 更新2023年美国AppleID免费共享:苹果账号全面开放共享Clash VPN 购买:稳定好用的 Clash 节点(2025 持续更新)Clash Verge是开源的吗?探索其开源特性与优势Trojan多用户管理面板一键安装脚本Jrohy版使用 Cloudflare Workers 自建 VLESS 节点:永久免费、解锁 Chatgpt 、不限流量、科学上网Nutbit 坚果机场怎么样 – SS 机场推荐 | 专线机场