In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to bind multiple IP addresses to a network card in the CentOS system. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
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:
The code is as follows:
Ip addr
Sample output:
The code is as follows:
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: 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.
The code is as follows:
Cat / etc/sysconfig/network-scripts/ifcfg-enp0s3
Sample output:
The code is as follows:
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= "08VOG 00VOUR 27RU 80VOUR 63VOR 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 a file
The code is as follows:
/ etc/sysconfig/network-scripts/ifcfg-enp0s3:
Vi / etc/sysconfig/network-scripts/ifcfg-enp0s3
Add an additional IP address as below.
The code is as follows:
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.
Finally, save and exit the file. Restart the network service for the changes to take effect.
The code is as follows:
Systemctl restart network
Now, let's check to see if an ip address has been added.
The code is as follows:
Ip addr
Sample output:
The code is as follows:
: 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: 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:
The code is as follows:
Ping-c 4 192.168.1.151
Sample output:
The code is as follows:
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 ms
64 bytes from 192.168.1.151: icmp_seq=2 ttl=64 time=0.075 ms
64 bytes from 192.168.1.151: icmp_seq=3 ttl=64 time=0.077 ms
64 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 2999ms
Rtt min/avg/max/mdev = 0.048 ms 0.069 ms 0.077 cusp 0.013
Ping-c 4 192.168.1.152
Sample output:
The code is as follows:
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 ms
64 bytes from 192.168.1.152: icmp_seq=2 ttl=64 time=0.075 ms
64 bytes from 192.168.1.152: icmp_seq=3 ttl=64 time=0.073 ms
64 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 2999ms
Rtt 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.
The code is as follows:
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=16
GATEWAY0= "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:
The code is as follows:
Ping-c 4 10.0.0.1
Sample output:
The code is as follows:
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 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=0.073 ms
64 bytes from 10.0.0.1: icmp_seq=3 ttl=64 time=0.074 ms
64 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 3000ms
Rtt min/avg/max/mdev = 0.073 ms 0.079 ms
After reading the above, do you have any further understanding of how to bind multiple IP addresses to a network card in the CentOS system? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.