分类:
2009-12-19 04:05:06
使用ifconfig命令
标准形式:
# ifconfig device_name hw ether MAC_address
例如:
# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE
SIOCSIFHWADDR: Device or resource busy
因为eth0正在使用,所以需要先执行ifdown操作。
现在做一个试验,我们先来查看eth0的配置文件,
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
HWADDR=00:0c:29:6a:56:56
NETMASK=255.255.255.0
IPADDR=192.168.1.9
TYPE=Ethernet
将eth0关闭,更改其物理网卡,
# ifdown eth0
# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE
# service network restart
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:AA:BB:CC:DD:EE
inet addr:192.168.1.9 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:217441 errors:0 dropped:0 overruns:0 frame:0
TX packets:845 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13095796 (12.4 MiB) TX bytes:116175 (113.4 KiB)
Interrupt:169 Base address:0x2000
这个时候如果想重启eth0或者关闭eth0都会失败,
# service network restart
Shutting down interface eth0: Device eth0 has MAC address 00:AA:BB:CC:DD:EE, instead of configured address 00:0C:29:6A:56:56. Ignoring.
[FAILED]
这是为什么呢?查看一下eth0的配置文件,发现HWADDR的值并没有改变,但是/etc/init.d/network这个程序是要读取这个配置文件的。
现在,对eth0的操作都不能生效了。想用ifconfig命令将MAC地址改回去也不可以,因为eth0一直开启。想到了一个办法,先把配置文件里的HWADDR值记住,再将配置文件里的HWADDR的值改为“00:AA:BB:CC:DD:EE”,然后再关闭eth0,这次可以正常关闭了。这时再用ifconfig命令将MAC地址改为原来的值,这里是“00:0C:29:6A:56:56”。启动后MAC变成了原来的MAC。
# ifconfig eth0 hw ether 00:0C:29:6A:56:56
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:6A:56:56
inet addr:192.168.1.9 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe6a:5656/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:218729 errors:0 dropped:0 overruns:0 frame:0
TX packets:1460 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:13206469 (12.5 MiB) TX bytes:201006 (196.2 KiB)
Interrupt:169 Base address:0x2000