如何在 CentOS 7 中启动我的网络?

如何在 CentOS 7 中启动我的网络?

我已经编辑了/etc/sysconfig/network-scripts/ifcfg-enpos2

BOOTPROTO="static"
IPADDR=192.168.1.105
NETMASK=255.255.255.0
NM_CONTROLLED=no

重启后我无法上网。如何重新启动我的网络?

systemctl restart network.service

网络未连接。我们来看看状态。

network.service - LSB: Bring up/down networking
       Loaded: loaded (/etc/rc.d/init.d/network)
       Active: active (exited) since Wed 2015-08-26 17:21:53 CST; 21s ago
      Process: 3494 ExecStop=/etc/rc.d/init.d/network stop (code=exited, status=0/SUCCESS)
      Process: 3674 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS)


Aug 26 17:21:50 localhost.localdomain network[3674]: Bringing up loopback interface:  Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Aug 26 17:21:50 localhost.localdomain network[3674]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Aug 26 17:21:50 localhost.localdomain network[3674]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Aug 26 17:21:50 localhost.localdomain network[3674]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo'
Aug 26 17:21:50 localhost.localdomain network[3674]: [  OK  ]
Aug 26 17:21:53 localhost.localdomain network[3674]: Bringing up interface enp2s0:  [  OK  ]
Aug 26 17:21:53 localhost.localdomain systemd[1]: Started LSB: Bring up/down networking.

这是我的ifcfg-lo文件:

cat /etc/sysconfig/network-scripts/ifcfg-lo
DEVICE=lo
IPADDR=127.0.0.1
NETMASK=255.0.0.0
NETWORK=127.0.0.0
# If you're having problems with gated making 127.0.0.0/8 a martian,
# you can change this to something else (255.255.255.255, for example)
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback

为什么我无法加载它?如何将我的IP地址设置为静态并使其正常连接到互联网?

答案1

CentOS 7 切换到systemd- 用于systemctl restart network.service重新启动网络。

对于像您这样的静态网络设置,您可能需要NetworkManager-config-server使用以下命令安装 RPM 软件包yum

答案2

这也花了我很多时间,但至少尝试一下:

# service NetworkManager stop
Redirecting to /bin/systemctl stop NetworkManager.service
# chkconfig NetworkManager off

删除了 lo 错误,因为 Manger 阻止了它。

只是我在新安装的 centos 7 上仍然无法上网

答案3

看起来您禁用了 NetworkManager,现在您的 ifcfg-enp0s2 文件中没有足够的信息。此外:

BOOTPROTO="static"
IPADDR=192.168.1.105
NETMASK=255.255.255.0
NM_CONTROLLED=no

您还需要:

# Specify the default gateway
GATEWAY=<ip of your router>
# Bring the interface up on boot
ONBOOT=yes
# Specify your dns server
DNS1=<ip of your router>

相关内容