Linux ifconfig命令:显示和配置网络接口。
Linux ifconfig命令 功能描述
使用ifconfig命令可以显示和配置网络接口,比如设置IP地址、MAC地址、激活或关闭网络接口。
Linux ifconfig命令 语法
ifconfig [接口] [选项| IP地址]
选项含义:
命令中各选项的含义如表所示。
Linux ifconfig命令 示例
配置网卡eth0的IP地址,同时激活该设备
[root@rhel ~]# ifconfig eth0192.168.0.2 netmask 255.255.255.0 up
配置网卡eth0的别名设备eth0:1的IP地址
[root@rhel ~]# ifconfig eth0:1192.168.0.3
激活网卡eth0:1设备
[root@rhel ~]# ifconfig eth0:1 up
查看网卡eth0设置的配置
[root@rhel ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:FC:2F:E5
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fefc:2fe5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11833 errors:0 dropped:0 overruns:0 frame:0
TX packets:14789 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:953120(930.7 KiB) TX bytes:12258316(11.6 MiB)
//eth0网卡的IP地址是192.168.0.2, MAC地址是00:0C:29:FC:2F:E5
查看所有启用的网卡设备
[root@rhel ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:FC:2F:E5
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fefc:2fe5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:11802 errors:0 dropped:0 overruns:0 frame:0
TX packets:14766 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:950646(928.3 KiB) TX bytes:12253702(11.6 MiB)
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:FC:2F:E5
inet addr:192.168.0.3 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:340 errors:0 dropped:0 overruns:0 frame:0
TX packets:340 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:28910(28.2 KiB) TX bytes:28910(28.2 KiB)
查看所有的网卡设备
[root@rhel ~]# ifconfig -a
关闭网卡eth0:1设备
[root@rhel ~]# ifconfig eth0:1 down
更改网卡eth0的硬件MAC地址为00:0C:29:18:2E:3D
[root@rhel ~]# ifconfig eth0 hw ether 00:0C:29:18:2E:3D