In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to assign multiple IP addresses to a network card on CentOS 7? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Sometimes, you may want to give multiple addresses to a network card. What are you supposed to do? Buy another network card to assign addresses? You don't have to do this in a small network. We can now assign multiple IP addresses to a network card in CentOS/RHEL 7. Want to know what to do? Okay, follow me. It's not hard.
First, let's find the IP address of the network card. In my CentOS 7 server, I only use one network card.
Run the following command with root privileges:
Ip addr
Sample output:
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 forever2: enp0s3: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:80:63:19 brd ff:ff:ff: Ff:ff:ff inet 192.168.1.150/24 brd 192.168.1.255 scope global enp0s3 valid_lft forever preferred_lft forever
As seen above, my network card name is enp0s3,ip and the address is 192.168.1.150.
As you know, the configuration file for the network card is stored in the / etc/sysconfig/network-scripts/ directory. The details of each network card will be stored under a different name, such as ifcfg-enp0s3.
Let's take a look at the details of ifcfg-enp0s3.
Cat / etc/sysconfig/network-scripts/ifcfg-enp0s3
Sample output:
TYPE= "Ethernet" BOOTPROTO= "none" DEFROUTE= "yes" IPV4_FAILURE_FATAL= "no" IPV6INIT= "yes" IPV6_AUTOCONF= "yes" IPV6_DEFROUTE= "yes" IPV6_FAILURE_FATAL= "no" NAME= "enp0s3" UUID= "e9f9caef-cb9e-4a19-aace-767c6ee6f849" ONBOOT= "yes" HWADDR= "08 Velcro 00 Velcro 27 Velcro 80 Pluto 63 Pluto 19" IPADDR0= "192.168.1.150" PREFIX0= "24" GATEWAY0= "192.168.1.1" DNS1= "192.168.1.1" IPV6_PEERDNS= "yes" IPV6_PEERROUTES= "yes"
OK, now we will assign multiple addresses in the same subnet.
Edit the file / etc/sysconfig/network-scripts/ifcfg-enp0s3:
Vi / etc/sysconfig/network-scripts/ifcfg-enp0s3
Add an additional IP address as below.
TYPE= "Ethernet" BOOTPROTO= "none" DEFROUTE= "yes" IPV4_FAILURE_FATAL= "no" IPV6INIT= "yes" IPV6_AUTOCONF= "yes" IPV6_DEFROUTE= "yes" IPV6_FAILURE_FATAL= "no" NAME= "enp0s3" UUID= "933cdc9b-b383-4ddd-b219-5a72c69c9cf0" ONBOOT= "yes" HWADDR= "08:00:27:3F:AB:68" IPADDR0= "192.168.1.150" IPADDR1= "192.168.1.151" IPADDR2= "192.168.1.152" PREFIX0= "24" GATEWAY0= "192.168.1. 1 "DNS1=" 192.168.1.1 "IPV6_PEERDNS=" yes "IPV6_PEERROUTES=" yes "
As you can see, I have added two IP addresses: IPADDR1= "192.168.1.151" & IPADDR2= "192.168.1.152"
Similarly, you can add more ip addresses.
*, save and exit the file. Restart the network service for the changes to take effect.
Systemctl restart network
Now, let's check to see if an IP address has been added.
Ip addr
Sample output:
: 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 forever2: enp0s3: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:3f:ab:68 brd ff:ff:ff:ff : ff:ff inet 192.168.1.150/24 brd 192.168.1.255 scope global enp0s3 valid_lft forever preferred_lft forever inet 192.168.1.151/24 brd 192.168.1.255 scope global secondary enp0s3 valid_lft forever preferred_lft forever inet 192.168.1.152/24 brd 192.168.1.255 scope global secondary enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe3f:ab68/64 scope link valid_lft forever preferred_lft forever
As you can see, a single network card already has three IP addresses.
Let's ping the new IP address:
Ping-c 4 192.168.1.151
Sample output:
PING 192.168.1.151 (192.168.1.151) 56 (84) bytes of data.64 bytes from 192.168.1.151: icmp_seq=1 ttl=64 time=0.048 ms64 bytes from 192.168.1.151: icmp_seq=2 ttl=64 time=0.075 ms64 bytes from 192.168.1.151: icmp_seq=3 ttl=64 time=0.077 ms64 bytes from 192.168.1.151: icmp_seq=4 ttl=64 time=0.077 ms-- 192.168.1.151 ping statistics-- 4 packets transmitted, 4 received, 0 packet loss Time 2999msrtt min/avg/max/mdev = 0.048 msping-c 4 192.168.1.152
Sample output:
PING 192.168.1.152 (192.168.1.152) 56 (84) bytes of data.64 bytes from 192.168.1.152: icmp_seq=1 ttl=64 time=0.034 ms64 bytes from 192.168.1.152: icmp_seq=2 ttl=64 time=0.075 ms64 bytes from 192.168.1.152: icmp_seq=3 ttl=64 time=0.073 ms64 bytes from 192.168.1.152: icmp_seq=4 ttl=64 time=0.075 ms-- 192.168.1.152 ping statistics-- 4 packets transmitted, 4 received, 0 packet loss Time 2999msrtt min/avg/max/mdev = 0.034 ms 0.064 ms 0.075 max 0.018
If you want to use a different subnet, you need to change the PREFIX0=24 to a different subnet, such as PREFIX1=16.
For example, I want to add a class An address (* such as 10.0.0.1) to my network card.
TYPE= "Ethernet" BOOTPROTO= "none" DEFROUTE= "yes" IPV4_FAILURE_FATAL= "no" IPV6INIT= "yes" IPV6_AUTOCONF= "yes" IPV6_DEFROUTE= "yes" IPV6_FAILURE_FATAL= "no" NAME= "enp0s3" UUID= "933cdc9b-b383-4ddd-b219-5a72c69c9cf0" ONBOOT= "yes" HWADDR= "08:00:27:3F:AB:68" IPADDR0= "192.168.1.150" IPADDR1= "192.168.1.151" IPADDR2= "192.168.1.152" IPADDR3= "10.0.0.1" PREFIX0= 24 "PREFIX1=16GATEWAY0=" 192.168.1.1 "DNS1=" 192.168.1.1 "IPV6_PEERDNS=" yes "IPV6_PEERROUTES=" yes "
You can see that I have added a Class An address (10.0.0.1) with a prefix of 16.
Save and exit the file. Restart the network service, and then the new address for ping:
Ping-c 4 10.0.0.1
Sample output:
PING 10.0.0.1 (10.0.0.1) 56 (84) bytes of data.64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.097 ms64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=0.073 ms64 bytes from 10.0.0.1: icmp_seq=3 ttl=64 time=0.074 ms64 bytes from 10.0.0.1: icmp_seq=4 ttl=64 time=0.075 ms-- 10.0.0.1 ping statistics-4 packets transmitted, 4 received, 0% packet loss Time 3000msrtt min/avg/max/mdev = 0.073 ms 0.079 ms
Similarly, you can add different gateways.
okay.
After reading the above, have you learned how to assign multiple IP addresses to a network card on CentOS 7? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.