Linux ifconfig ip 命令详解

📂 365bet足球比分直播 ⏳ 2025-10-29 19:33:32 👽 admin 👁️ 3754 💾 249
Linux ifconfig ip 命令详解

简介

ifconfig 和 ip 命令用于配置和显示 Linux 上的网络接口。虽然 ifconfig 是传统工具,但现在已被弃用并被提供更多功能的 ip 命令取代。

ifconfig

安装

sudo apt install net-tools

sudo yum install net-tools

查看所有活动的网络接口

ifconfig

启动/激活网络接口

sudo ifconfig up

# 例如:

sudo ifconfig eth0 up

# eth0:代表系统上的第一个以太网网络接口

# 其他的网络接口名字示例:

# wlan0:第一个无线网络接口

# lo:环回接口,用于同一台机器内的本地通信

# enp0s3:有线以太网接口的可预测名称

关闭/停用网络接口

sudo ifconfig down

# 例如:

sudo ifconfig eth0 down

分配 IP 地址

sudo ifconfig netmask

# 例如:

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0

分配广播地址

sudo ifconfig broadcast

# 例如:

sudo ifconfig eth0 broadcast 192.168.1.255

启用混杂模式

sudo ifconfig promisc

# 例如:

sudo ifconfig eth0 promisc

禁用混杂模式

sudo ifconfig -promisc

# 例如:

sudo ifconfig eth0 -promisc

ip 命令

查看所有网络接口

ip link show

查看所有接口的IP地址

ip addr show

查看具体接口详情

ip addr show

# 例如:

ip addr show eth0

启用网络接口

sudo ip link set up

# 例如:

sudo ip link set eth0 up

禁用网络接口

sudo ip link set down

# 例如:

sudo ip link set eth0 down

分配IP地址

sudo ip addr add / dev

# 例如:

sudo ip addr add 192.168.1.100/24 dev eth0

移除IP地址

sudo ip addr del / dev

# 例如:

sudo ip addr del 192.168.1.100/24 dev eth0

显示路由表

ip route show

添加默认网关

sudo ip route add default via

# 例如:

sudo ip route add default via 192.168.1.1

删除路由

sudo ip route del /

# 例如:

sudo ip route del 192.168.1.0/24

相关数据包

中国童星女歌手排行榜概览:热门歌曲与成长风采(2025版)
玩迷你世界卡顿怎么办 迷你世界卡顿解决方法一览
千万别碰,揭秘流量魔盒骗人的秘密

千万别碰,揭秘流量魔盒骗人的秘密

📅 08-12 🔗 365bet足球比分直播
峰回路转草木青,小径九转十八湾指什么生肖,精选解释词语释义
← 数字钱包借款时间解析:最长可借多久? 在PPT中如何设置背景音乐提升演示效果? →