ifconfig: network interfaces configuring :可设置网络设备的状态,或是显示目前的设置。
使用 ifconfig 命令对网卡所做的配置都是临时配置,重启之后都会被还原的。如果要永久配置网卡则需要通过修改配置文件的方式。
显示所有网络接口的配置:
如果网卡被关闭了则不会被显示出来
ifconfig
# 显示指定网卡的信息:
ifconfig 网卡名称
//例:ifconfig ens33
inet addr:IPv4地址
inet6 addr:IPv6地址
RX一行:分别表示网卡从启动到现在所接收的 总包数、错误数、丢弃数、过载数、帧数
TX一行:分别表示网卡从启动到现在所发送的 总包数、错误数、丢弃数、过载数、帧数
显示网络接口的统计信息:
例如,发送和接收的数据包数量:
# 所有信息
ifconfig -a
# 简要信息
ifconfig -s
激活或关闭网络接口:
ifconfig 网卡名 up # 激活接口
ifconfig 网卡名 down # 关闭接口
设置网卡配置 IPv4/6 地址 :
#修改 指定网卡 的 IPv4地址
ifconfig 网卡 IP
#修改 指定网卡 的 IPv4地址及子网掩码:
ifconfig 网卡 IP/掩码
#或
ifconfig 网卡 IP netmask 255.255.255.0
#ipv6
#为网卡设置IPv6地址
ifconfig 网卡名 add 33ffe:3240:800:1005::2/ 64
#为网卡删除IPv6地址
ifconfig 网卡名 del 33ffe:3240:800:1005::2/ 64
设置网卡的MAC地址(临时):
注意:需要将网卡down掉后才能设置,否则会提示 “SIOCSIFHWADDR: 设备或资源忙 - you may need to down the interface”
ifconfig 网卡 hw ether MAC地址
#
ifconfig ens33 hw ether 08:00:27:bd:61:3d
设置网卡的最大传输单元(临时):
单位是字节 :
ifconfig ens33 mtu 1480