Linux系统Centos没有网卡eth0配置文件怎么办

Linux系统Centos没有网卡eth0配置文件怎么办,第1张

CentOS中没有ifcfg-eth0 配置文件的解决办法

用 CentOS-6.5-i386-LiveDVD.iso镜像安装好CentOS 6.5系统后(已经把系统写入硬盘),发现ip在每次重启后都会还原,用ifconfig查看是有eth0网卡的(也有可能只有回环网卡lo),于是查看eth0网卡配置文件,发现在 /etc/sysconfig/network-scripts/ 目录下没有 ifcfg-eth0 这个网卡配置文件。

原因

查了一下,在官方wiki中有这样的描述:

上游的预设组态已改用 NetworkManager,而且介质预设是不会被启用的(针对以太网来说比较难理解)。权宜之计就是在安装过程中,等待安装程序询问你的系统语言、键盘、基本安装或其它存储设置后,执行「检查装置」并显示「请为这台电脑命名……」的画面。这个昼面内有一粒「设置网络」的按钮。点击这个按钮会启动NetworkManager。请选取名为 System eth0 的乙太网络连线并编辑它的设定。假如你选用「自动连线」的选项,网络连线在日後开机时便会被启动。你也可以在安装完成後透过 NetworkManager(「系统;选项;网络连线」或右按通知区域内的网络小图示,选取「编辑连线……」)来作出这个改动。

假如你不采用 NetworkManager,你可以通过编辑网络连接的设置文件(正常为 /etc/sysconfig/network-scripts/ifcfg-eth0)并把 ONBOOT=no改为 ONBOOT=yes来达到相同效果。

也就是说是CentOS6改用NetworkManager方式管理网络了,可以运行如下命令进行确认:

chkconfig--list | grep -i netw

结果:

NetworkManager0:off 1:off 2:on 3:on 4:on 5:on 6:off

network0:off 1:off 2:off 3:off 4:off 5:off 6:off

这里可以看到,NetworkManager是开机启动状态,network是关闭状态。

解决办法就是关闭NetworkManager,用传统的network方式来管理网络,并补充上ifcfg-eth0文件即可

修复步骤

1、关闭NetworkManager服务

$ service NetworkManager stop

2、关闭NetworkManager开机启动

chkconfig NetworkManager off

3、添加 /etc/sysconfig/network-scriipts/ifcfg-eth0 文件

DEVICE=eth0

BOOTPROTO=static

IPADDR=146.175.139.13

NETMASK=255.255.255.0

GATEWAY=146.175.139.255

HWADDR=00:25:90:81:5e:64

NM_COnTROLLED=no

ONBOOT=yes

TYPE=Ethernet

IPV6INIT=no

注:文件内容的值根据实际情况修改

4、开机启动network

chkconfig network on

5、开启network服务

service network start

即可生效。

您好,方法

添加一块网卡,网络模式这里选择的是NAT模式。ip地址也是自动获取的。

新增加的网卡为ens37

已经自动获取到IP地址

linux添加网卡方法

在/etc/sysconfig/network-scripts目录下并没有ifcfg-ens37的配置文件。

获取网卡ens37的的UUID配置信息。

ip addr获取ens37的MAC地址

cp -a ifcfg-ens34 ifcfg-ens37

修改这三个地方

重启网卡

systemctl restart network

再次执行命令

nmcli con show

前面的名称已经变成新添加的网卡名称ens37了。

在使用linux的过程中如果安装了多台虚拟机,并且每台虚拟机都是由上一台虚拟机克隆出来的我们可能会出现联网连不上的问题,在linux的控制台输出ifconfg会出现以下信息:

[root@tiny ~]$ ifconfig

eth2 Link encap:Ethernet HWaddr 00:0C:29:FE:F8:14

inet6 addr: fe80::20c:29ff:fefe:f814/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:68 errors:0 dropped:0 overruns:0 frame:0

TX packets:9 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:7385 (7.2 KiB) TX bytes:2310 (2.2 KiB)

Interrupt:19 Base address:0x2024

loLink encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:8 errors:0 dropped:0 overruns:0 frame:0

TX packets:8 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:480 (480.0 b) TX bytes:480 (480.0 b)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

会报 UP BROADCAST RUNNING MULTICAST错误。这是因为mac地址设置的问题,在这里提供一个解决办法:

1. 切换至root用户

由于相关文件只能由root进行修改,因此我们先应该转换为root用户启动

[admin@tiny ~]$ su root

1

1

2.查看当前MAC地址相关信息

[root@tiny rules.d]# cat /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 0x1022:0x2000 (pcnet32)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:49:e9:9d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x1022:0x2000 (vmxnet)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:13:e9:e2", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

# PCI device 0x1022:0x2000 (vmxnet)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:fe:f8:14", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

我们可以看到其中包含三块网卡信息分别是eth0,eth1,eth2,而我们使用eth2所以我们需要删除掉其他两块网卡信息。

[root@tiny rules.d]# vi /etc/udev/rules.d/70-persistent-net.rules

[root@tiny rules.d]# cat /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 0x1022:0x2000 (vmxnet)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:fe:f8:14", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

1

2

3

4

5

6

7

8

9

10

11

1

2

3

4

5

6

7

8

9

10

11

我们只留下eth2的网卡信息,我们记录下eth2的mac地址:00:0c:29:fe:f8:14。

4. 修改ifcfg-eth2中的信息

在这里我发现了一件非常尴尬的事情,在/etc/sysconfig/network-scripts/文件夹下没有ifcfg-eth2

[root@tiny network-scripts]# ls /etc/sysconfig/network-scripts/

ifcfg-eth0~ ifdown-ipppifdown-tunnel ifup-isdnifup-tunnel

ifcfg-eth1 ifdown-ipv6ifup ifup-plipifup-wireless

ifcfg-eth1~ ifdown-isdnifup-aliases ifup-plusb init.ipv6-global

ifcfg-lo ifdown-postifup-bnep ifup-postnet.hotplug

ifdown ifdown-ppp ifup-eth ifup-ppp network-functions

ifdown-bnep ifdown-routes ifup-ippp ifup-routes network-functions-ipv6

ifdown-eth ifdown-sit ifup-ipv6 ifup-sit

1

2

3

4

5

6

7

8

1

2

3

4

5

6

7

8

但是,我们可以拷贝一个

[root@tiny network-scripts]# mv /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth2

1

1

然后我们打开ifcfg-eth2

[root@tiny network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-eth2

DEVICE=eth1

TYPE=Ethernet

UUID=eeb8ed32-3b4d-45c4-b2fe-9c7b5fe4e2ac

ONBOOT=yes

NM_CONTROLLED=yes

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME="System eth1"

HWADDR=00:0C:29:49:E9:9D

LAST_CONNECT=1488606798

BOOTPROTO=static

IPADDR=192.168.132.114

NETMASK=255.255.255.0

GATEWAY=192.168.132.1

DNS1=210.31.249.20

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

mac地址和在70-persistent-net.rules中的mac并不一样,我们将70-persistent-net.rules中的mac地址复制过来,并且将DEVICE和NAME也做相应的修改

[root@tiny network-scripts]# vi /etc/sysconfig/network-scripts/ifcfg-eth2

[root@tiny network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-eth2

DEVICE=eth2

TYPE=Ethernet

UUID=eeb8ed32-3b4d-45c4-b2fe-9c7b5fe4e2ac

ONBOOT=yes

NM_CONTROLLED=yes

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME="System eth2"

HWADDR=00:0c:29:fe:f8:14

LAST_CONNECT=1488606798

BOOTPROTO=static

IPADDR=192.168.132.115

NETMASK=255.255.255.0

GATEWAY=192.168.132.1

DNS1=210.31.249.20

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

5. 重启服务,并测试

重启network,查看网卡信息,并测试联网情况 。执行下面的命令:

[root@tiny network-scripts]# service network restart

正在关闭接口 eth2: 设备状态:3 (断开连接)

[确定]

关闭环回接口: [确定]

d出环回接口: [确定]

d出界面 eth2: 活跃连接状态:激活的

活跃连接路径:/org/freedesktop/NetworkManager/ActiveConnection/23

[确定]

[root@tiny network-scripts]# ifconfig

eth2 Link encap:Ethernet HWaddr 00:0C:29:FE:F8:14

inet addr:192.168.132.115 Bcast:192.168.132.255 Mask:255.255.255.0

inet6 addr: fe80::20c:29ff:fefe:f814/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:1595 errors:0 dropped:0 overruns:0 frame:0

TX packets:117 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:159465 (155.7 KiB) TX bytes:33595 (32.8 KiB)

Interrupt:19 Base address:0x2024

loLink encap:Local Loopback

inet addr:127.0.0.1 Mask:255.0.0.0

inet6 addr: ::1/128 Scope:Host

UP LOOPBACK RUNNING MTU:16436 Metric:1

RX packets:8 errors:0 dropped:0 overruns:0 frame:0

TX packets:8 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:480 (480.0 b) TX bytes:480 (480.0 b)

[root@tiny network-scripts]# ping 119.75.217.109

PING 119.75.217.109 (119.75.217.109) 56(84) bytes of data.

64 bytes from 119.75.217.109: icmp_seq=1 ttl=64 time=0.611 ms

64 bytes from 119.75.217.109: icmp_seq=2 ttl=64 time=0.261 ms

^C

--- 119.75.217.109 ping statistics ---

2 packets transmitted, 2 received, 0% packet loss, time 1424ms

rtt min/avg/max/mdev = 0.261/0.436/0.611/0.175 ms

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

修改成功


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7315436.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-04
下一篇2023-04-04

发表评论

登录后才能评论

评论列表(0条)

    保存