每天一个Linux命令(49):ifconfig
来源:互联网 发布:mac 录音专业版 编辑:程序博客网 时间:2024/06/05 05:29
windows下的ipconfig用于获取网络接口配置信息,并对此进行修改。Linux拥有一个类似的工具,即ifconfig(interfaces config),需要以root身份登录或使用sudo运行。
1. 命令格式
ifconfig [网络设备] [参数]
2. 命令功能
查看,配置网络设备。
3. 命令参数
up,启动指定的网络设备、网卡。
down,关闭指定的网络设备、网卡,该参数可以有效地阻止指定接口的IP信息流。如果想永久地关闭一个接口,除此之外,我们还需要从核心路由表中全部删除接口的路由信息。
arp,设置指定网卡是否支持ARP协议。
-promisc,设置是否支持网卡的promiscuous模式,如果选择此参数,网卡将接收网络中发给它所有的数据包。
-allmulti,设置是否支持多播模式,如果选择此参数,网卡将接收网络中所有的多播数据包。
-a,显示全部接口信息。
-s,显示摘要信息(类似于netstat -i
)
add,给指定网卡配置IPv6地址
del,删除指定网卡的IPv6地址
<硬件地址>,配置网卡最大的传输单元
mtu <字节数>,设置网卡的最大传输单元 (bytes)
netmask <子网掩码>,设置网卡的子网掩码,掩码可以是有前缀0x的32位十六进制数,也可以是用点分开的4个十进制数。如果不打算将网络分成子网,可以不管这一选项;如果要使用子网,则网络中每一个系统必须有相同的子网掩码。
tunel,建立隧道
dstaddr,设定一个远端地址,建立点对点通信
-broadcast <地址>,为指定网卡设置广播协议
-pointtopoint <地址>,为网卡设置点对点通讯协议
multicast,为网卡设置组播标志
address,为网卡设置IPv4地址
txqueuelen <长度>,为网卡设置传输队列的长度
4. 使用实例
例一:显示网络设备信息(激活状态)
命令:ifconfig
# ifconfigeth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:20 inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0 TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:596390239 (568.7 MiB) TX bytes:2886956 (2.7 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:68 errors:0 dropped:0 overruns:0 frame:0 TX packets:68 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2856 (2.7 KiB) TX bytes:2856 (2.7 KiB)
说明:
第一行:连接类型:Ethernet(以太网),HWaddr(硬件mac地址)
第二行:网卡的IP地址、广播地址、子网掩码
第三行:UP,代表网卡是开启状态;RUNNING,代表网卡的网线被接上;MULTICAST,支持组播;MTU,最大传输单元;1500,1500字节
第四、五行:接收、发送数据包情况统计
第七行:接收、发送数据的字节统计信息
eth0表示第一块网卡,其中HWaddr表示网卡的物理地址,可以看到目前网卡的物理地址(MAC地址)是00:50:56:BF:26:20
inet addr表示网卡的IP地址:192.168.120.204,广播地址Bcast:192.168.120.255,掩码地址Mask:255.255.255.0
lo表示主机的会话地址,这个一般是用来测试一个网络程序,但又不想让局域网或外网的用户查看,只能在此台主机上运行,查看所用的网络接口。比如把 httpd服务指定到lo会话地址,在浏览器输入127.0.0.1,显示WEB网站。但只有你自己能看到,局域网的其它主机或用户看不到。
例二:启动,关闭指定网卡
命令:
ifconfig eth0 up //启动网卡eth0 ifconfig eth0 down //关闭网卡eth0
说明:SSH远程登录linux要小心,除非你有多网卡,否则关闭了就不能开启。
例三:为网卡配置和删除IPv6地址
命令:
ifconfig eth0 add 33ffe:3240:800:1005::2/64//为网卡eth0配置IPv6地址ifconfig eth0 del 33ffe:3240:800:1005::2/64//为网卡eth0删除IPv6地址
说明:SSH远程登录linux要小心,除非你有多网卡,否则关闭了就不能开启。
例四:用ifconfig修改MAC地址
命令:ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE
# ifconfig eth0 down //关闭网卡# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址# ifconfig eth0 up //启动网卡# ifconfigeth0 Link encap:Ethernet HWaddr 00:AA:BB:CC:DD:EE inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0 TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:596390239 (568.7 MiB) TX bytes:2886956 (2.7 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:68 errors:0 dropped:0 overruns:0 frame:0 TX packets:68 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2856 (2.7 KiB) TX bytes:2856 (2.7 KiB)# ifconfig eth0 hw ether 00:50:56:BF:26:20 //关闭网卡并修改MAC地址 # ifconfig eth0 up //启动网卡# ifconfigeth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:20 inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0 TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:596390239 (568.7 MiB) TX bytes:2886956 (2.7 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:68 errors:0 dropped:0 overruns:0 frame:0 TX packets:68 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2856 (2.7 KiB) TX bytes:2856 (2.7 KiB)
例五:为网卡配置IP地址、子网掩码、广播地址
# ifconfig eth0 192.168.120.56 # ifconfig eth0 192.168.120.56 netmask 255.255.255.0 # ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255
例六:为网卡启用和关闭ARP协议
命令:
ifconfig eth0 arpifconfig eth0 -arp
例七:设置网卡的最大传输单元
命令:ifconfig eth0 mtu 1500
# ifconfig eth0 mtu 1480# ifconfigeth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:1F inet addr:192.168.120.203 Bcast:192.168.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1480 Metric:1 RX packets:8712395 errors:0 dropped:0 overruns:0 frame:0 TX packets:36631 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:597062089 (569.4 MiB) TX bytes:2643973 (2.5 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:9973 errors:0 dropped:0 overruns:0 frame:0 TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:518096 (505.9 KiB) TX bytes:518096 (505.9 KiB)# ifconfig eth0 mtu 1500# ifconfigeth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:1F inet addr:192.168.120.203 Bcast:192.168.120.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8712548 errors:0 dropped:0 overruns:0 frame:0 TX packets:36685 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:597072333 (569.4 MiB) TX bytes:2650581 (2.5 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:9973 errors:0 dropped:0 overruns:0 frame:0 TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:518096 (505.9 KiB) TX bytes:518096 (505.9 KiB)
说明:设置能通过的最大数据包为1500bytes。
备注:在网卡重启后,系统重启后,用ifconfig配置的网卡信息就不存在了。要想将上述的配置信息永远的保存在系统里,就要修改网卡配置文件。
- 每天一个Linux命令(49):ifconfig
- 每天一个linux命令:ifconfig命令
- 每天一个linux命令:ifconfig命令
- 每天一个linux命令:ifconfig命令
- 每天一个linux命令(52):ifconfig命令
- 每天一个linux命令(52):ifconfig命令
- 每天一个linux命令(52):ifconfig命令
- 每天一个linux命令(1):ifconfig命令
- 每天一个linux命令(52):ifconfig命令
- 每天一个linux命令(52):ifconfig命令
- 每天一个linux命令(52):ifconfig命令
- 每天一个linux命令(40):ifconfig命令
- 每天一个linux命令(40):ifconfig命令
- 每天一个linux命令(52):ifconfig命令
- 每天一个 Linux 命令(52):ifconfig命令
- 每天一个Linux命令(52):ifconfig命令
- 每天一个linux命令(52):ifconfig命令
- 每天一个linux命令(52):ifconfig命令
- @OneToMany或@ManyToOne的用法-annotation关系映射篇
- 学习资料汇总(持续更新)
- Spring--IoC--从applicationContext容器中获取对象
- android 为什么不建议使用Enum
- #695 – 实现一个简单的拖拽(Implementing Drag-and-Drop Behavior)
- 每天一个Linux命令(49):ifconfig
- 一张图了解:sass
- Distributed tensorflow实现原理
- SOA微服务案例-基于springmvc+mybaties+dubbo+mq+gradle
- OpenGLES的简单应用绘图,以及照相机画面变色变形渲染(三)
- 你在执行composer self-update更新命令的时候可能会遇到错误:
- unicode,ansi,utf-8编码的区别--浅谈计算机编码发展史
- 关于FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream的一次解决过
- Python scikit-learn机器学习工具包学习笔记:cross_validation模块