# Configure network

This process configures your server to use Netplan and systemd-resolved to manage both ethernet and Wi-Fi connections through a single, unified configuration file.

---

1.  ## Install network driver (if applicable)

    ```sh
    lspci -nnk | grep -iA 3 net
    ```

    If the network controller says **“Broadcom”** and **“BCM43xx”**, install the drivers below; otherwise, skip to step 2.

    Ensure the `non-free` repository component is enabled for your Debian release. (`deb` and `deb-src`)

            ```sh
            sudo nano /etc/apt/sources.list
            ```

            Update package lists.

            ```sh
            sudo apt update
            ```

            Check that the Broadcom driver package is available.

            ```sh
            apt-cache policy broadcom-sta-dkms
            ```

            Install the kernel headers, DKMS, NetworkManager and the Broadcom driver.

            ```sh
            sudo apt install -y linux-headers-$(uname -r) dkms network-manager && sudo apt install -y broadcom-sta-dkms
            ```

            Verification: If the output includes `wl` with a _nonzero size_, the driver module is loaded.

            ```sh
            sudo modprobe -r b44 b43 b43legacy ssb brcmsmac bcma && sudo modprobe wl && lsmod | grep wl
            ```

            Remove any wireless interfaces if they exist.

            ```sh
            sudo nano /etc/network/interfaces
            ```

            Disable Wi-Fi power saving to help prevent connection drops.

            ```sh title="/etc/NetworkManager/conf.d/default-wifi-powersave-on.conf"
            sudo nano /etc/NetworkManager/conf.d/default-wifi-powersave-on.conf
            ```

            ```sh
            [connection]
            wifi.powersave = 2
            ```

            Restart NetworkManager.

            ```sh
            sudo systemctl restart NetworkManager
            ```

            Configure the corporate Wi-Fi connection using WPA-Enterprise credentials.

            ```sh
            sudo nmcli connection add type wifi con-name corporate-wifi ssid "YourSSID" wifi-sec.key-mgmt wpa-eap 802-1x.eap peap 802-1x.identity "your_username" 802-1x.password "your_password" 802-1x.phase2-auth mschapv2
            ```

            Connect to the corporate Wi-Fi network.

            ```sh
            sudo nmcli connection up corporate-wifi
            ```

      ```sh
      sudo apt update && sudo apt install linux-headers-$(uname -r) -y && sudo apt install bcmwl-kernel-source -y
      ```

      For changes to take effect, reboot the system.

    ```sh
    sudo reboot
    ```

    Verify the driver is active by running `ip link`. A wireless interface, typically `wlan0`, should now appear in the list.

2.  ## Install and enable wpa_supplicant

    ```sh
    sudo apt install wpasupplicant -y && sudo systemctl enable --now wpa_supplicant
    ```

3.  ## Create symlink to systemd-resolved

    ```sh
    sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
    ```

4.  ## Network configuration

      ### systemd-resolved

   1. Open netplan config

                     ```sh
                     sudo nano /etc/systemd/resolved.conf.d/10-override-dns.conf
                     ```

   2.  Update config

                     ```yaml title="/etc/systemd/resolved.conf.d/10-override-dns.conf"
                     [Resolve]
                     DNS=1.1.1.1 8.8.8.8
                     FallbackDNS=1.0.0.1 8.8.4.4
                     Domains=~.
                     DNSStubListener=no
                     ```

         ### netplan

               

   1. Open netplan config

                     ```sh
                     sudo nano /etc/netplan/50-cloud-init.yaml
                     ```

   2.  Update config

                     - Replace `enp3s0` with your ethernet ID from `ip link`.
                     - Replace `wlan0` with your Wi-Fi ID from `ip link`.
                     - Replace `Your_SSID_Name` and `Your_Password` under access-points.

                     ```yaml title="/etc/netplan/50-cloud-init.yaml"
                     network:
                       version: 2
                       renderer: networkd
                       ethernets:
                         enp3s0:
                           dhcp4: true
                           # Remove if causing issues when rebooting
                           optional: true
                           dhcp4-overrides:
                             route-metric: 100
                             use-dns: false
                           nameservers:
                             addresses: [1.1.1.1, 8.8.8.8]
                       # Optional
                       wifis:
                         wlan0:
                           dhcp4: true
                           optional: true
                           dhcp4-overrides:
                             route-metric: 600
                             use-dns: false
                           nameservers:
                             addresses: [1.1.1.1, 8.8.8.8]
                           access-points:
                             "Your_SSID_Name":
                               password: "Your_Password"
                     ```

   3.  Apply the config

                     ```sh
                     sudo chown root:root /etc/netplan/50-cloud-init.yaml && sudo chmod 600 /etc/netplan/50-cloud-init.yaml
                     ```

   4.  Apply the config

                     ```sh
                     sudo netplan apply
                     ```

         

5.  ## Restart systemd-resolved

    ```sh
    sudo systemctl restart systemd-resolved
    ```

6.  ## Enable systemd-networkd-wait-online

    ```sh
    sudo systemctl enable systemd-networkd-wait-online.service
    ```

7.  ## Reboot the system

    ```sh
    sudo reboot
    ```
