{"id":9968,"date":"2021-09-20T10:25:03","date_gmt":"2021-09-20T10:25:03","guid":{"rendered":"https:\/\/linuxways.net\/?p=9968"},"modified":"2021-09-20T10:25:03","modified_gmt":"2021-09-20T10:25:03","slug":"how-to-set-a-static-ip-on-debian-11","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/debian\/how-to-set-a-static-ip-on-debian-11\/","title":{"rendered":"How to Set a Static IP on Debian 11"},"content":{"rendered":"<p>On a DHCP network, your Linux system will usually receive an IP address automatically from the DHCP server which, in most cases, is the router. The IP configuration will usually comprise the IPv4 address, the netmask, gateway, and the DNS settings. This is usually convenient for desktop or client PCs which only need to access the internet or network resources.<\/p>\n<p>However, the case is different when you want to set up a server. In this case, you would need to configure a static IP to make the server always available via the same IP address. With DHCP, the IP address is bound to change once the lease time is over leading to the unavailability of the server.<\/p>\n<p>In this guide, we will take you through a walk-through of how to set a static IP on Debian 11. We will demonstrate how you can configure a static IP on both the desktop GUI and server instances.<\/p>\n<h2><strong>Prerequisites<\/strong><\/h2>\n<p>As you set sail, ensure that you have an instance of Debian 11 server installed and set up. In addition, ensure that you have configured a sudo user.<\/p>\n<p>There are two ways of configuring a static IP on Debian. You can achieve this using GUI or on command-line.<\/p>\n<h2><strong>Configure Static IP Address using the Graphical User Interface ( GUI )<\/strong><\/h2>\n<p>If you are running a Debian 11 desktop instance, log in using your username and password. Before we configure the static IP, first confirm the IP address assigned to your system. In our case, we have a Debian PC with an IP address of 192.168.2.104 in a DHCP network.<\/p>\n<p>You can verify this using the command shown.<\/p>\n<pre><strong>$ ip addr show<\/strong><\/pre>\n<p>In our system, <strong>enp0s3 <\/strong>interface is the active link that is assigned the IP address. This may be something else in your case.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"779\" height=\"308\" class=\"wp-image-9969\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-170.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-170.png 779w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-170-300x119.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-170-768x304.png 768w\" sizes=\"auto, (max-width: 779px) 100vw, 779px\" \/><\/p>\n<p>To get started with setting the static IP, click on <strong>\u2018Activities<\/strong>\u2019 on the left far corner. Search for and click on the \u2018<strong>Settings<\/strong>\u2019 icon.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"437\" class=\"wp-image-9970\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-171.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-171.png 800w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-171-300x164.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-171-768x420.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/strong><\/p>\n<p>On the \u2018Settings\u2019 page, select the \u2018<strong>Network<\/strong>\u2019 tab. Next, head over to the \u2018Wired\u2019 section and click on the small gear wheel as indicated.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"801\" height=\"596\" class=\"wp-image-9971\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-172.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-172.png 801w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-172-300x223.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-172-768x571.png 768w\" sizes=\"auto, (max-width: 801px) 100vw, 801px\" \/><\/strong><\/p>\n<p>This displays the current IP address configuration as shown. As we confirmed earlier, our current IP address is 192.168.2.104. This has been dynamically allocated to the active interface using the DHCP service.<\/p>\n<p>We are going to override the DHCP settings and manually set a static IP which will persist even upon a reboot.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"801\" height=\"582\" class=\"wp-image-9972\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-173.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-173.png 801w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-173-300x218.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-173-768x558.png 768w\" sizes=\"auto, (max-width: 801px) 100vw, 801px\" \/><\/strong><\/p>\n<p>Click the <strong>IPv4<\/strong> tab. Switch from \u2018<strong>Automatic<\/strong>\u2019 to <strong>\u2018Manual<\/strong>\u2019 in the <strong>IPv4 method<\/strong> section. Thereafter, specify your desired IP address, netmask, and default gateway. Be sure to also provide the preferred DNS settings.<\/p>\n<p>To apply the changes made, click the \u2018<strong>Apply\u2019<\/strong> button.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"557\" class=\"wp-image-9973\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-174.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-174.png 800w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-174-300x209.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-174-768x535.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/strong><\/p>\n<p>You need to restart the networking daemon or service for the Debian system to implement the new static IP settings. So, turn the toggle button off and then on.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"861\" height=\"455\" class=\"wp-image-9974\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-175.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-175.png 861w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-175-300x159.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-175-768x406.png 768w\" sizes=\"auto, (max-width: 861px) 100vw, 861px\" \/><\/strong><\/p>\n<p>Click on the gear icon once more to verify that the static IP settings have been applied.<\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"799\" height=\"561\" class=\"wp-image-9975\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-176.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-176.png 799w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-176-300x211.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-176-768x539.png 768w\" sizes=\"auto, (max-width: 799px) 100vw, 799px\" \/><\/strong><\/p>\n<p>On the terminal, verify that the network interface has acquired the newly configured IP address:<\/p>\n<pre><strong>$ ip addr show<\/strong><\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"735\" height=\"311\" class=\"wp-image-9976\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-177.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-177.png 735w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-177-300x127.png 300w\" sizes=\"auto, (max-width: 735px) 100vw, 735px\" \/><\/strong><\/p>\n<p>The output is a confirmation that the system was successfully configured using a static IP. Let\u2019s now shift gears and explore setting a static IP on the command line.<\/p>\n<h2><strong>Configure Static IP Address using the terminal<\/strong><\/h2>\n<p>If you are running a headless server, or are connecting to a remote server via SSH, the only option available is to configure the static IP on the command line.<\/p>\n<p>The network configuration settings are stored in the <strong>\/etc\/network\/interfaces <\/strong>file. Have a peek at the file as follows. Feel free to use Nano editor if you don\u2019t have vim installed.<\/p>\n<pre><strong>$ sudo vim \/etc\/network\/interfaces<\/strong><\/pre>\n<p>By default, only the loopback settings are specified.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"736\" height=\"196\" class=\"wp-image-9977\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-178.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-178.png 736w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-178-300x80.png 300w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" \/><\/p>\n<p>We are going to specify the IP settings for our active network interface. But before making any changes, make a backup of the configuration file.<\/p>\n<pre><strong>$ sudo cp \/etc\/network\/interfaces \/etc\/network\/interface.bak<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"742\" height=\"122\" class=\"wp-image-9978\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-179.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-179.png 742w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-179-300x49.png 300w\" sizes=\"auto, (max-width: 742px) 100vw, 742px\" \/><\/p>\n<p>Specify the IP settings as provided. Ensure to make your settings in accordance with your network subnet.<\/p>\n<pre><strong>auto enp0s3<\/strong>\r\n\r\n<strong>iface enp0s3 inet static<\/strong>\r\n\r\n<strong> address 192.168.2.150<\/strong>\r\n\r\n<strong> netmask 255.255.255.0<\/strong>\r\n\r\n<strong> gateway 192.168.2.1<\/strong>\r\n\r\n<strong> dns-nameservers 8.8.8.8 192.168.2.1<\/strong><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"671\" height=\"376\" class=\"wp-image-9979\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-180.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-180.png 671w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-180-300x168.png 300w\" sizes=\"auto, (max-width: 671px) 100vw, 671px\" \/><\/p>\n<p>To apply the changes, restart the networking service.<\/p>\n<pre><strong>$ sudo systemctl restart networking<\/strong><\/pre>\n<p><strong>NOTE:<\/strong><\/p>\n<p>This will disconnect you from the server if you are connected via SSH. Reconnect using the newly set static IP address.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"733\" height=\"294\" class=\"wp-image-9980\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-181.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-181.png 733w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/09\/word-image-181-300x120.png 300w\" sizes=\"auto, (max-width: 733px) 100vw, 733px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>We have outlined two methods of assigning a static IP on your Debian 11 PC &#8211; using GUI and the terminal. The former is the easier option when working on a Debian desktop and the latter comes in handy when configuring a remote server via an SSH client.<\/p>","protected":false},"excerpt":{"rendered":"<p>On a DHCP network, your Linux system will usually receive an IP address automatically from the DHCP server which, in most cases, is the router. The IP configuration&hellip;<\/p>","protected":false},"author":1,"featured_media":10294,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[521,97],"class_list":["post-9968","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian","tag-debian-11","tag-ip-address"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/9968","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=9968"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/9968\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/10294"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=9968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=9968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=9968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}