Centos7 configure IP address

There are two main ways to obtain an IP address for centos7, 1: dynamically obtain ip; 2: set a static IP address

Before configuring the network, we need to know what the name of the centos network card is. Centos7 no longer uses the ifconfig command, and can be viewed through the command IP addr. As shown in the figure, the network card is named ens32, and there is no IP address.

1、 Obtain ip dynamically (provided that your router has enabled DHCP)

Modify the network card configuration file vi /etc/sysconfig/network-scripts/ifcfg-ens32 (the last one is the network card name)

To obtain an IP address dynamically, you need to modify two places

(1)bootproto=dhcp

(2)onboot=yes

After modification, restart the network service to systemctl restart network

[ root@mini ~]# systemctl restart network
[ root@mini ~]# 

In this way, the dynamic configuration IP address is set. At this time, check the ip addr and you can see that the IP address has been obtained and you can go online (ping Baidu)

2、 Configure static IP address

Setting a static IP address is similar to dynamic iIP, but also to modify the network card configuration file vi /etc/sysconfig/network-scripts/ifcfg-ens32 (the last one is the network card name)

(1)bootproto=static

(2)onboot=yes

(3) Add a few lines at the end, IP address, subnet mask, gateway, dns server

IPADDR=192.168.1.160
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=119.29.29.29
DNS2=8.8.8.8

(4) Restart the network service

[ root@mini ~]# systemctl restart network
[ root@mini ~]# 

DNS server can only be equipped with one, I use two free dns servers, check the IP address, test the network

[ root@mini ~]# 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: ens32:<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
 link/ether 00:0c:29:d2:42:55 brd ff:ff:ff:ff:ff:ff
 inet 192.168.1.160/24 brd 192.168.1.255 scope global noprefixroute ens32
  valid_lft forever preferred_lft forever
 inet6 fe80::f86e:939e:ff9b:9aec/64 scope link noprefixroute
  valid_lft forever preferred_lft forever

[ root@mini ~]# ping www.baidu.com
PING www.a.shifen.com(163.177.151.109)56(84) bytes of data.64 bytes from163.177.151.109(163.177.151.109): icmp_seq=1 ttl=55 time=27.5 ms
64 bytes from163.177.151.109(163.177.151.109): icmp_seq=2 ttl=55 time=35.2 ms
^ C
- - - www.a.shifen.com ping statistics ---2 packets transmitted,2 received,0% packet loss, time 1008ms
rtt min/avg/max/mdev =27.570/31.425/35.281/3.859 ms

Recommended Posts

Centos7 configure IP address
Centos: add an IP address
Configure static IP under CentOS 7
Centos configure multiple virtual IP
Centos configure multiple virtual IP
Centos7 configure JDK
Centos7 configuration host name and IP address
IP address problem after restarting CentOS 7 system
Configure Ocserv on CentOS 6
ubuntu 14.04 configure 3-wire 3IP
Ubuntu18.04, Centos7 static IP
Configure lamp under centos6.8
Centos7 configure nodejs environment
Configure CentOS7 GPU environment
Complete steps to configure IP address in Ubuntu 18.04 LTS
Set static IP under Centos
CentOS 7 configure Java language development environment
Install and configure keepalived under CentOS 5.9
Configure rsyslog log client on CentOS
CentOS 8 (2)
CentOS 6/7 configure sendEmail to send mail
CentOS 7 configure php language development environment
CentOS 8 - install and configure NFS service
CentOS 8 (1)
Configure python3 environment on centos7 and
CentOS Minimal install and configure TIPS
Install and configure FreeIPA in Centos7
CentOS 7 configure Python language development environment
Configure Nginx reverse proxy based on CentOS 7
Configure Nginx load balancing based on CentOS 7
Configure Nginx forward proxy based on CentOS 7
Deploy Docker and configure Nginx in CentOS
Set static IP for CentOS in VMware
Install CentOS7 virtual machine, configure docker suite