diff --git a/tech_docs/linux/debian_networking.md b/tech_docs/linux/debian_networking.md index f05fca6..cf02765 100644 --- a/tech_docs/linux/debian_networking.md +++ b/tech_docs/linux/debian_networking.md @@ -1,93 +1,338 @@ -Certainly! Here's a more detailed guide on how to manage network configurations on a Debian 12 server using different methods, with additional context and instructions tailored to your preference for using VIM as a text editor. +# Network Configuration on Debian 12: Comprehensive Guide -### Network Configuration on Debian 12 +Debian 12 (Bookworm) provides multiple approaches for network configuration, each suited to different use cases and environments. Understanding which method your system uses is crucial for effective network management. -Debian 12 can manage network configurations through traditional Debian methods like the `/etc/network/interfaces` file, or modern methods such as `systemd-networkd` and NetworkManager. Below is a comprehensive guide on how to adjust the default route using these methods, and how to use VIM for editing configuration files. +## Understanding Network Management Systems -### 1. Using `/etc/network/interfaces` +### System Detection +Before making changes, determine which network management system is active: -For servers not using NetworkManager or `systemd-networkd`, the network settings are traditionally managed via the `/etc/network/interfaces` file. +```bash +# Check if NetworkManager is running +systemctl is-active NetworkManager -**Steps to modify the default route:** +# Check if systemd-networkd is running +systemctl is-active systemd-networkd -- **Open the configuration file with VIM**: - ```bash - sudo vim /etc/network/interfaces - ``` +# Check for traditional ifupdown configuration +ls -la /etc/network/interfaces +``` -- **Configure your network interface**: Here's an example of what your configuration might look like if you're setting a static IP and want to define which gateway the server should use: +**Important**: Only one network management system should be active to avoid conflicts. - ```plaintext - auto eth0 - iface eth0 inet static - address 192.168.1.100 - netmask 255.255.255.0 - gateway 192.168.1.1 - ``` +### Network Management Hierarchy +1. **NetworkManager**: Best for desktop environments and laptops with changing network conditions +2. **systemd-networkd**: Ideal for servers and containers requiring predictable, declarative configuration +3. **ifupdown** (`/etc/network/interfaces`): Traditional Debian method, suitable for simple server configurations - Make sure to replace `eth0` with the correct interface name, and update the `address`, `netmask`, and `gateway` with appropriate values for your network. Only set the `gateway` for the interface that should be the default route. +## Method 1: Traditional ifupdown Configuration -- **Restart networking to apply changes**: - ```bash - sudo systemctl restart networking - ``` +### When to Use +- Simple server setups with static configurations +- Legacy systems requiring compatibility +- Environments where minimal dependencies are preferred -### 2. Using `systemd-networkd` +### Implementation -If your server uses `systemd-networkd` for managing network interfaces, you'll configure them via `.network` files located in `/etc/systemd/network/`. +**1. Verify ifupdown is managing your interface:** +```bash +# Check current network interfaces +ip addr show +# Verify no NetworkManager or systemd-networkd conflicts +systemctl is-enabled NetworkManager systemd-networkd +``` -- **Create or edit a network file for your interface**: - ```bash - sudo vim /etc/systemd/network/10-eth0.network - ``` +**2. Edit the configuration file:** +```bash +sudo vim /etc/network/interfaces +``` - Here is what the configuration might look like: - ```plaintext - [Match] - Name=eth0 - - [Network] - DHCP=no - Address=192.168.1.100/24 - Gateway=192.168.1.1 - DNS=8.8.8.8 - ``` +**3. Example configurations:** - Adjust the interface name and network settings as necessary. +**Static IP with single interface:** +```plaintext +# The loopback network interface +auto lo +iface lo inet loopback -- **Restart `systemd-networkd` to apply changes**: - ```bash - sudo systemctl restart systemd-networkd - ``` +# Primary network interface +auto eth0 +iface eth0 inet static + address 192.168.1.100/24 + gateway 192.168.1.1 + dns-nameservers 8.8.8.8 8.8.4.4 + dns-search example.com + # Optional: Set metric for route priority + metric 100 +``` -### 3. Using NetworkManager +**Multiple interfaces with specific routing:** +```plaintext +auto lo +iface lo inet loopback -For servers with a graphical interface or for those preferring NetworkManager: +# Management interface (default route) +auto eth0 +iface eth0 inet static + address 192.168.1.100/24 + gateway 192.168.1.1 + dns-nameservers 8.8.8.8 + metric 100 -- **Edit connections using NMTUI**, or for command line changes: - ```bash - nmcli connection modify ipv4.addresses "192.168.1.100/24" ipv4.gateway "192.168.1.1" ipv4.dns "8.8.8.8" ipv4.method manual - ``` - Replace `` with the name of your connection. +# Secondary interface (no default gateway) +auto eth1 +iface eth1 inet static + address 10.0.0.100/24 + # Note: No gateway specified to avoid routing conflicts + metric 200 +``` -- **Apply changes**: - ```bash - nmcli connection up - ``` +**4. Apply changes:** +```bash +# Method 1: Restart networking service +sudo systemctl restart networking -### Making Temporary Changes +# Method 2: Bring interface down/up (less disruptive) +sudo ifdown eth0 && sudo ifup eth0 -For temporary routing adjustments: +# Verify configuration +ip route show +ip addr show eth0 +``` -- **Delete the existing default route**: - ```bash - sudo ip route del default - ``` -- **Add a new default route**: - ```bash - sudo ip route add default via 192.168.1.1 dev eth0 - ``` +### VIM Tips for Network Configuration +```bash +# VIM commands for efficient editing: +# :set number - Show line numbers +# :set syntax=conf - Enable syntax highlighting +# /gateway - Search for "gateway" +# :%s/old_ip/new_ip/g - Replace all occurrences of old_ip with new_ip +``` -These commands will modify the routing table until the next reboot or restart of the network service. +## Method 2: systemd-networkd Configuration -This comprehensive guide should help you manage your Debian server's network settings effectively. Whether you're making temporary changes or configuring settings for long-term use, these steps will ensure your network is set up according to your needs. \ No newline at end of file +### When to Use +- Modern server environments +- Container deployments +- Systems requiring advanced networking features (VLAN, bonding) +- Predictable network interface naming + +### Implementation + +**1. Enable systemd-networkd:** +```bash +# Disable conflicting services +sudo systemctl disable NetworkManager +sudo systemctl stop NetworkManager + +# Enable systemd-networkd +sudo systemctl enable systemd-networkd +sudo systemctl enable systemd-resolved # For DNS resolution +``` + +**2. Create network configuration:** +```bash +sudo vim /etc/systemd/network/10-eth0.network +``` + +**3. Configuration examples:** + +**Basic static configuration:** +```ini +[Match] +Name=eth0 +# Alternative matching options: +# MACAddress=aa:bb:cc:dd:ee:ff +# Driver=e1000e + +[Network] +DHCP=no +Address=192.168.1.100/24 +Gateway=192.168.1.1 +DNS=8.8.8.8 +DNS=8.8.4.4 +Domains=example.com + +# Optional advanced settings +[Route] +Destination=10.0.0.0/8 +Gateway=192.168.1.254 +Metric=100 +``` + +**Advanced configuration with multiple routes:** +```ini +[Match] +Name=eth0 + +[Network] +DHCP=no +Address=192.168.1.100/24 +DNS=8.8.8.8 + +# Multiple routes +[Route] +Gateway=192.168.1.1 +Metric=100 +# This becomes the default route due to lowest metric + +[Route] +Destination=10.0.0.0/8 +Gateway=192.168.1.254 +Metric=200 +``` + +**4. Apply configuration:** +```bash +sudo systemctl restart systemd-networkd +sudo systemctl restart systemd-resolved + +# Verify status +networkctl status +networkctl status eth0 +``` + +## Method 3: NetworkManager Configuration + +### When to Use +- Desktop environments +- Systems with wireless interfaces +- Dynamic network environments +- GUI management preferred + +### Command Line Interface +```bash +# List connections +nmcli connection show + +# Modify existing connection +nmcli connection modify "Wired connection 1" \ + ipv4.addresses "192.168.1.100/24" \ + ipv4.gateway "192.168.1.1" \ + ipv4.dns "8.8.8.8,8.8.4.4" \ + ipv4.method manual + +# Create new connection +nmcli connection add \ + type ethernet \ + con-name "Static-eth0" \ + ifname eth0 \ + ipv4.addresses 192.168.1.100/24 \ + ipv4.gateway 192.168.1.1 \ + ipv4.dns "8.8.8.8" \ + ipv4.method manual + +# Apply changes +nmcli connection up "Static-eth0" +``` + +### Text User Interface +```bash +sudo nmtui +# Navigate through the menu-driven interface +``` + +## Temporary Route Management + +### Understanding Route Priority +Routes with lower metric values take precedence. Use `ip route show` to view current routing table with metrics. + +### Temporary Changes +```bash +# View current routing table +ip route show + +# Delete specific default route +sudo ip route del default via 192.168.1.1 dev eth0 + +# Add new default route with metric +sudo ip route add default via 192.168.1.1 dev eth0 metric 100 + +# Add specific network route +sudo ip route add 10.0.0.0/8 via 192.168.1.254 dev eth0 + +# Flush all routes for interface (use with caution) +sudo ip route flush dev eth0 +``` + +**Note**: Temporary changes are lost on reboot or network service restart. + +## Troubleshooting and Verification + +### Essential Commands +```bash +# Network interface status +ip addr show +ip link show + +# Routing table +ip route show +ip route get 8.8.8.8 # Test route to specific destination + +# DNS resolution +resolvectl status +nslookup google.com + +# Connectivity testing +ping -c 4 192.168.1.1 # Gateway connectivity +ping -c 4 8.8.8.8 # Internet connectivity +traceroute 8.8.8.8 # Route tracing +``` + +### Common Issues and Solutions + +**1. Multiple default routes:** +```bash +# Identify multiple default routes +ip route show | grep default + +# Remove unwanted default route +sudo ip route del default via [unwanted_gateway] +``` + +**2. Interface naming changes:** +```bash +# Find interface names +ip link show +# or +ls /sys/class/net/ + +# Update configuration files with correct interface names +``` + +**3. DNS resolution issues:** +```bash +# Check DNS configuration +cat /etc/resolv.conf +resolvectl status + +# Restart DNS resolution service +sudo systemctl restart systemd-resolved +``` + +## Best Practices + +1. **Backup configurations** before making changes: + ```bash + sudo cp /etc/network/interfaces /etc/network/interfaces.backup + ``` + +2. **Test connectivity** after changes: + ```bash + ping -c 4 [gateway_ip] + ping -c 4 8.8.8.8 + ``` + +3. **Use consistent interface naming** with systemd predictable network interface names + +4. **Document network changes** for future reference + +5. **Implement gradual changes** in production environments + +6. **Monitor network performance** after configuration changes: + ```bash + ss -tuln # Show listening ports + netstat -rn # Show routing table + ``` + +This enhanced guide provides the context and depth needed for effective network management on Debian 12 systems, with clear explanations of when and why to use each method. \ No newline at end of file