服務報價 | 域名主機 | 網絡營銷 | 軟件工具| [加入收藏]
?熱線電話: 130-5800-8007
當前位置: 主頁 > 開發教程 > linux教程 >

CentOS 7.2更改網卡名稱

時間:2017-01-14 17:41來源:未知 作者:最模板 點擊:
CentOS 7.2更改網卡名稱,就是VMWare裝的CentOS虛擬機的自帶網卡名有點亂,想重新定義一下。 環境 1、VMWare虛擬機 6張網卡 2、系統 [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (
CentOS 7.2更改網卡名稱,就是VMWare裝的CentOS虛擬機的自帶網卡名有點亂,想重新定義一下。

 

環境

1、VMWare虛擬機

6張網卡

 

2、系統

[[email protected] ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

并且是最小化安裝。

 

網卡信息

 

網卡配置文件

 

配置內容

復制代碼
[[email protected] network-scripts]# cat ifcfg-eno16777736 
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=1160a71e-e5b5-4378-b742-c1bf0cba6f00
DEVICE=eno16777736
ONBOOT=no
復制代碼

 

這里啟動下網卡,獲得IP,好連接shell

復制代碼
[[email protected] network-scripts]# sed -i '/ONBOOT/s/no/yes/' ifcfg-eno*
[[email protected] network-scripts]# systemctl restart network
[[email protected] network-scripts]# ip addr
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
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.128/24 brd 192.168.140.255 scope global dynamic eno16777736
       valid_lft 1799sec preferred_lft 1799sec
    inet6 fe80::20c:29ff:fea3:b15c/64 scope link 
       valid_lft forever preferred_lft forever
3: eno33554960: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:66 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.129/24 brd 192.168.140.255 scope global dynamic eno33554960
       valid_lft 1800sec preferred_lft 1800sec
    inet6 fe80::20c:29ff:fea3:b166/64 scope link 
       valid_lft forever preferred_lft forever
4: eno50332184: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:70 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.130/24 brd 192.168.140.255 scope global dynamic eno50332184
       valid_lft 1800sec preferred_lft 1800sec
    inet6 fe80::20c:29ff:fea3:b170/64 scope link 
       valid_lft forever preferred_lft forever
5: eno67109408: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:7a brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.131/24 brd 192.168.140.255 scope global dynamic eno67109408
       valid_lft 1800sec preferred_lft 1800sec
    inet6 fe80::20c:29ff:fea3:b17a/64 scope link 
       valid_lft forever preferred_lft forever
6: eno83886632: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:84 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.132/24 brd 192.168.140.255 scope global dynamic eno83886632
       valid_lft 1800sec preferred_lft 1800sec
    inet6 fe80::20c:29ff:fea3:b184/64 scope link 
       valid_lft forever preferred_lft forever
7: eno100663856: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:8e brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.133/24 brd 192.168.140.255 scope global dynamic eno100663856
       valid_lft 1801sec preferred_lft 1801sec
    inet6 fe80::20c:29ff:fea3:b18e/64 scope link 
       valid_lft forever preferred_lft forever
[[email protected] network-scripts]# 
復制代碼

默認使用DHCP,都是自動獲取的IP

 

配置

CentOS7使用了“一致性網絡命名方法”,這里舉例,將網卡名截斷為前5個字符,如eno16777736改為eno16。

1、更改網卡配置文件名

復制代碼
[[email protected] network-scripts]# ll
total 252
-rw-r--r--. 1 root root   290 Jan 11 22:41 ifcfg-eno10
-rw-r--r--. 1 root root   288 Jan 11 22:41 ifcfg-eno16
-rw-r--r--. 1 root root   288 Jan 11 22:41 ifcfg-eno33
-rw-r--r--. 1 root root   288 Jan 11 22:41 ifcfg-eno50
-rw-r--r--. 1 root root   288 Jan 11 22:41 ifcfg-eno67
-rw-r--r--. 1 root root   288 Jan 11 22:41 ifcfg-eno83
-rw-r--r--. 1 root root   254 Sep 16  2015 ifcfg-lo
lrwxrwxrwx. 1 root root    24 Jan 11 22:31 ifdown -> ../../../usr/sbin/ifdown
-rwxr-xr-x. 1 root root   627 Sep 16  2015 ifdown-bnep
[[email protected] network-scripts]# 
復制代碼

 

并更改配置文件內容,舉例

復制代碼
[[email protected] network-scripts]# cat ifcfg-eno16 
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16
UUID=803d2d05-493b-489b-8201-1d3fc67878aa
DEVICE=eno16
ONBOOT=yes
[[email protected] network-scripts]# 
復制代碼

  

2、關閉“一致性網絡設備命名法”

更改前

復制代碼
[[email protected] ~]# cat /etc/sysconfig/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
[[email protected] ~]# 
復制代碼

 

添加net.ifnames=0 biosdevname=0

更改后

復制代碼
[[email protected] ~]# cat /etc/sysconfig/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap net.ifnames=0 biosdevname=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
[[email protected] ~]# 
復制代碼

 

更新GRUB、內核配置

復制代碼
[[email protected] ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-f034e6e19df748b7a27fad77b06e3179
Found initrd image: /boot/initramfs-0-rescue-f034e6e19df748b7a27fad77b06e3179.img
done
[[email protected] ~]# 
復制代碼

 

3、添加設備規則配置文件

修改/etc/udev/rules.d/70-persistent-net.rules,沒有該文件則新建文件

內容如下

復制代碼
[[email protected] ~]# cat /etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:5c", ATTR{type}=="1", KERNEL=="eth*", NAME="eno16"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:8e", ATTR{type}=="1", KERNEL=="eth*", NAME="eno10"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:66", ATTR{type}=="1", KERNEL=="eth*", NAME="eno33"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:70", ATTR{type}=="1", KERNEL=="eth*", NAME="eno50"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:7a", ATTR{type}=="1", KERNEL=="eth*", NAME="eno67"
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:a3:b1:84", ATTR{type}=="1", KERNEL=="eth*", NAME="eno83"
[[email protected] ~]# 
復制代碼

注意MAC地址與NAME相匹配(可以用ip addr查看)

 

4、重啟

[[email protected] ~]# reboot

 

使用

復制代碼
[[email protected] ~]# ip addr
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
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.128/24 brd 192.168.140.255 scope global dynamic eno16
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b15c/64 scope link 
       valid_lft forever preferred_lft forever
3: eno33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:66 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.129/24 brd 192.168.140.255 scope global dynamic eno33
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b166/64 scope link 
       valid_lft forever preferred_lft forever
4: eno50: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:70 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.130/24 brd 192.168.140.255 scope global dynamic eno50
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b170/64 scope link 
       valid_lft forever preferred_lft forever
5: eno67: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:7a brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.131/24 brd 192.168.140.255 scope global dynamic eno67
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b17a/64 scope link 
       valid_lft forever preferred_lft forever
6: eno83: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:84 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.132/24 brd 192.168.140.255 scope global dynamic eno83
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b184/64 scope link 
       valid_lft forever preferred_lft forever
7: eno10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:8e brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.133/24 brd 192.168.140.255 scope global dynamic eno10
       valid_lft 1768sec preferred_lft 1768sec
    inet6 fe80::20c:29ff:fea3:b18e/64 scope link 
       valid_lft forever preferred_lft forever
[[email protected] ~]# 
復制代碼

看見網卡名稱都已經更改了

 

再來設置個靜態ip,以eno83為例

復制代碼
[[email protected] network-scripts]# cat ifcfg-eno83 
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno83
UUID=919f599a-c262-4868-be7e-0646b1e98dee
DEVICE=eno83
IPADDR=192.168.140.140
PREFIX=24
ONBOOT=yes
[[email protected] network-scripts]# 
復制代碼

 

重啟網絡

復制代碼
[[email protected] network-scripts]# systemctl restart network
[[email protected] network-scripts]# 
[[email protected] network-scripts]# 
[[email protected] network-scripts]# ip addr
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
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:5c brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.128/24 brd 192.168.140.255 scope global dynamic eno16
       valid_lft 1802sec preferred_lft 1802sec
    inet6 fe80::20c:29ff:fea3:b15c/64 scope link 
       valid_lft forever preferred_lft forever
3: eno33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:66 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.129/24 brd 192.168.140.255 scope global dynamic eno33
       valid_lft 1802sec preferred_lft 1802sec
    inet6 fe80::20c:29ff:fea3:b166/64 scope link 
       valid_lft forever preferred_lft forever
4: eno50: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:70 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.130/24 brd 192.168.140.255 scope global dynamic eno50
       valid_lft 1803sec preferred_lft 1803sec
    inet6 fe80::20c:29ff:fea3:b170/64 scope link 
       valid_lft forever preferred_lft forever
5: eno67: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:7a brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.131/24 brd 192.168.140.255 scope global dynamic eno67
       valid_lft 1803sec preferred_lft 1803sec
    inet6 fe80::20c:29ff:fea3:b17a/64 scope link 
       valid_lft forever preferred_lft forever
6: eno83: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:84 brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.140/24 brd 192.168.140.255 scope global eno83
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fea3:b184/64 scope link 
       valid_lft forever preferred_lft forever
7: eno10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a3:b1:8e brd ff:ff:ff:ff:ff:ff
    inet 192.168.140.133/24 brd 192.168.140.255 scope global dynamic eno10
       valid_lft 1802sec preferred_lft 1802sec
    inet6 fe80::20c:29ff:fea3:b18e/64 scope link 
       valid_lft forever preferred_lft forever
[[email protected] network-scripts]# 
復制代碼

 

改好了~

 

ps:

 

 

1、如果沒有“配置-3添加設備規則配置文件“這步,其他不變,系統重啟后將使用eth0、eth1、eth2、...這樣的網卡名,此時系統會嘗試啟動配置文件(eno16等)描述的網卡,但網卡不存在,這些網卡將啟動失敗,并且開機后無法重啟網絡,提示failed to start lsb:bring up/down巴拉巴拉~

2、/etc/sysconfig/network-scripts這里目錄里的網卡配置文件不要有多余的,每個ifcfg-xxxx對應且僅對應一個網卡,否則容易造成重啟網絡失敗,提示failed to start lsb:bring up/down巴拉巴拉~

3、按這個順序更改,可以避免更改網卡名稱并重啟之后,無法重啟network的情況。

(責任編輯:最模板)
頂一下
(0)
0%
踩一下
(0)
0%
------分隔線----------------------------
体彩22选5开奖结果