修改配置文件

1
vim /etc/sysconfig/network-scripts/ifcfg-eth0
  • 将“BOOTPROTO=dhcp”改为“BOOTPROTO=static”
  • 将“ONBOOT=no”改为“ONBOOT=yes”

未修改前

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="eth0"
UUID="a4c4162e-15d9-4231-87d4-3ae1c9e53570"
DEVICE="eth0"
ONBOOT="yes"

修改后

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="eth0"
UUID="422dce01-9b25-4f06-8f0d-a8d2a6d07a89"
DEVICE="eth0"
ONBOOT="yes"
IPADDR="192.168.0.11"
GATEWAY="192.168.0.1"
NETMASK="255.255.255.0"
DNS1="218.2.2.2"
DNS2="218.4.4.4"

重启网络

1
/etc/init.d/network restart