View IP information
After CentOS is installed, view the ip information through the ip addr command
[root@localhost yum.repos.d]# 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:39:fe:2b brd ff:ff:ff:ff:ff:ff
View network card configuration
Enter the network card profile directory
cd /etc/sysconfig/network-scripts/
View the catalog file as follows
ifcfg-enp0s3 ifdown ifdown-ippp ...
It can be seen that the network card configuration file is ifcfg-enp0s3. Some computers may be eth0 or other
Configure dynamic IP
Edit network card profile
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
The contents of the document are as follows
YPE=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=e7666215-13db-4cc2-bbea-6fd152c7b4a8 DEVICE=enp0s3 ONBOOT=no
Change ONBOOT=no to ONBOOT=yes
... ONBOOT=yes
service network restart
service network restart //perhaps /etc/init.d/network restart
Restart of network service succeeded
Restarting network (via systemctl): [ OK ]
View ip information
At this time, you can see that ip is 192.168.2.107
... inet 192.168.2.107/24 brd 192.168.2.255 scope global noprefixroute dynamic enp0s3 ...
Configure static ip
The above configuration is dynamic ip. When the system is restarted, the ip may change, so you need to configure the ip as static.
Modify profile
Change BOOTPROTO=dhcp to BOOTPROTO=static
... BOOTPROTO=static ...
Add static ip information
IPADDR=192.168.2.110 // Static ip GETWAY=192.168.2.1 // default gateway NETMASK=255.255.255.0 // Subnet mask DNS1=192.168.2.1 // DNS address
service network restart
service network restart