Static IP Configuration Issue on Debian Bookworm Server
Recently, I started hosting a server on my PC, and everything worked perfectly with a public IP. However, after changing the public IP, I learned how to set up a static IP, but I encountered a loopback issue.
Understanding Static IP Address
A static IP address is a permanent IP address that does not change, unlike a dynamic IP address that can change over time. A static IP address is essential for hosting a server, running a website, or using remote desktop applications.
Setting Up Static IP Address on Debian Bookworm Server
To set up a static IP address on Debian Bookworm server, follow the steps below:
- Open the terminal and type
sudo nano /etc/netplan/01-netcfg.yamlto edit the network configuration file. - Find the network interface you want to configure, usually ens33, and replace the DHCP configuration with a static IP configuration, as shown below:
network:
version: 2
ethernets:
ens33:
dhcp4: no
dhcp6: no
addresses: [192.168.1.100/24]
routes:
- to: 192.168.1.1
via: 192.168.1.1
nameservers:
search: [example.com]
addresses: [8.8.8.8,8.8.4.4]In the above configuration, replace the IP addresses and DNS servers with your own values. The addresses field specifies the static IP address and subnet mask, while the routes field specifies the default gateway.
Loopback Issue
After setting up a static IP address, I encountered a loopback issue, where I could not access localhost or the server's IP address from the server itself. This issue occurs because the server's IP address is not in the loopback interface's network range.
Solving Loopback Issue
To solve the loopback issue, add the server's IP address to the loopback interface's network range. Edit the /etc/netplan/01-netcfg.yaml file and add the following configuration:
network:
version: 2
ethernets:
ens33:
dhcp4: no
dhcp6: no
addresses: [192.168.1.100/24]
routes:
- to: 192.168.1.1
via: 192.168.1.1
nameservers:
search: [example.com]
addresses: [8.8.8.8,8.8.4.4]
vlans:
lo:
id: 1
link: lo
ip-address: 127.0.0.1/8
127.0.1.1/32
192.168.1.100/32In the above configuration, the server's IP address, 192.168.1.100, is added to the loopback interface's network range. This configuration allows the server to access its IP address and localhost from itself.
- A static IP address is a permanent IP address that does not change.
- To set up a static IP address on Debian Bookworm server, edit the
/etc/netplan/01-netcfg.yamlfile and replace the DHCP configuration with a static IP configuration. - After setting up a static IP address, add the server's IP address to the loopback interface's network range to solve the loopback issue.
References
- Debian Handbook: https://debian-handbook.info/get/
- Debian Wiki: https://wiki.debian.org/
- Arch Linux Wiki: https://wiki.archlinux.org/