一、简介
ifconfig命令常用于配置或显示指定的网络接口信息,默认情况下ifconfig会显示当前运行的网络接口信息。使用ifconfig命令配置的网络信息是临时的,要想使其永久生效,需要将对应的配置信息写入/etc/sysconfig/network-scripts/下的接口配置文件当中。
二、ifconfig命令的使用
1、命令格式
ifconfig [-v] [-a] [-s] [interface]
ifconfig [-v] interface [aftype] options | address ...
2、通用选项
-a:显示所有的接口信息,包括状态为关闭的接口;
-s:以断格式的形式显示相应的接口信息;
3、接口选项
up/down:开启或关闭指定的接口;
[-]arp:开启或关闭指定接口的arp协议;
[-]promisc:开启或关闭接口的混杂模式;
[-]allmulti:开机或关闭接口的多播模式,开启后接口会接收网络中的多播包;
mtu #:设置mtu的大小为#。
address:为指定的接口配置IP;
netmask NETMASK:为指定的接口配置子网掩码;
三、实例
- 显示目前系统上所有的接口信息:
[root@localhost ~]# ifconfig -a
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 188.88.88.42 netmask 255.255.255.0 broadcast 188.88.88.255
inet6 fe80::20c:29ff:fe5f:a431 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:5f:a4:31 txqueuelen 1000 (Ethernet)
RX packets 1803 bytes 158713 (154.9 KiB)
RX errors 0 dropped 1 overruns 0 frame 0
TX packets 760 bytes 156650 (152.9 KiB)
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<host>
loop txqueuelen 0 (Local Loopback)
RX packets 4 bytes 340 (340.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 340 (340.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 00:00:00:00:00:00 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0-nic: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:e1:57:76 txqueuelen 500 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- 关闭指定的接口:
[root@localhost ~]# ifconfig virbr0 down
- 更改指定的接口Ip:
[root@localhost ~]# ifconfig eno16777736 192.168.122.200 netmask 255.255.255.0