Home > Operation and Maintenance > CentOS > Detailed explanation of two methods for configuring IP address in centos7

Detailed explanation of two methods for configuring IP address in centos7

藏色散人
Release: 2020-07-22 15:35:55
forward
6405 people have browsed it

The following column centos introductory tutorial will introduce to you two methods of configuring IP addresses in centos7. I hope it will be helpful to friends in need!

Detailed explanation of two methods for configuring IP address in centos7

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

Before configuring the network, we first need to know the name of the centos network card. Centos7 no longer uses the ifconfig command. You can view it through the command IP addr. As shown in the figure, the network card name is ens32 and has no IP address.

1. Dynamically obtain ip (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)

You need to modify the dynamically obtained IP address Just two places

(1)bootproto=dhcp

(2)onboot=yes

After modification, restart the network service. Systemctl restart network

[root@mini ~]# systemctl restart network
[root@mini ~]#
Copy after login
Copy after login

In this way, the dynamically configured IP address is set. Check again at this time. Click ip addr and you will see that you have obtained the IP address and can access the Internet (ping Baidu)

2. Configure a static IP address

Setting a static IP address is similar to a dynamic iIP. You also need 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
Copy after login

(4) Restart the network service

[root@mini ~]# systemctl restart network
[root@mini ~]#
Copy after login
Copy after login

You can configure only one DNS server. I use two free dns servers. Check the IP address and test the network connection

[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 from 163.177.151.109 (163.177.151.109): icmp_seq=1 ttl=55 time=27.5 ms
64 bytes from 163.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
Copy after login

For more centos related technical articles, please visit the centos system tutorial column!

The above is the detailed content of Detailed explanation of two methods for configuring IP address in centos7. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template