Linux ifconfig命令用于显示或设置网络设备。
ifconfig可设置网络设备的状态,或是显示目前的设置。
语法:
ifconfig [网络设备][down up -allmulti -arp -promisc][add<地址>][del<地址>][<hw<网络设备类型><硬件地址>][io_addr<I/O地址>][irq<IRQ地址>][media<网络媒介类型>][mem_start<内存地址>][metric<数目>][mtu<字节>][netmask<子网掩码>][tunnel<地址>][-broadcast<地址>][-pointopoint<地址>][IP地址]
参数说明:
add<地址> | 设置网络设备IPv6的IP地址。 |
---|---|
del<地址> | 删除网络设备IPv6的IP地址。 |
down | 关闭指定的网络设备。 |
hw<网络设备类型><硬件地址> | 设置网络设备的类型与硬件地址。 |
io_addr<I/O地址> | 设置网络设备的I/O地址。 |
irq<IRQ地址> | 设置网络设备的IRQ。 |
media<网络媒介类型> | 设置网络设备的媒介类型。 |
mem_start<内存地址> | 设置网络设备在主内存所占用的起始地址。 |
metric<数目> | 指定在计算数据包的转送次数时,所要加上的数目。 |
mtu<字节> | 设置网络设备的MTU。 |
netmask<子网掩码> | 设置网络设备的子网掩码。 |
tunnel<地址> | 建立IPv4与IPv6之间的隧道通信地址。 |
up | 启动指定的网络设备。 |
-broadcast<地址> | 将要送往指定地址的数据包当成广播数据包来处理。 |
-pointopoint<地址> | 与指定地址的网络设备建立直接连线,此模式具有保密功能。 |
-promisc | 关闭或启动指定网络设备的promiscuous模式。 |
[IP地址] | 指定网络设备的IP地址。 |
[网络设备] | 指定网络设备的名称。 |
使用方法:
显示网络设备信息
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:0A:0B:0C
inet addr:192.168.0.3 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::250:56ff:fe0a:b0c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:172220 errors:0 dropped:0 overruns:0 frame:0
TX packets:132379 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:87101880 (83.0 MiB) TX bytes:41576123 (39.6 MiB)
Interrupt:185 Base address:0x2024
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2022 errors:0 dropped:0 overruns:0 frame:0
TX packets:2022 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2459063 (2.3 MiB) TX bytes:2459063 (2.3 MiB)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
启动关闭指定网卡
# ifconfig eth0 down
# ifconfig eth0 up
- 1
- 2
为网卡配置和删除IPv6地址
# ifconfig eth0 add 33ffe:3240:800:1005::2/ 64 //为网卡诶之IPv6地址
ifconfig eth0 del 33ffe:3240:800:1005::2/ 64 //为网卡删除IPv6地址
- 1
- 2
- 3
用ifconfig修改MAC地址
# ifconfig eth0 down //关闭网卡
# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址
# ifconfig eth0 up //启动网卡
# ifconfig eth1 hw ether 00:1D:1C:1D:1E //关闭网卡并修改MAC地址
# ifconfig eth1 up //启动网卡
- 1
- 2
- 3
- 4
- 5
配置IP地址
# ifconfig eth0 192.168.1.56
//给eth0网卡配置IP地址
ifconfig eth0 192.168.1.56 netmask 255.255.255.0
// 给eth0网卡配置IP地址,并加上子掩码
ifconfig eth0 192.168.1.56 netmask 255.255.255.0 broadcast 192.168.1.255
// 给eth0网卡配置IP地址,加上子掩码,加上个广播地址
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
启用和关闭ARP协议
# ifconfig eth0 arp //开启
# ifconfig eth0 -arp //关闭
- 1
- 2
设置最大传输单元
# ifconfig eth0 mtu 1500
//设置能通过的最大数据包大小为 1500 bytes
- 1
- 2
- 3
</div>
<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-60ecaf1f42.css" rel="stylesheet">
<div class="more-toolbox">
<div class="left-toolbox">
<ul class="toolbox-list">
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#csdnc-thumbsup"></use>
</svg><span class="name">点赞</span>
<span class="count"></span>
</a></li>
<li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-Collection-G"></use>
</svg><span class="name">收藏</span></a></li>
<li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{"mod":"1582594662_002"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-fenxiang"></use>
</svg>分享</a></li>
<!--打赏开始-->
<!--打赏结束-->
<li class="tool-item tool-more">
<a>
<svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
</a>
<ul class="more-box">
<li class="item"><a class="article-report">文章举报</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="person-messagebox">
<div class="left-message"><a href="https://blog.csdn.net/xie_qi_chao">
<img src="https://profile.csdnimg.cn/B/F/6/3_xie_qi_chao" class="avatar_pic" username="xie_qi_chao">
<img src="https://g.csdnimg.cn/static/user-reg-year/1x/2.png" class="user-years">
</a></div>
<div class="middle-message">
<div class="title"><span class="tit"><a href="https://blog.csdn.net/xie_qi_chao" data-report-click="{"mod":"popu_379"}" target="_blank">解启超</a></span>
</div>
<div class="text"><span>发布了358 篇原创文章</span> · <span>获赞 55</span> · <span>访问量 3万+</span></div>
</div>
<div class="right-message">
<a href="https://im.csdn.net/im/main.html?userName=xie_qi_chao" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
</a>
<a class="btn btn-sm bt-button personal-watch" data-report-click="{"mod":"popu_379"}">关注</a>
</div>
</div>
</div>
</article>