{"id":2892,"date":"2020-12-25T15:59:33","date_gmt":"2020-12-25T15:59:33","guid":{"rendered":"https:\/\/linuxways.net\/?p=2892"},"modified":"2020-12-25T15:59:40","modified_gmt":"2020-12-25T15:59:40","slug":"how-to-assign-multiple-ip-addresses-to-single-nic-in-debian-10","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/how-to-assign-multiple-ip-addresses-to-single-nic-in-debian-10\/","title":{"rendered":"How to Assign Multiple IP Addresses to Single NIC in Debian 10"},"content":{"rendered":"<p>Setting up multiple IP addresses on a single NIC can be required for various reasons like to bind different services to different IP addresses, to host multiple SSL sites, etc. This post is going to show you how to assign multiple IP addresses to a single NIC in Debian system. If you are using the Ubuntu OS, you can visit our post on <a href=\"https:\/\/linuxways.net\/de\/ubuntu\/how-to-assign-multiple-ip-addresses-to-single-nic-in-ubuntu-20-04-lts\/\">How to assign multiple IP addresses to a single NIC in Ubuntu<\/a>.<\/p>\n<p>Note: We will be using Debian 10 (Buster) for testing the commands and procedure.<\/p>\n<h2>Adding Multiple IP Addresses to Single NIC Temporarily<\/h2>\n<p>We can add the secondary IP address to the network interface temporarily. The IP address added by this method stays until you reboot the system. Let\u2019s see how to add this:<\/p>\n<p>1. Before configuring the secondary IP address, you can <a href=\"https:\/\/linuxways.net\/de\/debian\/how-to-find-your-private-ip-address-in-debian-10\/\">check the current IP address<\/a> of the system by running the following command:<\/p>\n<pre>$ ip a<\/pre>\n<p>or<\/p>\n<pre>$ ifconfig<\/pre>\n<p>This is what the output of the &#8220;ip a\u201d command on our system looks like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1042\" height=\"261\" class=\"wp-image-2893\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address.png\" alt=\"view current ip address\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address.png 1042w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-300x75.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-1024x256.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-768x192.png 768w\" sizes=\"auto, (max-width: 1042px) 100vw, 1042px\" \/><\/p>\n<p>You can see the current or main IP address on our system is <strong>192.168.72.189\/24<\/strong> on NIC <strong>ens37<\/strong>.<\/p>\n<p>2. Now, we are going to assign the secondary IP address to it.<\/p>\n<p>To assign a secondary IP address to a NIC, the syntax is as follows:<\/p>\n<pre>$ ip adder add &lt;ip-address&gt; dev &lt;interface-name&gt;<\/pre>\n<p>For instance, to assign <strong>10.1.1.10\/8<\/strong> as the secondary IP to NIC <strong>ens37<\/strong>, we will run the following command:<\/p>\n<pre>$ ip addr add 10.1.1.10\/8 dev ens37<\/pre>\n<p>3. Now, run the following command to verify if the secondary IP address has been added to the NIC:<\/p>\n<pre>$ ip a<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1043\" height=\"308\" class=\"wp-image-2894\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-1.png\" alt=\"view current ip address\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-1.png 1043w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-1-300x89.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-1-1024x302.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-1-768x227.png 768w\" sizes=\"auto, (max-width: 1043px) 100vw, 1043px\" \/><\/p>\n<p>Similarly, you can add more IP addresses to your NIC. However, as discussed earlier, these IP addresses are temporary and cannot survive a reboot.<\/p>\n<h2>Removing the Multiple IP addresses from NIC<\/h2>\n<p>There are two ways to remove the additional IP addresses from the NIC. The first one is to reboot the system which automatically removes the temporary IP addresses from the NIC. However, rebooting a system is not a practical solution. The alternate and the right way is to manually remove the IP addresses using \u201cip addr del\u201d command.<\/p>\n<p>Here is the command for removing the IP address from the system:<\/p>\n<pre>$ sudo ip addr del &lt;ip-address&gt; dev &lt;interface-name&gt;<\/pre>\n<p>For instance, in order to remove the IP address, <strong>10.1.1.10\/8<\/strong> added to the <strong>ens37<\/strong>, we would run the following command:<\/p>\n<pre>$ sudo ip addr del 10.1.1.10\/8 dev ens37<\/pre>\n<h2>Adding Multiple IP Addresses to Single NIC Permanently<\/h2>\n<p>The \u201cip addr\u201d command temporarily assigns the secondary IP address to a NIC. You can also permanently assign the secondary IP address using <strong>the interface <\/strong>configuration file so that it remains persistent even if the system is rebooted. Let\u2019s see how to do this:<\/p>\n<p>1. Before configuring the secondary IP address, you can <a href=\"https:\/\/linuxways.net\/de\/debian\/how-to-find-your-private-ip-address-in-debian-10\/\">check the current IP address<\/a> of the system by running the following command:<\/p>\n<pre>$ ip a<\/pre>\n<p>or<\/p>\n<pre>$ ifconfig<\/pre>\n<p>This is what the output of the &#8220;ip a\u201d command on our system looks like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1042\" height=\"261\" class=\"wp-image-2895\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-2.png\" alt=\"view current ip address\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-2.png 1042w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-2-300x75.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-2-1024x256.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/view-current-ip-address-2-768x192.png 768w\" sizes=\"auto, (max-width: 1042px) 100vw, 1042px\" \/><\/p>\n<p>You can see the current or main IP address on our system is <strong>192.168.72.189\/24<\/strong> on NIC <strong>ens37<\/strong>. Now we are going to assign the secondary IP address to it.<\/p>\n<p>2. Edit the <strong>NIC <\/strong>configuration file as follows:<\/p>\n<pre>$ sudo nano \/etc\/network\/interfaces<\/pre>\n<p>This is how the default interfaces configuration file looks like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"657\" height=\"397\" class=\"wp-image-2896\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/interface-configuration-file.png\" alt=\"interface configuration file\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/interface-configuration-file.png 657w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/interface-configuration-file-300x181.png 300w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/p>\n<p>3. Now, under the current configuration lines, add an entry for the secondary IP address using the following syntax:<\/p>\n<pre>iface &lt;interface-name&gt; inet static\n\naddress &lt;ip-address&gt;<\/pre>\n<p>For instance, to assign <strong>10.1.1.10\/8<\/strong> as the secondary IP address to NIC <strong>ens37<\/strong>, we will add the following entry in the <strong>\/etc\/network\/interfaces<\/strong> file:<\/p>\n<pre>iface ens37 inet static\n\naddress 10.1.1.10\/8<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"657\" height=\"397\" class=\"wp-image-2897\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/interface-configuration-file-1.png\" alt=\"interface configuration file\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/interface-configuration-file-1.png 657w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/interface-configuration-file-1-300x181.png 300w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><\/p>\n<p>Similarly, you can add more IP addresses to your NIC. Once you are done with the configurations, save and close the interface configuration file.<\/p>\n<p>4. Now, in order to apply the configuration changes you have made to the interfaces configuration file, restart the networking service as follows:<\/p>\n<pre>$ sudo systemctl restart networking.service<\/pre>\n<p>On the other hand, you can also apply the configuration changes by bringing down and bringing up the network interface.<\/p>\n<p>To bring down the network interface, run the following command:<\/p>\n<pre>$ sudo ifdown ens37<\/pre>\n<p>Then run the following command to bring it up:<\/p>\n<pre>$ sudo ifup ens37<\/pre>\n<p>5. Now, run the following command to verify if the secondary IP address has been added to the NIC:<\/p>\n<pre>$ ip a<\/pre>\n<h2>Removing the Multiple IP addresses from NIC<\/h2>\n<p>You can also remove the IP address permanently assigned to the network interface. Here is how to do it:<\/p>\n<p>1. Edit the <strong>interfaces configuration<\/strong> file:<\/p>\n<pre>$ sudo nano \/etc\/network.interfaces<\/pre>\n<p>2. Now, remove the additional IP addresses entries you have added to a NIC except for the main IP address. Once you are done, save, and close the file.<\/p>\n<p>3. Now, restart the networking services to apply the configuration changes as follows:<\/p>\n<pre>$ sudo systemctl restart networking.service<\/pre>\n<p>On the other hand, you can also apply the configuration changes by bringing down and bringing up the network interface.<\/p>\n<p>To bring down the network interface, run the following command:<\/p>\n<pre>$ sudo ifdown ens37<\/pre>\n<p>Then run the following command to bring it up:<\/p>\n<pre>$ sudo ifup ens37<\/pre>\n<p>4. Now, run the following command to verify if the secondary IP address has been removed to the NIC:<\/p>\n<pre>$ ip a<\/pre>\n<p>In this post, you have learned how to assign and remove multiple IP addresses to and from a single NIC. Based on your preferences, you can either assign the multiple IP addresses temporarily or permanently as described in this post.<\/p>","protected":false},"excerpt":{"rendered":"<p>Setting up multiple IP addresses on a single NIC can be required for various reasons like to bind different services to different IP addresses, to host multiple SSL&hellip;<\/p>","protected":false},"author":4,"featured_media":2900,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[122,109,110],"class_list":["post-2892","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","tag-debian-2","tag-multiple-ip-addresses","tag-nic"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2892","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=2892"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2892\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/2900"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=2892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=2892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=2892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}