Wiki source code of Netzwerk
Version 1.1 by René Schmidt on 2023/09/20 14:24
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | (% class="jumbotron" %) | ||
| 2 | ((( | ||
| 3 | (% class="container" %) | ||
| 4 | ((( | ||
| 5 | = [[How to set up static IP address on Debian Linux 10/11>>url:https://www.cyberciti.biz/faq/add-configure-set-up-static-ip-address-on-debianlinux/]] = | ||
| 6 | |||
| 7 | The procedure is as follows to set up and configure a static IP information: | ||
| 8 | |||
| 9 | 1. Open the terminal application. | ||
| 10 | 1. Log in to remote or server using ssh command. | ||
| 11 | 1. Backup /etc/network/interfaces file running ##**sudo cp /etc/network/interfaces /root/**## | ||
| 12 | 1. Edit the /etc/network/interfaces | ||
| 13 | 1. Configure static IP address for enp0s5 Ethernet interface: ##**address 192.168.2.249**## | ||
| 14 | 1. Add subnet mask: ##**netmask 255.255.255.0**## | ||
| 15 | 1. Set up default gateway IP: ##**gateway 192.168.2.254**## | ||
| 16 | 1. Finally add DNS resolver IP: ##**dns-nameservers 192.168.2.254 8.8.8.8 1.1.1.1**## | ||
| 17 | |||
| 18 | Let us see all commands and examples in details. | ||
| 19 | ))) | ||
| 20 | ))) | ||
| 21 | |||
| 22 | (% class="row" %) | ||
| 23 | ((( | ||
| 24 | (% class="col-xs-12 col-sm-8" %) | ||
| 25 | ((( | ||
| 26 | == Finding your network interfaces name on Debian Linux == | ||
| 27 | |||
| 28 | Use the [[ip command>>url:https://www.cyberciti.biz/faq/linux-ip-command-examples-usage-syntax/]] as follows to [[show/display available Ethernet network interfaces>>url:https://www.cyberciti.biz/faq/linux-list-network-interfaces-names-command/]]: | ||
| 29 | ip -c link show | ||
| 30 | Also, we can try the following [[Linux command to show a list of network cards>>url:https://www.cyberciti.biz/faq/linux-list-network-cards-command/]]: | ||
| 31 | sudo lshw -class network -short | ||
| 32 | # Filter results using [[grep>>url:https://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/]]/[[egrep regex command>>url:https://www.cyberciti.biz/faq/grep-regular-expressions/]] | ||
| 33 | lspci | grep -E -i ~-~-color 'network|ethernet|wireless|wi-fi' | ||
| 34 | ip -br -c link show | ||
| 35 | Note down the Debian Linux interface name and type the following [[ip command>>url:https://www.cyberciti.biz/faq/linux-ip-command-examples-usage-syntax/]] to see [[the current IP address assinged to that network interface>>url:https://www.cyberciti.biz/faq/how-to-find-out-the-ip-address-assigned-to-eth0-and-display-ip-only/]]: | ||
| 36 | |||
| 37 | ip -c addr show enp0s5 | ||
| 38 | |||
| 39 | |||
| 40 | == Configuring Static IP on Debian 10 or 11 == | ||
| 41 | |||
| 42 | The /etc/network/interfaces[/file] contains network interface configuration information for Debian Linux. Hence, edit the file: | ||
| 43 | sudo vim /etc/network/interfaces | ||
| 44 | ~#~# OR ~#~# | ||
| 45 | |||
| 46 | (% class="box" %) | ||
| 47 | ((( | ||
| 48 | sudo nano /etc/network/interfaces | ||
| 49 | Look for the primary network interface enp0s5: | ||
| 50 | ))) | ||
| 51 | |||
| 52 | (% class="box" %) | ||
| 53 | ((( | ||
| 54 | allow-hotplug enp0s5 | ||
| 55 | iface enp0s5 inet dhcp | ||
| 56 | ))) | ||
| 57 | |||
| 58 | Remove dhcp and allow-hotplug lines. Append the following configuration to set up/add new static IP on Debian Linux 10/11. Here is my sample config file: | ||
| 59 | |||
| 60 | (% class="box" %) | ||
| 61 | ((( | ||
| 62 | # The loopback network interface | ||
| 63 | auto lo | ||
| 64 | iface lo inet loopback | ||
| 65 | |||
| 66 | # The primary network interface | ||
| 67 | auto enp0s5 | ||
| 68 | iface enp0s5 inet static | ||
| 69 | address 192.168.2.236 | ||
| 70 | netmask 255.255.255.0 | ||
| 71 | gateway 192.168.2.254 | ||
| 72 | dns-domain sweet.home | ||
| 73 | dns-nameservers 192.168.2.254 1.1.1.1 8.8.8.8 | ||
| 74 | ))) | ||
| 75 | |||
| 76 | [[Save and close the file when using vim/vi>>url:https://www.cyberciti.biz/faq/linux-unix-vim-save-and-quit-command/]] text editor. | ||
| 77 | |||
| 78 | == Restart networking service on Debian Linux to switch from DHCP to static IP config == | ||
| 79 | |||
| 80 | **Warning**: Do not run the following over ssh based session as you will disconnect. | ||
| 81 | |||
| 82 | Use the systemctl command as follows: | ||
| 83 | |||
| 84 | sudo systemctl restart networking.service | ||
| 85 | Make sure service restarted without any errors. Hence, type the following command:sudo systemctl status networking.service | ||
| 86 | Sample session: | ||
| 87 | |||
| 88 | (% class="box" %) | ||
| 89 | ((( | ||
| 90 | ● networking.service - Raise network interfaces | ||
| 91 | Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled) | ||
| 92 | Active: active (exited) since Wed 2021-01-27 23:10:00 IST; 1min 38s ago | ||
| 93 | Docs: man:interfaces(5) | ||
| 94 | Process: 1104 ExecStart=/sbin/ifup -a ~-~-read-environment (code=exited, status=0/SUCCESS) | ||
| 95 | Main PID: 1104 (code=exited, status=0/SUCCESS) | ||
| 96 | ))) | ||
| 97 | |||
| 98 | == See your new IP address assigned on Debian Linux == | ||
| 99 | |||
| 100 | (% class="box" %) | ||
| 101 | ((( | ||
| 102 | Again type the following [[ip command>>url:https://www.cyberciti.biz/faq/linux-ip-command-examples-usage-syntax/]]: | ||
| 103 | ip -c addr show | ||
| 104 | ip -c addr show enp0s5 | ||
| 105 | [[image:https://www.cyberciti.biz/media/new/faq/2021/01/How-to-configure-Static-IP-on-Debian-10-or-11.png||alt="How to configure Static IP on Debian 10 or 11" height="150" width="599"]] | ||
| 106 | When you change your IP address, you need to restart other services such as Nginx, SSH, etc. It all depends upon how you configured those services with IP binding. Make sure you adjust the firewall settings too. | ||
| 107 | ))) | ||
| 108 | |||
| 109 | |||
| 110 | == A note about /etc/network/interfaces.d/ directory == | ||
| 111 | |||
| 112 | **WARNING!** The following is an advanced configuration and is only recommended if you know various networking concepts. The nixCraft or author is not responsible for network connectivity loss. | ||
| 113 | |||
| 114 | You can place the network config in a separate file under /etc/network/interfaces.d/. I tested the following with Debian 11 with source keyword: | ||
| 115 | |||
| 116 | {{{source /etc/network/interfaces.d/*}}} | ||
| 117 | |||
| 118 | In other words, config lines beginning with “source” are used to include stanzas from other files. So configuration can be split into many files for ease of management. The word “source” is followed by the path of a file to be sourced. Shell wildcards can be used. Here is how ##/etc/network/interfaces## looks now: | ||
| 119 | |||
| 120 | sudo [[cat>>url:https://www.cyberciti.biz/faq/linux-unix-appleosx-bsd-cat-command-examples/]] /etc/network/interfaces | ||
| 121 | Outputs: | ||
| 122 | |||
| 123 | (% class="box" %) | ||
| 124 | ((( | ||
| 125 | # This file describes the network interfaces available on your system | ||
| 126 | # and how to activate them. For more information, see interfaces(5). | ||
| 127 | |||
| 128 | source /etc/network/interfaces.d/* | ||
| 129 | |||
| 130 | # The loopback network interface | ||
| 131 | auto lo | ||
| 132 | iface lo inet loopback | ||
| 133 | ))) | ||
| 134 | |||
| 135 | Here is my servers bridge network config file named /etc/network/interfaces.d/br0 | ||
| 136 | |||
| 137 | sudo vim /etc/network/interfaces.d/br0 | ||
| 138 | Append the following config to create br0 interface using eno1 Ethernet interface. For example: | ||
| 139 | |||
| 140 | (% class="box" %) | ||
| 141 | ((( | ||
| 142 | auto br0 | ||
| 143 | iface br0 inet static | ||
| 144 | address 192.168.2.19 | ||
| 145 | broadcast 192.168.2.255 | ||
| 146 | netmask 255.255.255.0 | ||
| 147 | gateway 192.168.2.254 | ||
| 148 | # If the resolvconf package is installed, you should not edit | ||
| 149 | # the resolv.conf configuration file manually. Set name server here | ||
| 150 | dns-nameservers 192.168.2.236 192.168.2.237 | ||
| 151 | dns-domain sweet.home | ||
| 152 | # If you have multiple interfaces such as eth0 and eth1 | ||
| 153 | # bridge_ports eth0 eth1 | ||
| 154 | bridge_ports eno1 | ||
| 155 | bridge_stp off # disable Spanning Tree Protocol | ||
| 156 | bridge_waitport 0 # no delay before a port becomes available | ||
| 157 | bridge_fd 0 # no forwarding delay | ||
| 158 | ))) | ||
| 159 | |||
| 160 | Then restart networking service on Debian Linux or [[reboot the Linux machine>>url:https://www.cyberciti.biz/faq/howto-reboot-linux/]] using the [[shutdown command>>url:https://www.cyberciti.biz/faq/howto-shutdown-linux/]]/[[reboot command>>url:https://www.cyberciti.biz/faq/howto-reboot-linux/]]. For instance: | ||
| 161 | |||
| 162 | (% class="box" %) | ||
| 163 | ((( | ||
| 164 | sudo reboot | ||
| 165 | OR | ||
| 166 | systemctl restart networking.service | ||
| 167 | ))) | ||
| 168 | |||
| 169 | == Conclusion == | ||
| 170 | |||
| 171 | (% class="box" %) | ||
| 172 | ((( | ||
| 173 | You learned how to convert the existing DHCP to static IP address settings on Debian Linux version 9/10/11. See Debian Linux [[man page online>>url:https://www.debian.org/doc/manuals/debian-reference/ch05.en.html]] or type the following command: | ||
| 174 | man interfaces | ||
| 175 | man nmcli | ||
| 176 | ))) | ||
| 177 | ))) | ||
| 178 | |||
| 179 | |||
| 180 | (% class="col-xs-12 col-sm-4" %) | ||
| 181 | ((( | ||
| 182 | {{box title="**Contents**"}} | ||
| 183 | {{toc/}} | ||
| 184 | {{/box}} | ||
| 185 | |||
| 186 | [[image:https://www.cyberciti.biz/media/new/faq/2021/01/How-to-setup-a-Static-IP-address-on-Debian-Linux.png||alt="How to setup a Static IP address on Debian Linux" height="305" width="590"]] | ||
| 187 | Finding NIC name and IP assigned by the DHCP server on Debian Linux | ||
| 188 | |||
| 189 | |||
| 190 | |||
| 191 | ))) | ||
| 192 | ))) |