温馨提示×

centos ifconfig检查网络连接

小樊
46
2025-10-21 22:59:29
栏目: 智能运维

在 CentOS 系统中,你可以使用 ifconfig 命令来检查网络接口的配置和状态。以下是一些常用的 ifconfig 命令及其用法:

  1. 查看所有网络接口

    ifconfig
    

    这将显示系统中所有活动的网络接口及其详细信息。

  2. 查看特定网络接口: 如果你想查看某个特定接口的信息,比如 eth0,可以使用:

    ifconfig eth0
    
  3. 检查网络连接状态: 通过 ifconfig 查看接口的状态,UP 表示接口已启动,DOWN 表示接口已关闭。

  4. 查看 IP 地址: 在输出中查找 inet 字段,这会显示分配给该接口的 IPv4 地址。例如:

    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::a00:27ff:fe4e:66a1  prefixlen 64  scopeid 0x20<link>
            ether 08:00:27:4e:66:a1  txqueuelen 1000  (Ethernet)
            RX packets 123456  bytes 123456789 (117.7 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 654321  bytes 987654321 (941.5 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
  5. 启用/禁用网络接口

    • 启用接口:
      sudo ifconfig eth0 up
      
    • 禁用接口:
      sudo ifconfig eth0 down
      

请注意,在 CentOS 8 及更高版本中,ifconfig 已被弃用,推荐使用 ip 命令来管理网络接口。你可以使用 ip addrip link 来替代 ifconfig 的功能。

0