APP下载

Linux设定和检视静态IP之ifconfig命令

消息来源:baojiabao.com 作者: 发布时间:2026-05-14

报价宝综合消息Linux设定和检视静态IP之ifconfig命令

1. ifconfig命令简介

Linux系统中使用ifconfig命令检视和修改IP资讯。但新系统建议使用ip命令。

CentOS 7 开始,已经废弃了ifconfig命令,ifconfig命令由net-tools套件提供。

CentOS 7预设并没有安装这个套件,需要手动额外安装。

[[email protected] ~]# yum -y install net-tools

总下载量:306 k

安装大小:918 k

Downloading packages:

net-tools-2.0-0.24.20131004git.el7.x86_64.rpm | 306 kB 00:00:00

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

正在安装 : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1

验证中 : net-tools-2.0-0.24.20131004git.el7.x86_64 1/1

已安装:

net-tools.x86_64 0:2.0-0.24.20131004git.el7

完毕!

linux安装ifconfig命令

2. 检视网络卡资讯,包括IP资讯以及入口流量资讯和出口流量资讯

[[email protected] ~]# ifconfig

ens160: flags=4163 mtu 1500

inet 113.105.164.151 netmask 255.255.255.192 broadcast 113.105.164.191

inet6 fe80::4e97:36a0:c406:6ac1 prefixlen 64 scopeid 0x20

ether 00:0c:29:dc:f4:8f txqueuelen 1000 (Ethernet)

RX packets 143511935 bytes 146703282343 (136.6 GiB)

RX errors 0 dropped 779125 overruns 0 frame 0

TX packets 92937512 bytes 141760328247 (132.0 GiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73 mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10

loop txqueuelen 1000 (Local Loopback)

RX packets 52922204 bytes 139829819707 (130.2 GiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 52922204 bytes 139829819707 (130.2 GiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

linux使用ifconfig检视网络卡与IP地址资讯

3. 禁用和启动网络卡

[[email protected] ~]# ifconfig eth0 down

[[email protected] ~]# ifconfig eth0 up

或者:

[[email protected] ~]# ifdown ens33 && ifup ens33

linux禁用和重新启动网络卡

4. 配置网络卡的IP地址与广播地址

[[email protected] ~]# ifconfig eth0 172.16.26.88 netmask 255.255.255.0 broadcast 172.16.26.255

5. 修改mtu大小

[[email protected] ~]# ifconfig eth0 mtu 1500

6. 总结

ifdown命令是net-tools套件之一,但目前已经不建议使用net-tools套件了,因为已经有了iproute2这个现代的网络管理工具。CentOS7开始,预设已经不再整合net-tools,而是集成了iproute2。

2020-01-19 19:49:00

相关文章