智传网优云课堂,专注分享IT技术
与IT技术爱好者一起共同学习进步

Linux设置查看静态IP之ifconfig命令

1. ifconfig命令简介

Linux系统中使用ifconfig命令查看和修改IP信息。但新系统建议使用ip命令。
CentOS 7 开始,已经废弃了ifconfig命令,ifconfig命令由net-tools套件提供。

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

[root@zcwyou ~]# 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信息以及入口流量信息和出口流量信息

[root@zcwyou ~]# ifconfig

ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> 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<UP,LOOPBACK,RUNNING> 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. 禁用和启动网卡

[root@zcwyou ~]# ifconfig eth0 down
[root@zcwyou ~]# ifconfig eth0 up

或者:

[root@zcwyou ~]# ifdown ens33 && ifup ens33

linux禁用和重新启动网卡

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

[root@zcwyou ~]# ifconfig eth0 172.16.26.88 netmask 255.255.255.0 broadcast 172.16.26.255

5. 修改mtu大小

[root@zcwyou ~]# ifconfig eth0 mtu 1500 

6. 总结

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

赞(0)
未经允许不得转载:Linux入门学习到精通 » Linux设置查看静态IP之ifconfig命令
分享到: 更多 (0)

学习QQ群:557371664

关注微信公众号自助视频学习

评论 抢沙发

评论前必须登录!