实验环境为Centos7.5

1.打开配置文件

[root@localhost ~]# cd ..
[root@localhost /]# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[root@localhost /]# vi etc/sysconfig/network-scripts/ifcfg-ens33

2.编辑配置文件

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=statics #dhcp为动态获取IP地址,statics为静态获取IP地址。
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=ens33
UUID=4b20da7e-0986-46f4-8e98-ab3b16fc4f0e
DEVICE=ens33
ONBOOT=yes #是否开机启用该网卡no为否,yes为是。

#在后方添加一下
IPADDR=192.168.10.10 #IP地址设置

NETMASK=255.255.255.0 #子网掩码设置

GETWAY=192.168.10.1 #网关设置

3.保存退出:ESC Shift+: 输入:wq #保存并退出

4.重启网卡

[root@localhost /]# systemctl restart network
测试
[root@localhost /]# ping 192.168.10.10 #ping自己或者ping局域网其他主机测试

PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.061 ms
64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.072 ms
64 bytes from 192.168.10.10: icmp_seq=3 ttl=64 time=0.070 ms
64 bytes from 192.168.10.10: icmp_seq=4 ttl=64 time=0.062 ms
^C #Ctrl+C中止发包
--- 192.168.10.10 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 0.061/0.066/0.072/0.007 ms