debian

Debian中ifconfig命令的常见用法

小樊
43
2025-06-30 23:49:11
栏目: 智能运维

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

基本用法

  1. 查看所有网络接口

    ifconfig
    
  2. 查看特定网络接口的信息

    ifconfig eth0
    

    其中eth0是你要查看的网络接口名称。

  3. 启动一个网络接口

    sudo ifconfig eth0 up
    
  4. 关闭一个网络接口

    sudo ifconfig eth0 down
    
  5. 设置IP地址

    sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
    
  6. 添加默认网关

    sudo route add default gw 192.168.1.1 eth0
    
  7. 删除默认网关

    sudo route del default gw 192.168.1.1 eth0
    

高级用法

  1. 查看MAC地址

    ifconfig eth0 | grep ether
    
  2. 查看广播地址

    ifconfig eth0 | grep broadcast
    
  3. 查看MTU(最大传输单元)

    ifconfig eth0 | grep mtu
    
  4. 启用或禁用混杂模式

    • 启用混杂模式:
      sudo ifconfig eth0 promisc
      
    • 禁用混杂模式:
      sudo ifconfig eth0 -promisc
      
  5. 设置网络接口别名

    sudo ifconfig eth0:1 192.168.1.101 netmask 255.255.255.0
    
  6. 查看网络接口统计信息

    ifconfig eth0
    

注意事项

通过这些基本和高级用法,你可以有效地管理和配置Debian系统中的网络接口。

0
看了该问题的人还看了