Linux每日一篇 - 41 - ifconfig
Linux网络接口配置神器!掌握ifconfig命令,轻松管理网络接口,配置IP地址!
ifconfig命令是什么?
ifconfig是”Interface Configuration”的缩写,用于配置和显示网络接口参数的命令行工具,就像网络接口的”遥控器”。
基本用法
# 显示所有网络接口信息
ifconfig
# 显示指定网络接口信息
ifconfig eth0
# 启用网络接口
ifconfig eth0 up
# 禁用网络接口
ifconfig eth0 down
# 为网络接口分配IP地址
ifconfig eth0 192.168.1.100
# 设置网络接口的子网掩码
ifconfig eth0 netmask 255.255.255.0
# 设置网络接口的广播地址
ifconfig eth0 broadcast 192.168.1.255
实用技巧
# 显示所有接口(包括未激活的)
ifconfig -a
# 设置网络接口的MTU值
ifconfig eth0 mtu 1500
# 设置网络接口的MAC地址
ifconfig eth0 hw ether 00:11:22:33:44:55
# 临时修改IP地址
ifconfig eth0 10.0.0.10 netmask 255.255.255.0
# 查看接口统计信息
ifconfig eth0
# 为接口添加别名
ifconfig eth0:1 192.168.1.101
常用场景
# 查看网络接口状态
ifconfig
# 启用网卡
ifconfig eth0 up
# 禁用网卡
ifconfig eth0 down
# 临时修改IP地址
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
# 重启网络服务
ifconfig eth0 down && ifconfig eth0 up
# 查看特定接口信息
ifconfig wlan0
# 临时设置网关(需配合route命令)
ifconfig eth0 192.168.1.100
route add default gw 192.168.1.1