一、簡介
ifconfig命令常用于配置或顯示指定的網絡接口信息奏篙,默認情況下ifconfig會顯示當前運行的網絡接口信息宋光。使用ifconfig命令配置的網絡信息是臨時的,要想使其永久生效叽粹,需要將對應的配置信息寫入/etc/sysconfig/network-scripts/下的接口配置文件當中览效。
二、ifconfig命令的使用
1虫几、命令格式
ifconfig [-v] [-a] [-s] [interface]
ifconfig [-v] interface [aftype] options | address ...
2锤灿、通用選項
-a:顯示所有的接口信息,包括狀態(tài)為關閉的接口辆脸;
-s:以斷格式的形式顯示相應的接口信息但校;
3、接口選項
up/down:開啟或關閉指定的接口啡氢;
[-]arp:開啟或關閉指定接口的arp協(xié)議状囱;
[-]promisc:開啟或關閉接口的混雜模式;
[-]allmulti:開機或關閉接口的多播模式倘是,開啟后接口會接收網絡中的多播包亭枷;
mtu #:設置mtu的大小為#。
address:為指定的接口配置IP搀崭;
netmask NETMASK:為指定的接口配置子網掩碼叨粘;
三、實例
- 顯示目前系統(tǒng)上所有的接口信息:
[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