ifconfig

    注解

    ifconfig 是一个古老的工具,现在显得有些过时了。

    更推荐使用 ip 命令 ,这是网络配置工具的集大成者。

    ifconfig 不带任何参数即可查询当前所有已 启用 ( up )网卡的状态:

    带上 -a 参数即查询所有网卡,包括 禁用 的( down ):

    1. $ ifconfig -a
    2. eth0 Link encap:Ethernet HWaddr 08:00:27:aa:87:65
    3. inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
    4. BROADCAST MULTICAST MTU:1500 Metric:1
    5. RX packets:239850 errors:0 dropped:0 overruns:0 frame:0
    6. TX packets:232433 errors:0 dropped:0 overruns:0 carrier:0
    7. collisions:0 txqueuelen:1000
    8. RX bytes:39353582 (39.3 MB) TX bytes:160813991 (160.8 MB)
    9. eth1 Link encap:Ethernet HWaddr 08:00:27:af:9e:56
    10. inet addr:192.168.56.11 Bcast:192.168.56.255 Mask:255.255.255.0
    11. inet6 addr: fe80::a00:27ff:feaf:9e56/64 Scope:Link
    12. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    13. RX packets:154411 errors:0 dropped:0 overruns:0 frame:0
    14. TX packets:147333 errors:0 dropped:0 overruns:0 carrier:0
    15. collisions:0 txqueuelen:1000
    16. RX bytes:11788649 (11.7 MB) TX bytes:141396393 (141.3 MB)
    17. lo Link encap:Local Loopback
    18. inet addr:127.0.0.1 Mask:255.0.0.0
    19. inet6 addr: ::1/128 Scope:Host
    20. UP LOOPBACK RUNNING MTU:16436 Metric:1
    21. RX packets:96 errors:0 dropped:0 overruns:0 frame:0
    22. RX bytes:8692 (8.6 KB) TX bytes:8692 (8.6 KB)

    带上网卡名则查询指定网卡:

    1. $ ifconfig eth0
    2. eth0 Link encap:Ethernet HWaddr 08:00:27:aa:87:65
    3. inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
    4. BROADCAST MULTICAST MTU:1500 Metric:1
    5. RX packets:239850 errors:0 dropped:0 overruns:0 frame:0
    6. TX packets:232433 errors:0 dropped:0 overruns:0 carrier:0
    7. collisions:0 txqueuelen:1000
    8. RX bytes:39353582 (39.3 MB) TX bytes:160813991 (160.8 MB)

    启停

    启用网卡 eth0

    禁用网卡 eth0

    1. $ ifconfig eth0 down
    1. $ ifconfig eth0 promisc

    关闭混杂模式:

    配置

    配置度量值( metric ):

    配置 MTU

    1. $ ifconfig eth0 mtu 1500

    配置 IP 地址以及掩码(可以分开):

    小菜学编程

    参考文献