原文鏈接:http://blog.csdn.net/nnuljl/article/details/38680107
1.前言
Ubuntu安裝完畢之后刻帚,如果發(fā)生異常宕機(jī),可能導(dǎo)致網(wǎng)卡的邏輯名出現(xiàn)異常对蒲,或者和之前的不一致。如果你的應(yīng)用處理是依據(jù)邏輯名俏让,那么有可能數(shù)據(jù)會(huì)傳輸?shù)椒穷A(yù)期的網(wǎng)卡接口上去笔咽,筆者今天要整理的是Ubuntu14.04的網(wǎng)卡邏輯名修改,筆者自己把這叫做”網(wǎng)卡固話“---網(wǎng)卡邏輯名固定化蔫巩。
2.網(wǎng)卡信息查詢
查看已啟用的網(wǎng)卡
root@ubuntu:~# ifconfig
eth0 Link encap:Ethernet HWaddr fa:16:3e:40:11:12
inet addr:172.18.0.9 Bcast:172.18.0.255 Mask:255.255.255.0
inet6 addr: fe80::f816:3eff:fe40:1112/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1400 Metric:1
RX packets:1327966 errors:0 dropped:0 overruns:0 frame:0
TX packets:22911 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:170759301 (170.7 MB) TX bytes:1282555 (1.2 MB)
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:65536 Metric:1
RX packets:2725810 errors:0 dropped:0 overruns:0 frame:0
TX packets:2725810 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:295593236 (295.5 MB) TX bytes:295593236 (295.5 MB)
上述HWaddr后面為eth0接口的MAC地址
查看已有邏輯名
[python] view plain copy
root@ubuntu:~# ls /sys/class/net/
eth0 lo
查看指定網(wǎng)卡MAC地址
[python] view plain copy
root@ubuntu:~# ifconfig eth0
eth0 Link encap:Ethernet HWaddr fa:16:3e:40:11:12
inet addr:172.18.0.9 Bcast:172.18.0.255 Mask:255.255.255.0
inet6 addr: fe80::f816:3eff:fe40:1112/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1400 Metric:1
RX packets:1328066 errors:0 dropped:0 overruns:0 frame:0
TX packets:23012 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:170767973 (170.7 MB) TX bytes:1293097 (1.2 MB)
[python] view plain copy
ifconfig <network-logicalname>
3.生成配置文件
[python] view plain copy
root@ubuntu:~# export INTERFACE="eth0"
root@ubuntu:~# export MATCHADDR="fa:16:3e:40:11:12"
root@ubuntu:~# /lib/udev/write_net_rules
root@ubuntu:~# ls /etc/udev/rules.d/
70-persistent-net.rules README
首先引入兩個(gè)變量INTERFACE谆棱,MATCHADDR快压,然后執(zhí)行write_net_rules,查看生成的文件70-persistent-net.rules
文件內(nèi)容如下,刪除KERNEL項(xiàng)垃瞧,并修改NAME值蔫劣。
[python] view plain copy
This file was automatically generated by the /lib/udev/write_net_rules
program, run by the persistent-net-generator.rules rules file.
You can modify it, as long as you keep each rule on a single
line, and change only the value of the NAME= key.
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?", ATTR{address}=="fa:16:3e:40:11:12", KERNEL=="eth", NAME="eth0"
修改后如下
[python] view plain copy
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="fa:16:3e:40:11:12", NAME="new-logicalname"
4.禁用源網(wǎng)卡邏輯名規(guī)則文件
[python] view plain copy
root@ubuntu:/etc/udev/rules.d# cd /lib/udev/rules.d/
root@ubuntu:/lib/udev/rules.d# mv 75-persistent-net-generator.rules 75-persistent-net-generator.rules.disabled
5.修改網(wǎng)卡配置
原網(wǎng)卡配置
[python] view plain copy
root@ubuntu:~# vim /etc/network/interfaces
This file describes the network interfaces available on your system
and how to activate them. For more information, see interfaces(5).
The loopback network interface
auto lo
iface lo inet loopback
The primary network interface
auto eth0
iface eth0 inet dhcp
修改為如下
[python] view plain copy
The primary network interface
auto new-logicalname
iface new-logicalname inet dhcp
不需要重啟網(wǎng)卡,直接重啟系統(tǒng)
6.重啟主機(jī)个从,查看新的網(wǎng)卡邏輯名
[python] view plain copy
root@ubuntu:~# ls /sys/class/net/
lo new-logicalname
root@ubuntu:~# ifconfig new-logicalname
new-logicalname Link encap:Ethernet HWaddr fa:16:3e:40:11:12
inet addr:172.18.0.9 Bcast:172.18.0.255 Mask:255.255.255.0
inet6 addr: fe80::f816:3eff:fe40:1112/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1400 Metric:1
RX packets:399 errors:0 dropped:0 overruns:0 frame:0
TX packets:357 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:36646 (36.6 KB) TX bytes:55027 (55.0 KB)
這樣以后所有的配置都可以使用新的網(wǎng)卡邏輯名拦宣。