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 set multiple IP addresses for a single network card on Ubuntu15.10

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

In this article, the editor introduces in detail "how to set multiple IP addresses for a single network card on Ubuntu15.10". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to set multiple IP addresses for a single network card on Ubuntu15.10" can help you solve your doubts.

If we buy a new network card and assign a new IP to set multiple IP is not necessary, in the Ubuntu system can use a network card to set multiple IP.

Temporarily add an IP address

First, let's find the IP address of the network card. In my Ubuntu 15.10 server version, I only used one network card.

Run the following command to find the IP address:

Sudo ip addr

Sample output:

1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6:: 1/128 scope host valid_lft forever preferred_lft forever2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000link/ether 08:00:27:2a:03:4b brd ff:ff:ff:ff:ff:ffinet 192.168.1. 103/24 brd 192.168.1.255 scope global enp0s3valid_lft forever preferred_lft foreverinet6 fe80::a00:27ff:fe2a:34e/64 scope link valid_lft forever preferred_lft forever

Or

Sudo ifconfig

Sample output:

Enp0s3 Link encap:Ethernet HWaddr 08:00:27:2a:03:4b inet addr:192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0inet6 addr: fe80::a00:27ff:fe2a:34e/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:186 errors:0 dropped:0 overruns:0 frame:0TX packets:70 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:21872 (21.8KB) TX bytes:9666 (9.6 KB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0inet6 addr:: 1Plus 128 Scope:HostUP LOOPBACK RUNNING MTU:65536 Metric:1RX packets:217 errors:0 dropped:0 overruns:0 frame:0TX packets:217 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:38793 (38.7 KB) TX bytes:38793 (38.7 KB)

As you can see in the output above, my network card name is enp0s3 and its IP address is 192.168.1.103.

Now let's add a new IP address to the network card, for example, 192.168.1.104.

Open your terminal and run the following command to add additional IP.

Sudo ip addr add 192.168.1.104/24 dev enp0s3

Use the command to check if the new IP is enabled:

Sudo ip address show enp0s3

Sample output:

2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000link/ether 08:00:27:2a:03:4e brd ff:ff:ff:ff:ff:ffinet 192.168.1.103/24 brd 192.168.1.255 scope global enp0s3valid_lft forever preferred_lft foreverinet 192.168.1.104/24 scope global secondary enp0s3valid_lft forever preferred_lft foreverinet6 fe80::a00:27ff:fe2a:34e/64 scope link valid_lft forever preferred_lft forever

Similarly, you can add as many IP addresses as you want.

Let's ping this IP address and verify it.

Sudo ping 192.168.1.104

Sample output

PING 192.168.1.104 (192.168.1.104) 56 (84) bytes of data.64 bytes from 192.168.1.104 icmp_seq=1 ttl=64 time=0.901 ms64 bytes from 192.168.1.104: icmp_seq=2 ttl=64 time=0.571 ms64 bytes from 192.168.1.104: icmp_seq=3 ttl=64 time=0.521 ms64 bytes from 192.168.1.104: icmp_seq=4 ttl=64 time=0.524 ms

Great, it works!

To delete an IP, simply run:

Sudo ip addr del 192.168.1.104/24 dev enp0s3

Check again to see if IP has been deleted.

Sudo ip address show enp0s3

Sample output:

2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000link/ether 08:00:27:2a:03:4e brd ff:ff:ff:ff:ff:ffinet 192.168.1.103/24 brd 192.168.1.255 scope global enp0s3valid_lft forever preferred_lft foreverinet6 fe80::a00:27ff:fe2a:34e/64 scope link valid_lft forever preferred_lft forever

You can see that it is gone!

As you know, these settings will fail after rebooting the system. So how do you set it to last forever? It's simple, too.

Add permanent IP address

The network card configuration file for the Ubuntu system is / etc/network/interfaces.

Let's take a look at the details of the above document.

Sudo cat / etc/network/interfaces

Sample output:

# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces (5). Source / etc/network/interfaces.d/*# The loopback network interfaceauto loiface lo inet loopback# The primary network interfaceauto enp0s3iface enp0s3 inet dhcp

As you can see in the output above, the network card has DHCP enabled.

Now, let's assign an additional address, such as 192.168.1.104Universe 24.

Edit / etc/network/interfaces:

Sudo nano / etc/network/interfaces

Add an additional IP address below.

# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces (5). Source / etc/network/interfaces.d/*# The loopback network interfaceauto loiface lo inet loopback# The primary network interfaceauto enp0s3iface enp0s3 inet dhcpiface enp0s3 inet static address 192.168.1.104 hand 24

Save and close the file.

Run the following command to make the changes take effect without a restart.

Sudo ifdown enp0s3 & & sudo ifup enp0s3

Sample output:

Killed old client processInternet Systems Consortium DHCP Client 4.3.1Copyright 2004-2014 Internet Systems Consortium.All rights reserved.For info, please visit https://www.isc.org/software/dhcp/Listening on LPF/enp0s3/08:00:27:2a:03:4eSending on LPF/enp0s3/08:00:27:2a:03:4eSending on Socket/fallbackDHCPRELEASE on enp0s3 to 192.168.1.1 port 67 (xid=0x225f35) Internet Systems Consortium DHCP Client 4.3.1Copyright 2004-2014 Internet Systems Consortium.All rights reserved.For info Please visit https://www.isc.org/software/dhcp/Listening on LPF/enp0s3/08:00:27:2a:03:4eSending on LPF/enp0s3/08:00:27:2a:03:4eSending on Socket/fallbackDHCPDISCOVER on enp0s3 to 255.255.255.255 port 67 interval 3 (xid=0xdfb94764) DHCPREQUEST of 192.168.1.103 on enp0s3 to 255.255.255.255 port 67 (xid=0x6447b9df) DHCPOFFER of 192.168.1.103 from 192.168.1.1DHCPACK of 192.168.1.103 from 192.168.1.1bound to 192.168.1.103-renewal in 35146 seconds.

Note: if you connect to the server remotely, it is important to put the above two commands on one line, because the first command will disconnect you. In this way, you can keep your ssh session.

Now, let's check if a new IP has been added with the following command:

Sudo ip address show enp0s3

Sample output:

2: enp0s3: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000link/ether 08:00:27:2a:03:4e brd ff:ff:ff:ff:ff:ffinet 192.168.1.103/24 brd 192.168.1.255 scope global enp0s3valid_lft forever preferred_lft foreverinet 192.168.1.104/24 brd 192.168.1.255 scope global secondary enp0s3valid_lft forever preferred_lft foreverinet6 fe80::a00:27ff:fe2a:34e/64 scope link valid_lft forever preferred_lft forever

Fine! We have added additional IP.

Verify the ping IP address again.

Sudo ping 192.168.1.104

Sample output:

PING 192.168.1.104 (192.168.1.104) 56 (84) bytes of data.64 bytes from 192.168.1.104: icmp_seq=1 ttl=64 time=0.137 ms64 bytes from 192.168.1.104: icmp_seq=2 ttl=64 time=0.050 ms64 bytes from 192.168.1.104: icmp_seq=3 ttl=64 time=0.054 ms64 bytes from 192.168.1.104: icmp_seq=4 ttl=64 time=0.067 ms reads here This article "how to set multiple IP addresses for a single network card on Ubuntu15.10" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, 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.

Share To

Development

Wechat

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

12
Report