Debian Network Configuration
Basic network configuration for Debian systems
Section titled “Basic network configuration for Debian systems”0. Specs
Section titled “0. Specs”0.0. The What
Section titled “0.0. The What”Network configuration examples for Debian 12 and 13.
Tried to be as thorough as possible: single NIC, multiple NICs, multiple networks, NIC bonding.
Debian and Ubuntu network configurations are very different, so there are separate tutorials for Debian and Ubuntu.
0.1. Configuration Files
Section titled “0.1. Configuration Files”Debian 12 & 13 use ifupdown for network configuration.
The main configuration file is /etc/network/interfaces. This file includes all files in the /etc/network/interfaces.d/ directory.
It is good practice to keep /etc/network/interfaces as shown below and create a separate configuration file for each NIC in the /etc/network/interfaces.d/ directory.
sudo nano /etc/network/interfaces# This file describes the network interfaces available on your system# and how to activate them. For more information, see interfaces(5).source /etc/network/interfaces.d/*## The loopback network interfaceauto loiface lo inet loopback0.2. Name Server Configuration
Section titled “0.2. Name Server Configuration”The name server configuration file is /etc/resolv.conf. It can be as simple as:
nameserver 192.168.1.1Or it may have more detailed configuration:
# Primary DNS servernameserver 8.8.8.8# Secondary DNS servernameserver 8.8.4.4# Tertiary DNS server (optional)#nameserver 1.1.1.1# Search domains (optional)# If a domain name is provided without a fully qualified domain name (FQDN),# the system appends these search domains to the provided domain to perform# DNS lookups.# For example, if "example.com" is provided in a lookup, and "search# localdomain" is configured, the system will also try to resolve# example.com.localdomain".search localdomain0.3. Configuration Commands
Section titled “0.3. Configuration Commands”Stop a NIC:
sudo ifdown enp0s3Start a NIC:
sudo ifup enp0s3To restart a NIC, stop it and start it again:
sudo ifdown enp0s3 && sudo ifup enp0s3Restart networking (restarts all NICs and other networking services):
sudo systemctl restart networking0.4. Sources
Section titled “0.4. Sources”1. Example Configurations
Section titled “1. Example Configurations”1.1. DHCP Configuration
Section titled “1.1. DHCP Configuration”Our NIC is enp0s3.
sudo nano /etc/network/interfaces.d/enp0s3Fill as below:
auto enp0s3iface enp0s3 inet dhcpRestart networking:
sudo systemctl restart networking1.2. Static IP Configuration
Section titled “1.2. Static IP Configuration”Our NIC is enp0s3.
sudo nano /etc/network/interfaces.d/enp0s3Fill as below:
auto enp0s3iface enp0s3 inet static address 192.168.1.135/24 broadcast 192.168.1.255 network 192.168.1.0 gateway 192.168.1.1sudo systemctl restart networking1.3. Static IP Configuration with 2 IPs
Section titled “1.3. Static IP Configuration with 2 IPs”Our NIC is enp0s3.
sudo nano /etc/network/interfaces.d/enp0s3Fill as below:
auto enp0s3iface enp0s3 inet static address 192.168.1.196/24 broadcast 192.168.1.255 network 192.168.1.0 gateway 192.168.1.1iface enp0s3 inet static address 10.1.1.1/8sudo systemctl restart networking1.4. Static IP Configuration with 2 NICs
Section titled “1.4. Static IP Configuration with 2 NICs”Our NICs are enp0s3 and enp0s8.
First NIC:
sudo nano /etc/network/interfaces.d/enp0s3Fill as below:
auto enp0s3iface enp0s3 inet static address 192.168.1.196/24 broadcast 192.168.1.255 network 192.168.1.0 gateway 192.168.1.1Second NIC:
sudo nano /etc/network/interfaces.d/enp0s8Fill as below:
auto enp0s8iface enp0s8 inet static address 10.1.1.1/8 broadcast 10.255.255.255 network 10.0.0.0Restart networking:
sudo systemctl restart networking2. Case Study - Multiple Networks
Section titled “2. Case Study - Multiple Networks”2.0. Specs
Section titled “2.0. Specs”We have 2 separate networks (192.168.1.X and 10.X.X.X). Some hosts from one network need to reach hosts in the other network.
We will install a new host to act as a router between the networks.
The host will have 2 NICs (one in each network), and we’ll enable IP routing on it.
This way, hosts in one network will be able to reach hosts in the other network. This will be possible by defining IP routes on the hosts to use the server with 2 NICs as a router to the other network.
Hosts in the 192.168.1.X network use 192.168.1.1 as the default gateway; hosts in the 10.X.X.X network use 10.1.1.1 as the default gateway.
Our router will have 2 NICs: one with IP 192.168.1.196 and the other with IP 10.1.1.196.
Hosts in the 192.168.1.X network will use 192.168.1.196 to reach the 10.X.X.X network. Hosts in the 10.X.X.X network will use 10.1.1.196 to reach the 192.168.1.X network.
We will configure:
- The router (192.168.1.196 & 10.1.1.196)
- The host in the first network (192.168.1.197)
- The host in the second network (10.1.1.198)
Then we’ll check connectivity between them.
2.1. Configuration of the Router
Section titled “2.1. Configuration of the Router”We have 2 NICs (enp0s3 - 192.168.1.X network, and enp0s8 -10.X.X.X network).
Clean the /etc/network/interfaces file:
sudo nano /etc/network/interfacesSet as below:
source /etc/network/interfaces.d/*auto loiface lo inet loopbackConfigure NICs:
enp0s3 (192.168.1.196/24):
sudo nano /etc/network/interfaces.d/enp0s3Fill as below:
auto enp0s3iface enp0s3 inet static address 192.168.1.196/24 broadcast 192.168.1.255 network 192.168.1.0 gateway 192.168.1.1enp0s8 (10.1.1.196/8):
sudo nano /etc/network/interfaces.d/enp0s8Fill as below:
auto enp0s8iface enp0s8 inet static address 10.1.1.196/8 broadcast 10.255.255.255 network 10.0.0.0Restart networking (your SSH connection may break; reconnect if needed):
sudo systemctl restart networkingEnable IP Forwarding:
sudo nano /etc/sysctl.confAdd the following line to the end:
net.ipv4.ip_forward = 1Activate:
sudo sysctl -pSet name server (if not already configured):
sudo nano /etc/resolv.confnameserver 8.8.8.8nameserver 8.8.4.42.2. Configuration of the First Host
Section titled “2.2. Configuration of the First Host”We have 1 NIC (enp0s3 - 192.168.1.X network).
Clear the /etc/network/interfaces file:
sudo nano /etc/network/interfacesSet as below:
source /etc/network/interfaces.d/*auto loiface lo inet loopbackConfigure NIC:
enp0s3 (192.168.1.197/24):
sudo nano /etc/network/interfaces.d/enp0s3auto enp0s3iface enp0s3 inet static address 192.168.1.197/24 broadcast 192.168.1.255 network 192.168.1.0 gateway 192.168.1.1Define route:
Create a script file to add the route when the interface comes up:
sudo nano /etc/network/if-up.d/routesFill as below:
#!/bin/shif [ "$IFACE" = "enp0s3" ]; then ip route del 10.0.0.0/8 via 192.168.1.196 dev enp0s3 ip route add 10.0.0.0/8 via 192.168.1.196 dev enp0s3fiMake the script executable:
sudo chmod 750 /etc/network/if-up.d/routesRestart networking (your SSH connection may break; reconnect if needed):
sudo systemctl restart networkingSet name server (if not already configured):
sudo nano /etc/resolv.confnameserver 8.8.8.8nameserver 8.8.4.42.3. Configuration of the Second Host
Section titled “2.3. Configuration of the Second Host”We have 1 NIC (enp0s3 - 10.X.X.X network).
Clear the /etc/network/interfaces file:
sudo nano /etc/network/interfacesSet as below:
source /etc/network/interfaces.d/*auto loiface lo inet loopbackConfigure NIC:
enp0s3 (10.1.1.198/8):
sudo nano /etc/network/interfaces.d/enp0s3auto enp0s3iface enp0s3 inet static address 10.1.1.198/8 broadcast 10.255.255.255 network 10.0.0.0 gateway 10.1.1.1Define route:
Create a script file to add the route when the interface comes up:
sudo nano /etc/network/if-up.d/routesFill as below:
#!/bin/shif [ "$IFACE" = "enp0s3" ]; then ip route del 192.168.1.0/24 via 10.1.1.196 dev enp0s3 ip route add 192.168.1.0/24 via 10.1.1.196 dev enp0s3fiMake the script executable:
sudo chmod 750 /etc/network/if-up.d/routesRestart networking (your SSH connection may break; reconnect if needed):
sudo systemctl restart networkingSet name servers (if not already configured):
sudo nano /etc/resolv.confnameserver 8.8.8.8nameserver 8.8.4.42.4. Notes
Section titled “2.4. Notes”The host in the first network can ping the host in the other network now, and vice versa.
Try on the first host (192.168.1.197)
ping 10.1.1.198Try on the second host (10.1.1.198)
ping 192.168.1.197For a host to connect to another host on the other network, routing must be defined on both hosts.
3. NIC Bonding
Section titled “3. NIC Bonding”Network Interface Card (NIC) bonding involves using two or more NICs together to achieve redundancy and/or increased throughput.
The most commonly used bonding modes are:
-
Active Backup: Also known as failover mode. In this mode, one interface is active while the other interfaces remain in standby mode. If the active interface fails, one of the standby interfaces takes over. It provides redundancy but does not offer load balancing.
-
Balance-rr (Round-Robin): Packets are transmitted sequentially across the bonded interfaces in a round-robin fashion. This provides load balancing and increased throughput, but does not provide fault tolerance.
-
Balance-xor: Combines the MAC addresses of the interfaces and applies an XOR operation to determine the outgoing interface. It provides load balancing and fault tolerance, but requires switch support for optimal performance.
-
Broadcast: All packets are sent on all interfaces. This mode is typically used when the switch does not support other bonding modes. It provides fault tolerance but not load balancing.
All examples below use 2 NICs (enp0s3 and enp0s8) on the same network (192.168.1.X).
3.0. Preliminary Steps
Section titled “3.0. Preliminary Steps”Before configuring bonding of any type, there are some necessary preliminary steps.
To use NIC bonding, the ifenslave package must be installed:
sudo apt updatesudo apt -y install ifenslaveEnsure the bonding kernel module is loaded:
sudo modprobe bondingEnsure the kernel module loads at startup:
sudo nano /etc/modulesAdd to the end of the file (if it doesn’t already exist):
bondingClear the /etc/network/interfaces file:
sudo nano /etc/network/interfacesSet as below:
source /etc/network/interfaces.d/*auto loiface lo inet loopbackSet Name Servers (if not already)
sudo nano /etc/resolv.confnameserver 8.8.8.8nameserver 8.8.4.43.1. Active Backup Bonding
Section titled “3.1. Active Backup Bonding”Configure the bond:
sudo nano /etc/network/interfaces.d/bondFill as below:
auto enp0s3iface enp0s3 inet manual bond-master bond0
auto enp0s8iface enp0s8 inet manual bond-master bond0
auto bond0iface bond0 inet static address 192.168.1.196/24 netmask 255.255.255.0 network 192.168.1.0 gateway 192.168.1.1 slaves enp0s3 enp0s8 bond-mode active-backup bond-primary enp0s3Restart Networking:
sudo systemctl restart networkingCheck the status of the bond
sudo cat /proc/net/bonding/bond03.2. Balance-RR Bonding
Section titled “3.2. Balance-RR Bonding”Configure the bond
sudo nano /etc/network/interfaces.d/bondauto enp0s3iface enp0s3 inet manual bond-master bond0
auto enp0s8iface enp0s8 inet manual bond-master bond0
auto bond0iface bond0 inet static address 192.168.1.196/24 netmask 255.255.255.0 network 192.168.1.0 gateway 192.168.1.1 bond-slaves enp0s3 enp0s8 bond-mode balance-rrRestart networking:
sudo systemctl restart networkingCheck the status of the bond:
sudo cat /proc/net/bonding/bond03.3. Balance-XOR Bonding
Section titled “3.3. Balance-XOR Bonding”Configure the bond
sudo nano /etc/network/interfaces.d/bondauto enp0s3iface enp0s3 inet manual bond-master bond0
auto enp0s8iface enp0s8 inet manual bond-master bond0
auto bond0iface bond0 inet static address 192.168.1.196/24 netmask 255.255.255.0 network 192.168.1.0 gateway 192.168.1.1 bond-slaves enp0s3 enp0s8 bond-mode balance-xorRestart networking:
sudo systemctl restart networkingCheck the status of the bond:
sudo cat /proc/net/bonding/bond03.4. Broadcast Bonding
Section titled “3.4. Broadcast Bonding”Configure the bond:
sudo nano /etc/network/interfaces.d/bondauto enp0s3iface enp0s3 inet manual bond-master bond0
auto enp0s8iface enp0s8 inet manual bond-master bond0
auto bond0iface bond0 inet static address 192.168.1.196/24 netmask 255.255.255.0 network 192.168.1.0 gateway 192.168.1.1 bond-slaves enp0s3 enp0s8 bond-mode broadcastRestart networking:
sudo systemctl restart networkingCheck the status of the bond:
sudo cat /proc/net/bonding/bond0