Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to add ip addresses and gateways to Centos7

Shulou Source: shulou.com Published: 2022-06-01 13:07:06 10月20日 Update

This article introduces the knowledge of "how to add ip addresses and gateways to Centos7". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. View os version

[root@oracle network-scripts] # cat / etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

two。 Check which network port is linked. In many cases, there is more than one network port on the server. In this example, there are four. You need to determine which network port is plugged into the current network cable. In this case, if em1 is in the linked state, then configure the em1 when configuring ip.

[root@oracle network-scripts] # nmcli dev status

DEVICE TYPE STATE CONNECTION

Em2 ethernet unavailable--

P1p1 ethernet unavailable--

P1p2 ethernet unavailable--

Em1 ethernet connected--

Lo loopback unmanaged--

3. Modify the file, red is added and modified, BOOTPROTO=dhcp, changed from dhcp to static

NM_CONTROLLED=no indicates that the port will be set through the configuration file

ONBOOT=yes means that the network card starts automatically when it starts.

Vi / etc/sysconfig/network-scripts/ifcfg-em1

TYPE=Ethernet

BOOTPROTO=static

IPADDR=172.24.80.236

NETMASK=255.255.255.0

GATEWAY=172.24.80.1

NM_CONTROLLED=no

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=em1

UUID=67ac8318-e715-4081-9ef7-781140c62cb1

DEVICE=em1

ONBOOT=yes

4. Restart the service

Systemctl restart network.service

5. Verify that the interface is configured correctly

[root@oracle network-scripts] # ip add

1: lo: mtu 65536 qdisc noqueue state UNKNOWN

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: em1: mtu 1500 qdisc mq state UP qlen 1000

Link/ether d0:94:66:3e:ae:d0 brd ff:ff:ff:ff:ff:ff

Inet 172.24.80.236/24 brd 172.24.80.255 scope global em1

Valid_lft forever preferred_lft forever

Inet6 fe80::d294:66ff:fe3e:aed0/64 scope link

Valid_lft forever preferred_lft forever

3: em2: mtu 1500 qdisc mq state DOWN qlen 1000

Link/ether d0:94:66:3e:ae:d1 brd ff:ff:ff:ff:ff:ff

4: p1p1: mtu 1500 qdisc mq state DOWN qlen 1000

Link/ether d0:94:66:3e:bf:03 brd ff:ff:ff:ff:ff:ff

5: p1p2: mtu 1500 qdisc mq state DOWN qlen 1000

Link/ether d0:94:66:3e:bf:04 brd ff:ff:ff:ff:ff:ff

6. View the network port status

[root@oracle network-scripts] # nmcli dev status

DEVICE TYPE STATE CONNECTION

Em2 ethernet unavailable--

P1p1 ethernet unavailable--

P1p2 ethernet unavailable--

Em1 ethernet unmanaged--

Lo loopback unmanaged--

This is the end of the introduction to "how to add ip addresses and gateways to Centos7". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Network port configuration address gateway content file time more status knowledge link service practical successful learning next dilemma actual situation meaning interface Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Tech Info MariaDB OPPO Reno Linux