linux

Linux ifconfig命令详解

小樊
42
2025-06-01 12:29:01
栏目: 智能运维

ifconfig 是一个用于配置和显示 Linux 内核中网络接口的命令行实用程序。它可以用来查看和设置网络接口的参数,如 IP 地址、子网掩码、广播地址等。以下是 ifconfig 命令的一些常用选项和用法:

  1. 查看所有网络接口的信息:
ifconfig
  1. 查看指定网络接口的信息(例如,查看 eth0 接口的信息):
ifconfig eth0
  1. 显示网络接口的统计信息(例如,显示 eth0 接口的统计信息):
ifconfig eth0 stats
  1. 配置网络接口的 IP 地址和子网掩码(例如,为 eth0 接口分配 IP 地址 192.168.1.2 和子网掩码 255.255.255.0):
ifconfig eth0 192.168.1.2 netmask 255.255.255.0
  1. 启用网络接口(例如,启用 eth0 接口):
ifconfig eth0 up
  1. 禁用网络接口(例如,禁用 eth0 接口):
ifconfig eth0 down
  1. 为网络接口设置广播地址(例如,为 eth0 接口设置广播地址 192.168.1.255):
ifconfig eth0 broadcast 192.168.1.255
  1. 修改网络接口的 MTU(最大传输单元)值(例如,将 eth0 接口的 MTU 值设置为 1500):
ifconfig eth0 mtu 1500
  1. 为网络接口添加别名(例如,为 eth0 接口添加别名 eth0:1):
ifconfig eth0:1 192.168.1.3 netmask 255.255.255.0

请注意,ifconfig 命令在某些 Linux 发行版中可能已被弃用,取而代之的是 ip 命令。尽管如此,ifconfig 仍然在许多系统中广泛使用。要使用 ip 命令执行上述操作,可以参考以下示例:

  1. 查看所有网络接口的信息:
ip addr
  1. 查看指定网络接口的信息(例如,查看 eth0 接口的信息):
ip addr show eth0
  1. 配置网络接口的 IP 地址和子网掩码(例如,为 eth0 接口分配 IP 地址 192.168.1.2 和子网掩码 255.255.255.0):
ip addr add 192.168.1.2/24 dev eth0
  1. 启用网络接口(例如,启用 eth0 接口):
ip link set eth0 up
  1. 禁用网络接口(例如,禁用 eth0 接口):
ip link set eth0 down
  1. 删除网络接口的别名(例如,删除 eth0:1 别名):
ip addr del 192.168.1.3/24 dev eth0 label eth0:1

0
看了该问题的人还看了