歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

cnetos7更改網卡類型

centos 7.0安裝完成後,默認情況下網卡是不開機啟動的,而且對於網卡的命名也有所改變。在centos 5及以前的系統網卡命名為eth0

eth1這樣的名字,而到了centos 6時代網卡的名字改變成了em1 em2 這樣的名字,更大的變化出現在centos 7時代,網卡的名字直接

改變成了ens192 eno12312等的模樣。下面具體說下centos 7.0網卡的配置操作。

系統安裝完成,進入網卡的配置文件夾

[root@localhost network-scripts]# ll
total 232
-rw-r--r--. 1 root root   238 Jul 10 05:55 ifcfg-eno16777736
-rw-r--r--. 1 root root   254 Sep 16  2015 ifcfg-lo
lrwxrwxrwx. 1 root root    24 Jul 10 04:20 ifdown -> ../../../usr/sbin/ifdown
-rwxr-xr-x. 1 root root   627 Sep 16  2015 ifdown-bnep
-rwxr-xr-x. 1 root root  5817 Sep 16  2015 ifdown-eth
-rwxr-xr-x. 1 root root  6196 Nov 20  2015 ifdown-ib
-rwxr-xr-x. 1 root root   781 Sep 16  2015 ifdown-ippp
-rwxr-xr-x. 1 root root  4201 Sep 16  2015 ifdown-ipv6
lrwxrwxrwx. 1 root root    11 Jul 10 04:20 ifdown-isdn -> ifdown-ippp
-rwxr-xr-x. 1 root root  1642 Sep 16  2015 ifdown-post
-rwxr-xr-x. 1 root root  1068 Sep 16  2015 ifdown-ppp
-rwxr-xr-x. 1 root root   837 Sep 16  2015 ifdown-routes
-rwxr-xr-x. 1 root root  1444 Sep 16  2015 ifdown-sit
-rwxr-xr-x. 1 root root  1599 Apr  2  2015 ifdown-Team
-rwxr-xr-x. 1 root root  1556 Apr  2  2015 ifdown-TeamPort
-rwxr-xr-x. 1 root root  1462 Sep 16  2015 ifdown-tunnel
lrwxrwxrwx. 1 root root    22 Jul 10 04:20 ifup -> ../../../usr/sbin/ifup
-rwxr-xr-x. 1 root root 12631 Sep 16  2015 ifup-aliases
-rwxr-xr-x. 1 root root   859 Sep 16  2015 ifup-bnep
-rwxr-xr-x. 1 root root 11721 Sep 16  2015 ifup-eth
-rwxr-xr-x. 1 root root 10145 Nov 20  2015 ifup-ib
-rwxr-xr-x. 1 root root 12039 Sep 16  2015 ifup-ippp
-rwxr-xr-x. 1 root root 10430 Sep 16  2015 ifup-ipv6
lrwxrwxrwx. 1 root root     9 Jul 10 04:20 ifup-isdn -> ifup-ippp
-rwxr-xr-x. 1 root root   642 Sep 16  2015 ifup-plip
-rwxr-xr-x. 1 root root  1043 Sep 16  2015 ifup-plusb
-rwxr-xr-x. 1 root root  2609 Sep 16  2015 ifup-post
-rwxr-xr-x. 1 root root  4154 Sep 16  2015 ifup-ppp
-rwxr-xr-x. 1 root root  1925 Sep 16  2015 ifup-routes
-rwxr-xr-x. 1 root root  3263 Sep 16  2015 ifup-sit
-rwxr-xr-x. 1 root root  1755 Apr  2  2015 ifup-Team
-rwxr-xr-x. 1 root root  1876 Apr  2  2015 ifup-TeamPort
-rwxr-xr-x. 1 root root  2682 Sep 16  2015 ifup-tunnel
-rwxr-xr-x. 1 root root  1740 Sep 16  2015 ifup-wireless
-rwxr-xr-x. 1 root root  4623 Sep 16  2015 init.ipv6-global
-rw-r--r--. 1 root root 15322 Sep 16  2015 network-functions
-rw-r--r--. 1 root root 26134 Sep 16  2015 network-functions-ipv6
查看ip
[root@localhost ~]# 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
       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:80:4b:0a brd ff:ff:ff:ff:ff:ff
    inet 192.168.5.100/24 brd 192.168.5.255 scope global dynamic eno16777736
       valid_lft 84668sec preferred_lft 84668sec
    inet6 fe80::20c:29ff:fe80:4b0a/64 scope link 
       valid_lft forever preferred_lft forever
[root@localhost ~]#
首先,把網卡文件備份一份,然後將原來的網卡移動並改名成eth0,編輯網卡的配置文件 vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 將裡面的NAME項修改為

eth0

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-eno16777736  ifdown-ppp       ifup-ib      ifup-Team
ifcfg-lo           ifdown-routes    ifup-ippp    ifup-TeamPort
ifdown             ifdown-sit       ifup-ipv6    ifup-tunnel
ifdown-bnep        ifdown-Team      ifup-isdn    ifup-wireless
ifdown-eth         ifdown-TeamPort  ifup-plip    init.ipv6-global
ifdown-ib          ifdown-tunnel    ifup-plusb   network-functions
ifdown-ippp        ifup             ifup-post    network-functions-ipv6
ifdown-ipv6        ifup-aliases     ifup-ppp
ifdown-isdn        ifup-bnep        ifup-routes
ifdown-post        ifup-eth         ifup-sit
[root@localhost network-scripts]#
[root@localhost network-scripts]# cp ifcfg-eno16777736 ifcfg-bak
[root@localhost network-scripts]# mv ifcfg-eno16777736 ifcfg-eth0 
[root@localhost network-scripts]# vim ifcfg-eth0 
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="eth0"
DEVICE="eth0"
ONBOOT="yes"
控制設備名,不讓讓內核以它自己的方式命名
[root@localhost ~]# > /etc/udev/rules.d/70-persistent-ipoib.rules

禁用該可預測命名規則。對於這一點,你可以在啟動時傳遞“net.ifnames=0”的內核

參數。這是通過編輯/etc/default/grub並加入“net.ifnames=0”到GRUBCMDLINELINUX

變量來實現的。

[root@localhost network-scripts]# vim /etc/default/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 net.ifnames=0 biosdevname=0 

rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
執行:grub2-mkconfig -o /boot/grub2/grub.cfg
[root@localhost network-scripts]# 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-db79cc75da8e4cb7b1d044ee4b5fc069
Found initrd image: /boot/initramfs-0-rescue-

db79cc75da8e4cb7b1d044ee4b5fc069.img
done
重啟

[root@localhost /]# reboot
驗證網卡狀態
[root@localhost ~]# 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
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:80:4b:0a brd ff:ff:ff:ff:ff:ff
    inet 192.168.5.100/24 brd 192.168.5.255 scope global dynamic eth0
       valid_lft 86318sec preferred_lft 86318sec
    inet6 fe80::20c:29ff:fe80:4b0a/64 scope link 
       valid_lft forever preferred_lft forever
centos7啟動服務service的方式改為systemctl了

[root@localhost ~]# systemctl restart network

[root@localhost ~]# systemctl status network

[0m network.service - LSB: Bring up/down networking

Loaded: loaded (/etc/rc.d/init.d/network)

Active: active (exited) since Sun 2016-07-10 06:03:07 CST; 2min 25s ago

Docs: man:systemd-sysv-generator(8)

Process: 2965 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)

Process: 3145 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)

Jul 10 06:03:04 localhost.localdomain systemd[1]: Starting LSB: Bring up/down networking...

Jul 10 06:03:05 localhost.localdomain network[3145]: Bringing up loopback interface: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'

Jul 10 06:03:05 localhost.localdomain network[3145]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'

Jul 10 06:03:05 localhost.localdomain network[3145]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'

Jul 10 06:03:05 localhost.localdomain network[3145]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'

Jul 10 06:03:05 localhost.localdomain network[3145]: [ OK ]

Jul 10 06:03:07 localhost.localdomain network[3145]: Bringing up interface eth0: Connection successfully activated (D-Bus active path: /org/freedesktop/Ne...ection/1)

Jul 10 06:03:07 localhost.localdomain network[3145]: [ OK ]

Jul 10 06:03:07 localhost.localdomain systemd[1]: Started LSB: Bring up/down networking.

Hint: Some lines were ellipsized, use -l to show in full.

[root@localhost ~]#

本文出自 “子非魚” 博客,請務必保留此出處http://zyxjohn.blog.51cto.com/5313197/1813868

Copyright © Linux教程網 All Rights Reserved