Linux ifconfig 命令

时间:2022-08-06 18:46:37

在centos6 自带ifconfig

在centos7 默认不带ifconfig,需要自己安装

ifconfig命令用来配置或查看网卡接口,常见用法如下:

安装ifconfig命令
[root@mysql ~]# yum install net-tools -y
查看所有网卡的信息
ifconfig (不包括down状态的网卡)
[root@mysql ~]# ifconfig
eth0: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu
inet 192.168.0.111 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::8c18:4c0c:35b:f89c prefixlen scopeid 0x20<link>
ether :0c::bf:7a:4b txqueuelen (Ethernet)
RX packets bytes (42.1 KiB)
RX errors dropped overruns frame
TX packets bytes (24.4 KiB)
TX errors dropped overruns carrier collisions lo: flags=<UP,LOOPBACK,RUNNING> mtu
inet 127.0.0.1 netmask 255.0.0.0
inet6 :: prefixlen scopeid 0x10<host>
loop txqueuelen (Local Loopback)
RX packets bytes (0.0 B)
RX errors dropped overruns frame
TX packets bytes (0.0 B)
TX errors dropped overruns carrier collisions


[root@mysql ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.111 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::8c18:4c0c:35b:f89c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:bf:7a:4b txqueuelen 1000 (Ethernet)
RX packets 396 bytes 43132 (42.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 189 bytes 25028 (24.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 # eth0:网卡名称
# Link encap:网卡的接口类型,这里是以太网
# HWaddr:网卡的硬件地址,俗称的MAC地址
# inet addr:IPv4地址,如果是IPv6会写成inet6 addr
# Bcast:广播地址
# Mask:子网掩码
# UP:表示网卡是开启状态
# BROADCAST:表示网卡支持广播
# RUNNING:表示网卡的网线已经被接上
# MULTICAST:表示网卡支持组播
# MTU:网络最大传输单元
# Metric:到达网关的度量值,参考:http://m.chinabyte.com/network/191/12287691_gfh.shtml
# RX packets:网络从启动到现在为止接收的数据包大小,单位是字节,error 发生错误的数据包,dropped 被丢弃的数据包
# TX packets:网络从启动到现在为止发送的数据包大小,单位是字节,error 发生错误的数据包,dropped 被丢弃的数据包
# collisions:发生碰撞的数据包,如果发生太多次,表明网络状况不太好
# txqueuelen:传输数据的缓冲区的储存长度
# RX bytes:总接收字节总量
# TX bytes:总发送字节总量
# Memory:网卡硬件的内存地址

[root@mysql ~]# ifconfig -a             // 查看所有网卡的信息(包括down状态的网卡

[root@mysql ~]# ifconfig eth0 // 查看指定网卡的信息

[root@mysql ~]# ifconfig eth0 up        // 启用指定的网卡,等同于:ifup eth0

[root@mysql ~]# ifconfig eth0 down      // 关闭指定的网卡,等同于:ifdown eth0

[root@mysql ~]# ifconfig eth0 arp       // 开启网卡的ARP协议
[root@mysql ~]# ifconfig eth0 -arp // 关闭网卡的ARP协议 [root@mysql ~]# ifconfig eth0 192.168.0.100 // 设置/修改网卡的IP地址(临时生效)
[root@mysql ~]# ifconfig eth0 192.168.0.100/ // 设置/修改网卡的IP地址和子网掩码(临时生效)
[root@mysql ~]# ifconfig eth0 192.168.0.100 netmask 255.255.255.0 // 设置/修改网卡的IP地址和子网掩码(临时生效)
[root@mysql ~]# ifconfig eth0 192.168.0.100 hw ether ::::: // 设置/修改网卡的IP地址和MAC地址(临时生效),ether(以太网)表示网卡的接口类型
[root@mysql ~]# ifconfig eth0 mtu // 设置/修改网卡的最大传输单元(临时生效) [root@mysql ~]# ifconfig eth0: 192.168.0.50/ // 给网卡配置虚拟接口,相当于给网卡再配置一个IP地址(临时生效)
[root@mysql ~]# ifconfig eth0: 192.168.0.51/ // 给网卡配置虚拟接口,相当于给网卡再配置一个IP地址(临时生效)
[root@mysql ~]# ifconfig eth0: 192.168.0.52/ // 给网卡配置虚拟接口,相当于给网卡再配置一个IP地址(临时生效