centos 網卡重命名
centos網卡重命名
在cento卡模塊就是網卡的驅動程序,驅動程序是一種可以使計算機和設備通信的特殊程序,是硬件廠商根據操作系統編寫的配置文件,是添加到操作系統中的一小塊代碼,其中包含有關硬件設備的信息,相當於硬件的接口,操作系統只能通過這個接口,才能控制硬件設備的工作,s網如若系統沒有加載網卡模塊,則無法識別硬件物理網卡。
在centos6中查看系統所使用的網絡驅動ethtool工具:
[[email protected] ~]# ethtool -i eth0 #查看網卡驅動 driver: e1000 version: 7.3.21-k8-NAPI firmware-version: bus-info: 0000:02:01.0 supports-statistics: yes supports-test: yes supports-eeprom-access: yes supports-register-dump: yes supports-priv-flags: no [[email protected] ~]# modprobe -r e1000 #卸載網卡驅動後,ssh等斷開 ######################通過桌面終端查看驗證########################### [[email protected] */ ~]# ifconfig #卸載網卡驅動後,只有環回口 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:60 errors:0 dropped:0 overruns:0 frame:0 TX packets:60 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:5280 (5.1 KiB) TX bytes:5280 (5.1 KiB) [[email protected] net]# cd /lib/modules/2.6.32-696.el6.x86_64/kernel/drivers/net [[email protected] net]# ll |grep e100 #查看相關驅動安裝的位置 drwxr-xr-x. 2 root root 4096 Jul 14 10:39 e1000 drwxr-xr-x. 2 root root 4096 Jul 14 10:39 e1000e -rwxr--r--. 1 root root 66400 Mar 22 03:45 e100.ko [[email protected] net]# modprobe e1000 #裝載系統網卡模塊 |
在Linux系統之上一切皆文件,網卡的命名同樣由相關配置文件組成,在centos6中網卡的啟動識別文件/etc/udev/rules.d/70-persistent-net.rules,通過修改此配置文件即可實現網卡的重命名,具體可是將網卡重命名分為兩步:
第一步:修改/etc/udev/rules.d/70-persistent-net.rules配置文件
第二步:修改/etc/sysconfig/network-scripts/ifcfg-eth*中的 DEVICE=***和NAME=***配置文件
具體可參考如下實例:
[[email protected] ~]# sed -i ‘s/eth0/eth-DB1/;s/eth1/eth-DB2/‘ /etc/udev/rules.d/70-persistent-net.rules #第一步:通過sed處理 文件名字更改 [email protected] ~]# cat /etc/udev/rules.d/70-persistent-net.rules # 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. # PCI device 0x8086:0x100f (e1000) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:ad:7b:c1", ATTR{type}=="1", KERNEL=="eth*", NAME="eth-DB1" # PCI device 0x8086:0x100f (e1000) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:ad:7b:cb", ATTR{type}=="1", KERNEL=="eth*", NAME="eth-DB2" [[email protected] ~]# #第二步:修改配置文件中的設備name sed -i ‘s/eth0/eth-DB1/g‘ /etc/sysconfig/network-scripts/ifcfg-eth0 [[email protected] ~]# #第三步:修改配置文件中的設備name sed -i ‘s/eth1/eth-DB2/g‘ /etc/sysconfig/network-scripts/ifcfg-eth1 [[email protected] ~]# modprobe -r e1000 #卸載驅動模塊或重啟機器 ###############################通過桌面終端查看驗證############################ [[email protected] ~]# modprobe e1000 #重新加載驅動模塊 [[email protected] ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 8: eth-DB1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 #驗證說明配置文件已更改 link/ether 00:0c:29:ad:7b:c1 brd ff:ff:ff:ff:ff:ff inet 192.168.100.128/24 brd 192.168.100.255 scope global eth-DB1 inet6 fe80::20c:29ff:fead:7bc1/64 scope link valid_lft forever preferred_lft forever 9: eth-DB2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 #驗證說明配置文件已更改 link/ether 00:0c:29:ad:7b:cb brd ff:ff:ff:ff:ff:ff inet 172.18.253.115/16 brd 172.18.255.255 scope global eth-DB2 inet6 fe80::20c:29ff:fead:7bcb/64 scope link valid_lft forever preferred_lft forever |
在centos7中,正常情況下網卡的命名過程如下:
第一步:
udev, 輔助工具程序/lib/udev/rename_device/usr/lib/udev/rules.d/60-net.rules
第二步:
biosdevname會根據/usr/lib/udev/rules.d/71-biosdevname.rules
第三步:
通過檢測網絡接口設備,根據/usr/lib/udev/rules.d/75-net-description
ID_NET_NAME_ONBOARD
ID_NET_NAME_SLOT
ID_NET_NAME_PATH
如若采用傳統的網卡命名則采用如下方式:
1./etc/default/grub and add net.ifnames=0 biosdevname=0 to line GRUB_CMDLINE_LINUX,
2.grub2-mkconfig -o /boot/grub2/grub.cfg #修改開啟啟動引導文件,執行命令重新生效
3.vim /etc/sysconfig/network-scripts/ifcfg-eno1 #編輯配置網卡配置文件
......
NAME=eth0 #修改name和設備名稱
DEVICE=eth0
4. mv /etc/sysconfig/network-scripts/ifcfg-eno1 /etc/sysconfig/network-scripts/ifcfg-eth0
5. shutdown -r now #修改網卡1和網卡2位eth0和eth1
本文出自 “11831715” 博客,請務必保留此出處http://11841715.blog.51cto.com/11831715/1958144
centos 網卡重命名