01.概括
由于在centos7和ubuntu16.04上,网卡的名称比较长,可以将它设置为ethX格式的
02.Centos7系统
$ uname -a
Linux centos.mai.cn 3.10.0-229.el7.x86_64 #1 SMP Fri Mar 6 11:36:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ sudo vim /etc/sysconfig/grub
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0" --多增加这两个参数
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
$ cat /etc/sysconfig/network-scripts/ifcfg-eth0 --可以更名为eth0
TYPE=Ethernet
PEFROUTE="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
BOOTPROTO=none
NAME=eth0
#DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.3.17
NETMASK=255.255.255.0
GATEWAY=192.168.3.1
DNS1=8.8.8.8
$ sudo reboot
$ ping -c 1 www.baidu.com
PING www.baidu.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38: icmp_seq=1 ttl=56 time=7.50 ms
03.ubuntu16.04系统
$ uname -a
Linux ubuntu 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ sudo vim /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="net.ifnames=0 biosdevname=0"
$ sudo grub-mkconfig -o /boot/grub/grub.cfg
$ sudo vim /etc/network/interfaces
auto eth0
iface eth0 inet static
address 192.168.3.21
netmask 255.255.255.0
gateway 192.168.3.1
dns-nameservers 8.8.8.8 114.114.114.114
$ sudo reboot
$ ping -c 1 www.baidu.com
PING www.baidu.com (14.215.177.38) 56(84) bytes of data.
64 bytes from 14.215.177.38: icmp_seq=1 ttl=56 time=7.50 ms
$ sudo sed -i 's/TimeoutStartSec=.*/TimeoutStartSec=2sec/' /etc/systemd/system/network-online.target.wants/networking.service #在重启时遇到的时间问题
一键脚本:
sudo sed -i "s/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT='net.ifnames=0 biosdevname=0'/g" /etc/default/grub
sudo grub-mkconfig -o /boot/grub/grub.cfg