温馨提示×

centos下ifconfig命令的常见用法

小樊
56
2026-01-02 04:40:13
栏目: 智能运维

在 CentOS 系统中,ifconfig 命令用于配置、激活和查询网络接口。以下是一些常见的 ifconfig 用法:

  1. 查看所有网络接口信息:
ifconfig
  1. 查看指定网络接口的信息(例如:eth0):
ifconfig eth0
  1. 激活一个网络接口(例如:eth0):
ifconfig eth0 up
  1. 关闭一个网络接口(例如:eth0):
ifconfig eth0 down
  1. 为网络接口分配 IP 地址(例如:eth0,IP 地址为 192.168.1.100,子网掩码为 255.255.255.0):
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
  1. 为网络接口设置广播地址(例如:eth0,广播地址为 192.168.1.255):
ifconfig eth0 broadcast 192.168.1.255
  1. 为网络接口启用或禁用广播:
# 启用广播
ifconfig eth0 broadcast

# 禁用广播
ifconfig eth0 -broadcast
  1. 修改网络接口的 MTU(最大传输单元,例如:eth0,MTU 为 1500):
ifconfig eth0 mtu 1500
  1. 为网络接口添加别名(例如:eth0:0,IP 地址为 192.168.1.200):
ifconfig eth0:0 192.168.1.200
  1. 删除网络接口别名(例如:eth0:0):
ifconfig eth0:0 down
ifconfig eth0:0 up

请注意,ifconfig 命令在较新的 CentOS 版本中可能已被弃用,建议使用 ip 命令替代。

0