It seems that command setting is recommended in CentOS7. Set using the nmcli command. It is assumed that the IP address of the local network and router is "192.168.1.1".
First, check the device with "nmcli d".
DEVICE TYPE STATE CONNECTION
enp0s3 ethernet disconnected--
lo loopback no management--
Check enp0s3. Since enp0s3 is a device name, it depends on the device you want to set.
The file to actually set. This is the default. /etc/sysconfig/network-scripts/ifcfg-enp0s3
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=enp0s3
UUID=d980175f-0b3e-4fs2-8fe5-4532bbb31b315f
DEVICE=enp0s3
ONBOOT=no
Type the command above to set it.
nmcli c m enp0s3 connection.autoconnect yes
Change ONBOOT = no → yes. If no, the network cannot be used.
nmcli c modify enp0s3 ipv4.address 192.168.1.11/24
IPADDR=192.168.1.11 PREFIX=24 The IP address and subnet mask are set.
nmcli c modify enp0s3 ipv4.gateway 192.168.1.1
GATEWAY=192.168.1.1
nmcli c modify enp0s3 ipv4.dns 192.168.1.1
DNS=192.168.1.1
nmcli c modify enp0s3 ipv4.method manual
BOOTPROTO = dhcp → changed to none
nmcli c down enp0s3;nmcli c up enp0s3
The settings will not be reflected unless you restart. After restarting, check the settings with the following command.
nmcli d show enp0s3
Add to/etc/hosts.
192.168.1.1 router #router
192.168.1.11 Host name#Own host name
nameserver 192.168.1.1
By setting DNS = 192.168.1.1 in step ④, the IP address automatically enters the nameserver.
ping (-c 3) 192.168.1.11 or own host name
ping (-c 3) 192.168.1.1 or router
OK if there is no packet loss
ping (-c 3) google.com
Check if ping can be passed to the outside. Access google to try.