zoukankan      html  css  js  c++  java
  • 【转】linux中ifconfig 命令详解详解

    1 概述 

    ifconfig工具不仅可以被用来简单地获取网络接口配置信息,还可以修改这些配置。用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在。要想将上述的配置信息永远的存的电脑里,那就要修改网卡的配置文件了。

    2 命令详解

    2.1 命令常见参数

    Usage:

    ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
    [add <address>[/<prefixlen>]]
    [del <address>[/<prefixlen>]]
    [[-]broadcast [<address>]] [[-]pointopoint [<address>]]
    [netmask <address>] [dstaddr <address>] [tunnel <address>]
    [outfill <NN>] [keepalive <NN>]
    [hw <HW> <address>] [metric <NN>] [mtu <NN>]
    [[-]trailers] [[-]arp] [[-]allmulti]
    [multicast] [[-]promisc]
    [mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]
    [txqueuelen <NN>]
    [[-]dynamic]
    [up|down] ...

    2.2 命令常见参数说明

    参数

    说明

    -a

    显示全部接口信息。

    -s

    显示摘要信息(类似于 netstat -i)。

    <interface> address

    为网卡设置IPv4地址。

    <interface> add <address>

    给指定网卡配置IPv6地址。

    <interface> del <address>

    删除指定网卡的IPv6地址。

    <interface> netmask <address>

    设置网卡的子网掩码。掩码可以是有前缀0x的32位十六进制数,也可以是用点分开的4个十进制数。如果不打算将网络分成子网,可以不管这一选项;如果要使用子网,那么请记住,网络中每一个系统必须有相同子网掩码。

    <interface> dstaddr <address>

    设定一个远端地址,建立点对点通信。

    <interface> tunnel <address>

    建立隧道。

    <interface> hw <address>

    设置硬件地址。

    <interface> mtu <NN>

    设置最大传输单元。

    <interface> [-]arp

    设置指定网卡是否支持ARP协议。-表示不支持arp。

    <interface> multicast

    为网卡设置组播标志。

    <interface> [-]promisc

    设置是否支持网卡的promiscuous模式,如果选择此参数,网卡将接收网络中发给它所有的数据包。-表示关闭混杂模式。

    <interface> txqueuelen <NN>

    为网卡设置传输列队的长度。

    <interface> up

    启动指定网卡。

    <interface> down

    关闭指定网卡。该参数可以有效地阻止通过指定接口的IP信息流,如果想永久地关闭一个接口,我们还需要从核心路由表中将该接口的路由信息全部删除。

    2.3 网卡字段简单说明
     

    (1) 简单分析 

    [root@localhost ~]# ifconfig eth0

    // UP:表示“接口已启用”。
    // BROADCAST :表示“主机支持广播”。
    // RUNNING:表示“接口在工作中”。
    // MULTICAST:表示“主机支持多播”。
    // MTU:1500(最大传输单元):1500字节
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

    // inet :网卡的IP地址。
    // netmask :网络掩码。
    // broadcast :广播地址。
    inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255

    // 网卡的IPv6地址
    inet6 fe80::2aa:bbff:fecc:ddee prefixlen 64 scopeid 0x20<link>

    // 连接类型:Ethernet (以太网) HWaddr (硬件mac地址)
    // txqueuelen (网卡设置的传送队列长度)
    ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet)


    // RX packets 接收时,正确的数据包数。
    // RX bytes 接收的数据量。
    // RX errors 接收时,产生错误的数据包数。
    // RX dropped 接收时,丢弃的数据包数。
    // RX overruns 接收时,由于速度过快而丢失的数据包数。
    // RX frame 接收时,发生frame错误而丢失的数据包数。
    RX packets 2825 bytes 218511 (213.3 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0

    // TX packets 发送时,正确的数据包数。
    // TX bytes 发送的数据量。
    // TX errors 发送时,产生错误的数据包数。
    // TX dropped 发送时,丢弃的数据包数。
    // TX overruns 发送时,由于速度过快而丢失的数据包数。
    // TX carrier 发送时,发生carrier错误而丢失的数据包数。
    // collisions 冲突信息包的数目。
    TX packets 1077 bytes 145236 (141.8 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    3 简单实例

    3.1 显示网络设备信息 

    (1) 显示激活的网卡信息

    ifconfig 

    (2) 显示所有的网卡信息

    ifconfig -a 

    (3) 显示简要的网卡信息

    ifconfig -s 

    3.2 启动关闭指定网卡
    (1) 关闭网卡

    ifconfig eth0 down 

    (2) 启动网卡

    ifconfig eth0 up 

    3.3 配置和删除ip地址 

    (1) 配置ip

    // 配置ip地址
    ifconfig eth0 192.168.1.100

    // 配置ip地址和子网掩码
    ifconfig eth0 192.168.1.100 netmask 255.255.255.0

    // 配置ip地址、子网掩码和广播地址
    ifconfig eth0 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 

    (2) 单网卡添加多个IP地址

    ifconfig eth0:0 192.168.1.100 netmask 255.255.255.0 up

    ifconfig eth0:1 192.168.2.100 netmask 255.255.255.0 up
     

    (3) 删除IP地址

    ifconfig eth0 del 192.168.1.100

    3.4 修改MAC地址

    ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE

    3.5 启用和关闭ARP协议

    (1) 启用arp

    ifconfig eth0 arp

    (2) 禁用arp

    ifconfig eth0 -arp

    禁用arp的时候,可以看到出现NOARP字段。

    [root@localhost ~]# ifconfig eth0 arp
    [root@localhost ~]#
    [root@localhost ~]# ifconfig eth0
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255
    inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20<link>
    ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet)
    RX packets 2635 bytes 204710 (199.9 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 1071 bytes 144688 (141.2 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    [root@localhost ~]# ifconfig eth0 -arp
    [root@localhost ~]#
    [root@localhost ~]# ifconfig eth0
    eth0: flags=4291<UP,BROADCAST,RUNNING,NOARP,MULTICAST> mtu 1500
    inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255
    inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20<link>
    ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet)
    RX packets 2636 bytes 204770 (199.9 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 1071 bytes 144688 (141.2 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    3.6 设置最大传输单元
     

    ifconfig eth0 mtu 1500

    3.7 设置网卡的promiscuous模式
     

    (1) 启用

    ifconfig eth0 promisc
     

    (2) 禁用

    ifconfig eth0 -promisc
     

    如果选择此参数,网卡将接收网络中发给它所有的数据包。当启用时出现PROMISC字段。

    [root@localhost ~]# ifconfig eth0 promisc
    [root@localhost ~]#
    [root@localhost ~]#
    [root@localhost ~]# ifconfig eth0
    eth0: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST> mtu 1500
    inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255
    inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20<link>
    ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet)
    RX packets 2659 bytes 206696 (201.8 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 1071 bytes 144688 (141.2 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


    [root@localhost ~]#
    [root@localhost ~]# ifconfig eth0 -promisc
    [root@localhost ~]#
    [root@localhost ~]#
    [root@localhost ~]# ifconfig eth0
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255
    inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20<link>
    ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet)
    RX packets 2661 bytes 206816 (201.9 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 1071 bytes 144688 (141.2 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    3.8 设置网卡的多播模式
     

    (1) 启用

    ifconfig eth0 allmulti
     

    (2) 禁用

    ifconfig eth0 -allmulti

    如果选择此参数,网卡将接收网络中所有的多播数据包。当启用时会出现MULTICAST字段。

    [root@localhost ~]# ifconfig eth0 allmulti
    [root@localhost ~]#
    [root@localhost ~]# ifconfig eth0
    eth0: flags=4675<UP,BROADCAST,RUNNING,ALLMULTI,MULTICAST> mtu 1500
    inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255
    inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20<link>
    ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet)
    RX packets 2676 bytes 207716 (202.8 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 1071 bytes 144688 (141.2 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0


    [root@localhost ~]#
    [root@localhost ~]# ifconfig eth0 -allmulti
    [root@localhost ~]#
    [root@localhost ~]#
    [root@localhost ~]# ifconfig eth0
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 192.168.1.135 netmask 255.255.255.0 broadcast 192.168.1.255
    inet6 fe80::20c:29ff:fe9b:52d3 prefixlen 64 scopeid 0x20<link>
    ether 00:aa:bb:cc:dd:ee txqueuelen 1000 (Ethernet)
    RX packets 2676 bytes 207716 (202.8 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 1071 bytes 144688 (141.2 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    3.9 配置和删除IPv6地址
     

    (1) 添加

    ifconfig eth0 add 3ffe:3240:800:1005::2/64
     

    (2) 删除

    ifconfig eth0 del 3ffe:3240:800:1005::2/64
    ————————————————
    版权声明:本文为CSDN博主「路痴的旅行」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/u011857683/article/details/83758503

  • 相关阅读:
    H5纯前端获取视频第一帧、大小、尺寸、类型等
    HTML5 拖放(Drag 和 Drop)
    HTML5 MathML:在文档中使用 MathML 元素,对应的标签是 <math>...</math>
    HTML5 内联 SVG:什么是SVG?SVG优势
    docker-machine安装教程
    Manjaro系统和软件安装记录
    geektime专栏《Java并发编程实战》笔记【待完成】
    kubernetes之三 使用kubectl在k8s上部署应用
    给虚拟机CentOS7扩容(lvm方式)
    分析SQL的执行过程
  • 原文地址:https://www.cnblogs.com/shuai7boy/p/11387990.html
Copyright © 2011-2022 走看看