In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to add an auxiliary IP address in the Ubuntu system, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Linux administrators should be aware of this because this is a routine task. Many people want to know why we need to add multiple IP addresses to the server and why we need to add it to a single network card. Am I right?
You may have a similar problem: how to assign multiple IP addresses to a single Nic in Linux? In this article, you can get the answer.
When we set up a new server, ideally it will have an IP address, the server's primary IP address, which corresponds to the server hostname.
We should not host any applications on the server's primary IP address, which is not desirable. If we want to host any application on the server, we should add a secondary IP for this.
This is an industry practice that allows users to install SSL certificates. Most systems come with a single network card, which is enough to add additional IP addresses.
We can add an IP address on the same interface or create a subinterface on the same device and then add IP to it. By default, until Ubuntu 14.04 LTS, the interface is named ethX (eth0), but since Ubuntu 15.10 the network interface name has changed from ethX to enXXXXX (ens33 for servers and enp0s3 for desktops).
In this article, we will show you how to do this on Ubuntu and derive it to other distributions (to correction: this sentence is self-added).
Note: do not add the IP address after the DNS details. If so, DNS will not work properly.
How to add a temporary secondary IP address to Ubuntu 14.04 LTS
Before adding an IP address to the system, run any of the following commands to verify the server primary IP address:
# ifconfig or # ip addr # ip addr eth0 Link encap:Ethernet HWaddr 08:00:27:98:b7:36 inet addr:192.168.56.150 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe98:b736/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4 errors:0 dropped:0 overruns:0 frame:0 TX packets:105 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:902 (902.0 B) TX bytes:16423 (16.4 KB) eth2 Link encap:Ethernet HWaddr 08:00:27:6a:cf:d3 inet addr:10.0.3.15 Bcast:10.0.3.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe6a: Cfd3/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:80 errors:0 dropped:0 overruns:0 frame:0 TX packets:146 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:8698 (8.6 KB) TX bytes:17047 (17.0 KB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask : 255.0.0.0 inet6 addr: 1Plus 128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:25 errors:0 dropped:0 overruns:0 frame:0 TX packets:25 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:1730 (1.7 KB) TX bytes:1730 (1.7 KB)
As I can see, the primary IP address of the server is 192.168.56.150, and I use the next IP 192.168.56.151 as a secondary IP, using the following methods:
# ip addr add 192.168.56.151/24 broadcast 192.168.56.255 dev eth0 label eth0:1
Enter the following command to check the newly added IP address. If you restart the server, the newly added IP address will disappear because our IP is temporarily added.
# ip addr1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1 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: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:98:b7:36 Brd ff:ff:ff:ff:ff:ff inet 192.168.56.150/24 brd 192.168.56.255 scope global eth0 valid_lft forever preferred_lft forever inet 192.168.56.151/24 brd 192.168.56.255 scope global secondary eth0:1 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe98:b736/64 scope link valid_lft forever preferred_lft forever3: eth2: mtu 1500 qdisc pfifo_fast state UP Group default qlen 1000 link/ether 08:00:27:6a:cf:d3 brd ff:ff:ff:ff:ff:ff inet 10.0.3.15 brd 24 brd 10.0.3.255 scope global eth2 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe6a:cfd3/64 scope link valid_lft forever preferred_lft forever how to add * Secondary IP address to Ubuntu 14.04 LTS
To add a * * secondary IP address on a Ubuntu system, simply edit the / etc/network/interfaces file and add the required IP details.
# vi / etc/network/interfaces# vi / etc/network/interfaces# The loopback network interfaceauto loiface lo inet loopback # The primary network interfaceauto eth0iface eth0 inet static address 192.168.56.150 netmask 255.255.255.0 network 192.168.56.0 broadcast 192.168.56.255 gateway 192.168.56.1 auto eth0:1iface eth0:1 inet static address 192.168.56.151 netmask 255.255.255.0
Save and close the file, and then restart the network interface service.
# service networking restart or # ifdown eth0:1 & & ifup eth0:1
Verify the newly added IP address:
# ifconfigeth0 Link encap:Ethernet HWaddr 08:00:27:98:b7:36 inet addr:192.168.56.150 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe98:b736/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5 errors:0 dropped:0 overruns:0 frame:0 TX packets:84 errors:0 Dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:962 (962.0 B) TX bytes:11905 (11.9 KB) eth0:1 Link encap:Ethernet HWaddr 08:00:27:98:b7:36 inet addr:192.168.56.151 Bcast:192.168.56.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 eth2 Link encap:Ethernet HWaddr 08 : 00:27:6a:cf:d3 inet addr:10.0.3.15 Bcast:10.0.3.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe6a:cfd3/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4924 errors:0 dropped:0 overruns:0 frame:0 TX packets:3185 errors:0 dropped:0 overruns:0 carrier:0 Collisions:0 txqueuelen:1000 RX bytes:4037636 (4. 0 MB) TX bytes:422516 (422.5 KB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: 1Take 128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:0 (0.0B) TX bytes:0 (0.0B) how to temporarily add a secondary IP address to Ubuntu 16.04LTS
As mentioned at the beginning of this article, the network interface name has been changed from 'ethX' to' enXXXX' (enp0s3) since Ubuntu 15.10, so replace your interface name.
Before doing this, check the IP information on the system:
# ifconfig or # ip addr enp0s3: flags=4163 mtu 1500 inet 192.168.56.201 netmask 255.255.255.255.255.0 broadcast 192.168.56.255 inet6 fe80::a00:27ff:fe97:132e prefixlen 64 scopeid 0x20 ether 08purr 277purse 97coupe 13e txqueuelen 1000 (Ethernet) RX packets 7 bytes 420 (420.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 294 bytes 24747 (24.7 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 enp0s8: flags=4163 mtu 1500 inet 10.0.3.15 netmask 255.255.255.0 broadcast 10.0.3.255 inet6 fe80::344b:6259:4dbe:eabb prefixlen 64 scopeid 0x20 ether 08:00:27:12:e8:c1 txqueuelen 1000 (Ethernet) RX packets 1 bytes 590 (590.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 97 bytes 10209 (10209 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 325 bytes 24046 (24.0 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 325 bytes 24046 (24.0 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
As I can see, the primary IP address of the server is 192.168.56.201, so I will use the next IP 192.168.56.202 as the secondary IP, using the following command.
# ip addr add 192.168.56.202/24 broadcast 192.168.56.255 dev enp0s3
Run the following command to check if a new IP has been assigned. When you restart the machine, it will disappear.
# ip addr1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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 group default qlen 1000 link/ether 08:00:27:97:13:2e Brd ff:ff:ff:ff:ff:ff inet 192.168.56.201/24 brd 192.168.56.255 scope global enp0s3 valid_lft forever preferred_lft forever inet 192.168.56.202/24 brd 192.168.56.255 scope global secondary enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe97:132e/64 scope link valid_lft forever preferred_lft forever3: enp0s8: mtu 1500 qdisc pfifo_fast state UP group default Qlen 1000 link/ether 08:00:27:12:e8:c1 brd ff:ff:ff:ff:ff:ff inet 10.0.3.15 brd 24 brd 10.0.3.255 scope global dynamic enp0s8 valid_lft 86353sec preferred_lft 86353sec inet6 fe80::344b:6259:4dbe:eabb/64 scope link valid_lft forever preferred_lft forever how to add * Secondary IP address to Ubuntu 16.04 LTS
To add a * * secondary IP address on a Ubuntu system, simply edit the / etc/network/interfaces file and add the details of the required IP.
We should not add a secondary IP address after the dns-nameservers line because it will not work and we should add the IP details in the following format.
In addition, we do not need to add subinterfaces (what we did earlier in Ubuntu 14.04 LTS):
# vi / etc/network/interfaces # interfaces (5) file used by ifup (8) and ifdown (8) auto loiface lo inet loopback # The primary network interfaceauto enp0s3iface enp0s3 inet staticaddress 192.168.56.201netmask 255.255.255.0 iface enp0s3 inet staticaddress 192.168.56.202netmask 255.255.255.0 gateway 192.168.56.1network 192.168.56.0broadcast 192.168.56.255dns-nameservers 8.8.8.8 8.8.4.4dns-search 2daygeek.local
Save and close the file, and then restart the network interface service:
# systemctl restart networking or # ifdown enp0s3 & & ifup enp0s3
Run the following command to check if a new IP has been assigned:
# ip addr1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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 group default qlen 1000 link/ether 08:00:27:97:13:2e Brd ff:ff:ff:ff:ff:ff inet 192.168.56.201/24 brd 192.168.56.255 scope global enp0s3 valid_lft forever preferred_lft forever inet 192.168.56.202/24 brd 192.168.56.255 scope global secondary enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe97:132e/64 scope link valid_lft forever preferred_lft forever3: enp0s8: mtu 1500 qdisc pfifo_fast state UP group default Qlen 1000 link/ether 08:00:27:12:e8:c1 brd ff:ff:ff:ff:ff:ff inet 10.0.3.15/24 brd 10.0.3.255 scope global dynamic enp0s8 valid_lft 86353sec preferred_lft 86353sec inet6 fe80::344b:6259:4dbe:eabb/64 scope link valid_lft forever preferred_lft forever
Let me ping the new IP address:
# ping 192.168.56.202-c 4PING 192.168.56.202 (192.168.56.202) 56 (84) bytes of data.64 bytes from 192.168.56.202: icmp_seq=1 ttl=64 time=0.019 ms64 bytes from 192.168.56.202: icmp_seq=2 ttl=64 time=0.087 ms64 bytes from 192.168.56.202: icmp_seq=3 ttl=64 time=0.034 ms64 bytes from 192.168.56.202: icmp_seq=4 ttl=64 time=0.042 ms-- 192.168.56.202 ping statistics-- 4 packets transmitted, 4 received 0% packet loss, time 3068msrtt min/avg/max/mdev = 0.019 ms 0.045 + 0.087 ms is all the content of the article "how to add a secondary IP address in the Ubuntu system" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.