Skip to content

Network Connectivity Issues

Cannot connect to Wi-Fi on Debian

When you can't connect to Wi-Fi on Debian, 99% of the time it's due to missing wireless card firmware. Out of commitment to free software, Debian's default standard installation images do not include this non-free firmware.

Core Solution: Install Firmware Packages

  1. Identify your wireless card:

    • Open a terminal and type lspci | grep -i network or lsusb | grep -i network to see your wireless card model. Common vendors include Intel, Realtek, Broadcom, and Atheros.
  2. Get and install the firmware:

    • Best method: Use a wired network

      • If your computer has an Ethernet port, plug in a network cable first.
      • Edit /etc/apt/sources.list to ensure it includes non-free and non-free-firmware.
      • Update the package list: sudo apt update
      • Install the corresponding firmware package based on your card's vendor:
        • Intel cards: sudo apt install firmware-iwlwifi
        • Realtek cards: sudo apt install firmware-realtek
        • Broadcom cards: sudo apt install firmware-brcm80211
        • Atheros cards: sudo apt install firmware-atheros
      • If you're unsure, you can install a collective package: sudo apt install firmware-linux-nonfree
      • After installation, it's best to reboot the computer or reload the kernel module.
    • No wired network: Manual installation

      1. On another computer with internet access, visit the Debian Packages website.
      2. Search for and download the firmware package you need (e.g., firmware-iwlwifi), which will be a .deb file.
      3. Copy this .deb file to your Debian computer using a USB drive.
      4. Install it using the apt command: sudo apt install ./firmware-iwlwifi_xxxxxxxx_all.deb.
    • The once-and-for-all solution: Use an unofficial image with integrated firmware

      • When installing Debian, download an installation image that includes all non-free firmware directly from the Debian unofficial images site. This will allow the installer to recognize and configure your wireless network during the installation process.

Wired network connection fails on Debian

Wired networks generally have fewer issues than wireless ones because the required firmware is more generic. If you encounter problems, follow these steps to troubleshoot:

  1. Check the physical connection:

    • Ensure the network cable is securely plugged in at both ends.
    • Check if the corresponding port's indicator lights on the router or switch are blinking normally.
  2. Check if the network card is recognized:

    • lspci | grep -i ethernet
    • If you can see your network card information, the hardware has been recognized by the system.
  3. Check the Network Manager status:

    • Debian desktop editions typically use the NetworkManager service to manage networks.
    • Check the service status: sudo systemctl status NetworkManager
    • If the service is not running, start it: sudo systemctl start NetworkManager
    • Click the network icon in the system tray to see if a wired connection is available.
  4. Check the IP address:

    • Run ip a or ifconfig.
    • Check if your wired network interface (usually enpXsY or eth0) has obtained an IP address.
    • If the IP address is 169.254.x.x, it means your computer failed to get an IP address from the router (DHCP server). Check your router's settings or restart the router.

How to set a static IP on Debian

Setting a static IP is common for servers or devices that require a fixed address.

Method 1: Using nmtui (Recommended, simple)

nmtui is a text-based NetworkManager configuration tool that is very intuitive.

  1. Run sudo nmtui in a terminal.
  2. Select "Edit a connection" and press Enter.
  3. Select your wired or wireless connection, move to "Edit...", and press Enter.
  4. In the "IPv4 CONFIGURATION" section, change <Automatic> to <Manual>.
  5. On the right side, click <Add...> in the "Addresses" section and enter the static IP address and subnet mask in the format 192.168.1.100/24.
  6. Enter your gateway address (usually the router's IP) in the "Gateway" field.
  7. Add DNS server addresses in the "DNS servers" field, such as 8.8.8.8 or 114.114.114.114.
  8. Move to <OK> at the bottom and press Enter to save.
  9. Exit nmtui, then restart the network connection for the changes to take effect: sudo systemctl restart NetworkManager.

Method 2: Modifying configuration files (Common for servers)

For servers without a desktop environment, you can directly edit the /etc/network/interfaces file.

Note: If your system is using NetworkManager, do not use this method as it will cause conflicts. This method is for systems where network interfaces are managed by ifupdown.

  1. Edit the file: sudo nano /etc/network/interfaces.
  2. Find the configuration for the relevant network interface and modify it as follows:
    # The primary network interface
    allow-hotplug enp1s0
    # iface enp1s0 inet dhcp  <-- Comment out or delete the DHCP line
    
    # Static IP configuration
    iface enp1s0 inet static
        address 192.168.1.100
        netmask 255.255.255.0
        gateway 192.168.1.1
        dns-nameservers 8.8.8.8 1.1.1.1
  3. After saving, restart the networking service: sudo systemctl restart networking or sudo /etc/init.d/networking restart.

How to share folders in Debian

  • Samba: Used for file sharing with Windows systems, and also widely used for sharing between Linux systems.
  • NFS (Network File System): The native, efficient file-sharing method between Linux/UNIX systems.

Using Samba (Compatible with Windows)

  1. Install Samba:
    bash
    sudo apt install samba
  2. Create a shared directory:
    bash
    mkdir /home/<your_username>/Share
  3. Configure Samba:
    • Edit the smb.conf file: sudo nano /etc/samba/smb.conf
    • Add your share configuration at the end of the file:
      [PublicShare]
         comment = Public Shared Folder
         path = /home/<your_username>/Share
         browseable = yes
         writable = yes
         guest ok = yes
         read only = no
      This is a simple anonymous share configuration that allows anyone on the network to read and write.
  4. Create a Samba user:
    • For security, it's usually necessary to create password-protected access. Samba user passwords are independent of system passwords.
    • sudo smbpasswd -a your_username (the username must be an existing system user)
    • Then set a Samba password for that user as prompted.
  5. Restart the Samba service:
    bash
    sudo systemctl restart smbd nmbd
  6. Access: In Windows File Explorer, enter \\<debian_ip_address>\ in the address bar. In a Linux file manager, connect to smb://<debian_ip_address>/.

How to connect to a remote desktop on Debian

  • VNC (Virtual Network Computing): Cross-platform, works like directly operating the screen.
  • RDP (Remote Desktop Protocol): Microsoft's protocol, which can be implemented on Linux using xrdp.

Using VNC (Example with TigerVNC)

  1. Install a VNC server on Debian:
    bash
    sudo apt install tigervnc-standalone-server tigervnc-xorg-extension
  2. Run it for the first time to set a password:
    • Run vncserver. It will prompt you to set a password for the connection.
  3. Configure the VNC session:
    • VNC needs to know which desktop environment to load on startup. Edit the ~/.vnc/xstartup file:
      bash
      nano ~/.vnc/xstartup
    • Ensure the file content is similar to this (example for Xfce):
      bash
      #!/bin/sh
      unset SESSION_MANAGER
      unset DBUS_SESSION_BUS_ADDRESS
      exec startxfce4
      For GNOME, it might be exec gnome-session; for KDE, exec startplasma-x11.
    • Add execute permission to the file: chmod +x ~/.vnc/xstartup
  4. Start the VNC server:
    • vncserver :1 (The :1 here represents a display port, which you'll need when connecting).
  5. Connect from another computer:
    • Use any VNC client (like RealVNC, TightVNC, TigerVNC Viewer).
    • Enter the server address: <debian_ip_address>:1
    • Enter the VNC password you set earlier.

Using RDP (xrdp)

xrdp essentially translates RDP requests into a VNC or local Xorg session in the background.

  1. Install xrdp:
    bash
    sudo apt install xrdp
  2. Add the xrdp user to the ssl-cert group:
    bash
    sudo adduser xrdp ssl-cert
  3. Restart the xrdp service:
    bash
    sudo systemctl restart xrdp
  4. Connect:
    • On Windows, open "Remote Desktop Connection" and enter the IP address of the Debian machine.
    • You will see the xrdp login screen. Choose the Xorg session and enter your Debian username and password.

What is the relationship between /etc/network/interfaces and NetworkManager? Which should I use?

These are two different network configuration management tools on Debian. You should typically use only one of them to avoid conflicts.

  • /etc/network/interfaces (provided by the ifupdown package)

    • Role: The traditional, stable, text-file-based method of network configuration.
    • How it works: You manually edit the /etc/network/interfaces file to define the configuration for each network interface (e.g., enp3s0), specifying whether it's DHCP or a static IP, what the address is, etc. You then use ifup <interface> and ifdown <interface> commands to activate or deactivate the interface.
    • Pros: Static configuration, very reliable, no extra background processes. It's the preferred choice in a server environment.
    • Cons: Inflexible. It's very inconvenient for desktop users who need to frequently switch Wi-Fi networks, use VPNs, or connect to Bluetooth networks by manually editing a file each time.
    • Use case: Servers, or devices with a fixed network environment.
  • NetworkManager

    • Role: A modern, dynamic, and powerful network management service.
    • How it works: It's a service that runs continuously in the background, automatically detecting network hardware, managing wired and wireless connections, handling VPNs, and providing graphical configuration interfaces (like the network icon in the system tray, nmtui, nm-connection-editor).
    • Pros: Extremely convenient and powerful. It easily handles complex desktop networking needs, such as saving multiple Wi-Fi passwords, automatically switching between networks, and graphical configuration.
    • Cons: It's a relatively "heavy" service for a minimal server environment.
    • Use case: All desktop and laptop users.

Which one should I use?

  • If you installed a Debian desktop edition (GNOME, KDE, Xfce, etc.), use NetworkManager. This is the default configuration method, and all the graphical network tools you see are its frontends. In this case, your /etc/network/interfaces file should be very simple, possibly only containing source /etc/network/interfaces.d/* and a loopback (lo) interface configuration. Do not manually edit it to configure your main network card.
  • If you installed a Debian server without a GUI, it's recommended to use /etc/network/interfaces. It's more lightweight and direct.

How do I know which one is managing my network? By default, if the NetworkManager service is running, it will take control of all devices not explicitly configured in /etc/network/interfaces. You can check its status with sudo systemctl status NetworkManager.

ping fails but I can browse the internet. What's the problem? How to troubleshoot DNS issues?

This is a classic network problem that almost always points to a DNS (Domain Name System) resolution failure.

Problem Analysis:

  • You can browse the internet (e.g., you can open a page by directly visiting an IP address like 114.114.114.114 in your browser). This proves that the IP routing from your device to the internet is working. The physical connection, IP address, and gateway are all fine.
  • ping fails (e.g., ping www.baidu.com shows Name or service not known or Temporary failure in name resolution). This proves that your system cannot convert the domain name www.baidu.com into its corresponding IP address.

DNS acts like the internet's phone book, responsible for translating easy-to-remember domain names into machine-readable IP addresses.

DNS Troubleshooting Steps:

  1. Confirm the problem:

    • Try to ping a domain name: ping www.debian.org (likely to fail).
    • Try to ping a public IP address: ping 8.8.8.8 (Google's DNS server).
    • If the former fails and the latter succeeds, it is 100% a DNS issue.
  2. Check the current DNS configuration:

    • The DNS server addresses are stored in the /etc/resolv.conf file.
    • cat /etc/resolv.conf
    • Look at the nameserver entries inside. If this file is empty, or if the IP address inside is an inaccessible internal address (like 127.0.0.53, which is the local stub for systemd-resolved), then the DNS configuration is incorrect.
    • Note: This file is usually generated automatically by NetworkManager or the resolvconf program. It is not recommended to edit it manually, as your changes will be lost after a network restart.
  3. Temporary solution (for testing):

    • Manually edit /etc/resolv.conf to add a reliable public DNS.
    bash
    # First, back it up
    sudo cp /etc/resolv.conf /etc/resolv.conf.bak
    # Edit the file
    sudo nano /etc/resolv.conf
    • Delete all content and add:
    nameserver 8.8.8.8
    nameserver 1.1.1.1
  4. Permanent Solution:

    • For Desktop (NetworkManager):
      • Open your network settings through the graphical interface.
      • Go to your active connection's settings (wired or Wi-Fi).
      • In the "IPv4" tab, switch "Method" from "Automatic (DHCP)" to "Automatic (DHCP), addresses only".
      • In the "DNS" field that appears, enter your desired DNS servers, separated by commas (e.g., 8.8.8.8, 1.1.1.1).
      • Save and reconnect. NetworkManager will now write these DNS servers to /etc/resolv.conf.
    • For Server (/etc/network/interfaces):
      • Add a dns-nameservers line to your static IP configuration as shown in the static IP section above.