centos7实战之网卡名从eth1改为eth0,设置固定IP

centos网卡名从eth1改为eth0,设置固定IP

网卡名默认是eth0,那为什么会变成eth1呢?

是因为我们在开启linux镜像的时候,点了复制该虚拟机导致的。
在这里插入图片描述

修改eth0

vim  /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:d3:d1:35", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0C:29:B5:B2:69", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

此时如果你去修改/etc/sysconfig/network-scripts/ifcfg-eth0文件,改IP是没有用的,因为现在系统起作用的是eth1网卡,而这个文件只对eth0有效(我试的是这样,如果错了请告我)。

所以我们需要把/etc/udev/rules.d/70-persistent-net.rules 中的eth0删除,然后把eth1改成eth0。改完之后我们还需修改/etc/sysconfig/network-scripts/ifcfg-eth0文件

设置固定IP

vim /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:51:62:2d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

此时只有我们设置好的eth0网卡了,我们需要把eth0的网卡地址在/etc/sysconfig/network-scripts/ifcfg-eth0配置一下即可

vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #网卡名称
HWADDR=00:0c:29:51:62:2d #MAC地址改成eth0的地址就行
TYPE=Ethernet
UUID=ea47e492-95cc-4d39-b186-ba1bc3b189e2
ONBOOT=yes #相当于启动这个网卡的开关,你要用eth0这个一定要yes,表示开
NM_CONTROLLED=yes 
BOOTPROTO=static #获取ip的方式(static/dhcp(动态获取)/bootp/none) 
IPADDR=192.168.211.130 #IP地址 我们需要设的(注意要和自己电脑同一网段呀!不然ping不通)
NETMASK=255.255.255.0 #子网掩码
NETWORK=192.168.211.0 #网络地址
BROADCAST=192.168.0.255 #广播地址
NBROOT=yes  #  系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备。

修改完成后,把虚拟机镜像重启即可了,如果不重启,则当前的虚拟机还是使用的eth1。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值