centos 7.0安装完成后,默认情况下网卡是不开机启动的,而且对于网卡的命名也有所改变。在centos 5及以前的系统网卡命名为eth0
eth1这样的名字,而到了centos 6时代网卡的名字改变成了em1 em2 这样的名字,更大的变化出现在centos 7时代,网卡的名字直接
改变成了ens192 eno12312等的模样。下面具体说下centos 7.0网卡的配置操作。
系统安装完成,进入网卡的配置文件夹
[[email protected] 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
[[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 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 [[email protected] ~]#
首先,把网卡文件备份一份,然后将原来的网卡移动并改名成eth0,编辑网卡的配置文件 vi /etc/sysconfig/network-scripts/ifcfg-eno16777736 将里面的NAME项修改为
eth0
[[email protected] ~]# cd /etc/sysconfig/network-scripts/ [[email protected] 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 [[email protected] network-scripts]# [[email protected] network-scripts]# cp ifcfg-eno16777736 ifcfg-bak [[email protected] network-scripts]# mv ifcfg-eno16777736 ifcfg-eth0 [[email protected] 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"
控制设备名,不让让内核以它自己的方式命名
[[email protected] ~]# > /etc/udev/rules.d/70-persistent-ipoib.rules
禁用该可预测命名规则。对于这一点,你可以在启动时传递“net.ifnames=0”的内核
参数。这是通过编辑/etc/default/grub并加入“net.ifnames=0”到GRUBCMDLINELINUX
变量来实现的。
[[email protected] 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
[[email protected] 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
重启
[[email protected] /]# reboot
验证网卡状态
[[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 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了
[[email protected] ~]# systemctl restart network
[[email protected] ~]# 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.
[[email protected] ~]#