1.查看当前系统 ip
CentOS7为最小化安装,所以查询命令为 ip addr
enp0s3 中地址 192.168.1.110
[root@localhost network-scripts]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:4c:4c:61 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.110/24 brd 192.168.1.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::377c:6c14:8215:759/64 scope link noprefixroute
valid_lft forever preferred_lft forever
2.查找网卡配置文件
*
一般为 ip addr 中查询的文件名字:enp0s3
vim /etc/sysconfig/network-scripts/ifcfg-*
3.编辑
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static # 原为 dhcp ,改为 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=enp0s3
UUID=864e0ebe-00cf-4707-8e5e-770cb52380fb
DEVICE=enp0s3
ONBOOT=yes # 开机启用配置
ZONE=public
IPADDR=192.168.1.110 # 静态IP(自由设置)
GATEWAY=192.168.1.1 # 默认网关(一般为.1 或 .2)
NETMASK=255.255.255.0 # 子网掩码
DNS1=114.114.114.114 # DNS,公用的 114.114.114.114,也有8.8.8.8
PREFIX=24
4.重启网络服务
/etc/init.d/network restart
# 或
service network restart
5.检查网络
ip addr 先检查网络是否启用
ping www.baidu.com 查看是否能通