ifconfig 命令详解
显示行号
|
选择喜欢的代码风格
默认
GitHub
Dune
LakeSide
Plateau
Vibrant
Blue
Eighties
Tranquil
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
ifconfig 命令配置和显示 Linux 系统网卡的网络参数。在现代 Linux 系统上,ip 命令已替换 ifconfig。
ifconfig 命令安装:
-bash: ifconfig: command not found
#Debian
apt-get install net-tools
#Ubuntu
apt-get install net-tools
#Arch Linux
pacman -S net-tools
#Kali Linux
apt-get install net-tools
#CentOS
yum install net-tools
#Fedora
dnf install net-tools
#Raspbian
apt-get install net-tools
#Docker
docker run cmd.cat/ifconfig ifconfig
ifconfig 命令补充说明:
ifconfig 代表“接口配置”。 它用于查看和更改系统上网络接口的配置。ifconfig用于配置系统的内核驻留网络接口。 它在引导时用于根据需要设置接口。 此后,通常仅在调试或需要系统调整时才需要它。
如果未提供任何参数,则 ifconfig 将显示系统活动接口的状态。
如果给出单个接口参数,则仅显示给定接口的状态。
如果仅给出一个 -a 参数,则它将显示所有接口的状态,即使是那些“关闭”(不活动)的接口。
在所有其他情况下,ifconfig 根据提供的选项配置接口。
ifconfig 命令语法:
ifconfig [-v] [-a] [-s] [interface]
ifconfig [-v] interface [aftype] options | address ...
ifconfig 命令选项:
add<地址>:设置网络设备IPv6的ip地址;
del<地址>:删除网络设备IPv6的IP地址;
down:关闭指定的网络设备;
io_addr:设置网络设备的I/O地址;
irq
media<网络媒介类型>:设置网络设备的媒介类型;
mem_start<内存地址>:设置网络设备在主内存所占用的起始地址;
metric<数目>:指定在计算数据包的转送次数时,所要加上的数目;
mtu<字节>:设置网络设备的MTU;
netmask<子网掩码>:设置网络设备的子网掩码;
tunnel<地址>:建立IPv4与IPv6之间的隧道通信地址;
up:启动指定的网络设备;
-broadcast<地址>:将要送往指定地址的数据包当成广播数据包来处理;
-pointopoint<地址>:与指定地址的网络设备建立直接连线,此模式具有保密功能;
-promisc:关闭或启动指定网络设备的promiscuous模式;
IP地址:指定网络设备的IP地址;
网络设备:指定网络设备的名称。
ifconfig 命令实例
显示网络设备信息(激活状态的):
$ ifconfig
eth0: flags=4163
inet 192.168.0.3 netmask 255.255.240.0 broadcast 192.168.15.255
inet6 fe80::f816:3eff:fead:d65d prefixlen 64 scopeid 0x20
ether fa:16:3e:ad:d6:5d txqueuelen 1000 (Ethernet)
RX packets 864311275 bytes 101734334939 (94.7 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1343329615 bytes 1275961324860 (1.1 TiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 14111 bytes 1482133 (1.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14111 bytes 1482133 (1.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
#eth0 表示第一块网卡, inet addr 用来表示网卡的IP地址
#lo 是表示主机的回坏地址,这个一般是用来测试一个网络程序,但又不想让局域网或外网的用户能够查看,
#只能在此台主机上运行和查看所用的网络接口。比如把 httpd服务器的指定到回坏地址,
#在浏览器输入127.0.0.1就能看到你所架WEB网站了。但只是您能看得到,局域网的其它主机或用户无从知道。
启动关闭指定网卡:
ifconfig eth0 up
ifconfig eth0 down
#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地址
用 ifconfig 修改 MAC 地址:
ifconfig eth0 hw ether 00:AA:BB:CC:dd:EE
配置 IP 地址:
[root@localhost ~]# ifconfig eth0 192.168.2.10
[root@localhost ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0
[root@localhost ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0 broadcast 192.168.2.255
启用和关闭 arp 协议:
ifconfig eth0 arp #开启网卡eth0 的arp协议
ifconfig eth0 -arp #关闭网卡eth0 的arp协议
设置最大传输单元:
ifconfig eth0 mtu 1500 #设置能通过的最大数据包大小为 1500 bytes
停用网络接口 wlan0。
ifconfig wlan0 down
将网络接口 wlan1 配置为使用静态 IP 地址 122.140.201.66。
ifconfig wlan0 netmask 255.255.255.0
ifconfig 其他实例:
ifconfig #处于激活状态的网络接口
ifconfig -a #所有配置的网络接口,不论其是否激活
ifconfig eth0 #显示eth0的网卡信息
ifconfig 命令扩展阅读:
Linux ifconfig command
ifconfig:最熟悉又陌生的命令行
arp 命令
IPv4 地址查询(IP 库查询)
dhclient 命令
ping 命令
CommandNotFound ⚡️ 坑否 - 其他频道扩展阅读:
msginit 命令aapt 命令ngx_waf 安装避坑sendmail 命令rustc 命令
上一页
下一页
ifconfig 命令评论