一、通过命令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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:a5:3e:e7 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.121/24 brd 192.168.0.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:fea5:3ee7/64 scope link
valid_lft forever preferred_lft forever
3: ens36: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether 00:0c:29:a5:3e:f1 brd ff:ff:ff:ff:ff:ff
第一个网卡名为lo一般不会修改,而选择ens开头的,本次以ens36为例,该名称对应的网卡文件为/etc/sysconfig/network-scripts/ifcfg-ens36
二、添加配置静态IP、网关、DNS、子网掩码
vi /etc/sysconfig/network-scripts/ifcfg-ens36
TYPE=Ethernet
BOOTPROTO=none
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.0.122
GATEWAY=192.168.0.1
DNS1=223.5.5.5
NETMASK=255.255.255.0
三、重启服务
systemctl restart network