Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add ip addresses and gateways to Centos7

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report