Centos 7 enables the network card to automatically retrieve IP

  • 2020-05-17 07:36:20
  • OfStack

The default installation of Centos7 does not have the configuration card information turned on, so the external network cannot be accessed.

The following configuration opens the network and automatically gets the Ip address

1. Check your network card information

Perform Ifconfig


eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

    inet6 fe80::20c:29ff:fee8:8637 prefixlen 64 scopeid 0x20<link>

    ether 00:0c:29:e8:86:37 txqueuelen 1000 (Ethernet)

    RX packets 1121 bytes 98968 (96.6 KiB)

    RX errors 0 dropped 0 overruns 0 frame 0

    TX packets 179 bytes 25233 (24.6 KiB)

    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

    inet 127.0.0.1 netmask 255.0.0.0

    inet6 ::1 prefixlen 128 scopeid 0x10<host>

    loop txqueuelen 0 (Local Loopback)

    RX packets 900 bytes 78372 (76.5 KiB)

    RX errors 0 dropped 0 overruns 0 frame 0

    TX packets 900 bytes 78372 (76.5 KiB)

    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 

1. eno16777736 represents the name of the network card, ether 00:0 c: 29: e8:86-37 representative Mac address of network card

2. Configure the network card to start the network connection


cd /etc/system/network-scripts/

vi ifcfg-eno16777736 

HWADDR=00:0C:29:E8:86:37
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=79d6c916-aab8-45e4-a163-37ae73393d26
ONBOOT=no

Change ONBOOT= no to ONBOOT=yes

Restart the network


service network restart

4. Then execute ifconfig


eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
    inet 192.168.159.128 netmask 255.255.255.0 broadcast 192.168.159.255
    inet6 fe80::20c:29ff:fee8:8637 prefixlen 64 scopeid 0x20<link>
    ether 00:0c:29:e8:86:37 txqueuelen 1000 (Ethernet)
    RX packets 1699 bytes 140091 (136.8 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 333 bytes 42669 (41.6 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
    inet 127.0.0.1 netmask 255.0.0.0
    inet6 ::1 prefixlen 128 scopeid 0x10<host>
    loop txqueuelen 0 (Local Loopback)
    RX packets 900 bytes 78372 (76.5 KiB)
    RX errors 0 dropped 0 overruns 0 frame 0
    TX packets 900 bytes 78372 (76.5 KiB)
    TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

inet 192.168.159.128 represents the IP address


Related articles: