Skip to main content

Configuring Network Interfaces

1. Viewing Network Interfaces

Command Description Example Output
ip addr show Display all network interfaces and their IP addresses
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP
    inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
ifconfig Display network interface configuration (legacy tool)
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
        inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
        ether 00:1a:2b:3c:4d:5e
ip link show List all network interfaces (without IP info)
1: lo<LOOPBACK>
2: eth0<BROADCAST,MULTICAST,UP,LOWER_UP>

Example: Displaying interface details with ip

ip addr show eth0
Note: The ip command is preferred over ifconfig in modern systems.

2. Configuring IP Addresses

Method Description Command Notes
ifconfig Configure network interfaces (legacy) ifconfig eth0 192.168.1.100 netmask 255.255.255.0 Deprecated in favor of ip command
ip addr Manage IP addresses using ip command ip addr add 192.168.1.100/24 dev eth0 Modern and preferred method
nmcli NetworkManager CLI tool nmcli dev ip4 addr add 192.168.1.100/24 dev eth0 Used in GUI environments like GNOME

Example: Assigning Static IP Address Using ip Command

ip addr add 192.168.1.100/24 dev eth0
ip link set eth0 up

Example: Viewing Assigned IP Addresses

ip addr show eth0
Note: The /24 notation represents the subnet mask in CIDR format (255.255.255.0).

3. Enabling and Disabling Interfaces

Command Description Example
ip link set Enable or disable network interfaces using the ip command.
ip link set eth0 up
ip link set eth0 down
ifconfig Deprecated but still used; enables/disables interfaces via ifconfig.
ifconfig eth0 up
ifconfig eth0 down
Note: The ip command is preferred over ifconfig in modern systems.

Example: Enabling an Interface

ip link set wlan0 up

Example: Disabling an Interface

ip link set wlan0 down

4. Viewing Routing Table

Command Description Example
ip route Display the routing table using ip command ip route
route -n Display routing table in numeric format (no DNS resolution) route -n
netstat -rn Display routing table using netstat (legacy) netstat -rn

Example: Displaying routing table with ip route

ip route show
default via 192.168.1.1 dev enp3s0 proto dhcp metric 100 
192.168.1.0/24 dev enp3s0 proto kernel scope link src 192.168.1.100 metric 100 
192.168.1.1 dev enp3s0 proto dhcp scope link src 192.168.1.100 metric 100
Note: The ip route command is preferred over route and netstat as it's more modern and feature-rich.

5. Adding Static Routes

Route Property Value Description
Destination 192.168.1.0/24 Network address to route packets to
Gateway 10.0.0.1 IP address of the next hop router
Interface eth0 Network interface to use for routing

Example: Adding a Static Route Using ip Command

ip route add 192.168.1.0/24 via 10.0.0.1 dev eth0

Example: Adding a Static Route Using route Command

route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.0.1
Note: The ip command is preferred over the deprecated route command in modern Linux systems.
Warning: Ensure the gateway IP is reachable before adding a static route to avoid network connectivity issues.

6. Deleting Routes

Command Description Example
ip route del Remove a specific route from the routing table ip route del 192.168.1.0/24 via 10.0.0.1
route del Legacy command to delete a route (deprecated in favor of ip) route del -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.0.1

Example: Delete a specific route using ip command

ip route del 192.168.1.0/24 via 10.0.0.1
Note: Ensure the route exists before deletion to avoid errors.
Warning: Deleting routes can disrupt network connectivity if not done carefully.

7. Setting Default Gateway

Method Description Command Notes
ip route Set default gateway using ip command ip route add default via 192.168.1.1 dev eth0 Temporary change; persists until reboot
nmcli Using NetworkManager CLI nmcli dev route add default 192.168.1.1 dev eth0 Works with NetworkManager-managed interfaces
systemd-networkd Using systemd-networkd configuration
[Match]
Name=eth0

[Network]
DHCP=ipv4
Gateway=192.168.1.1
Requires systemd-networkd service
/etc/network/interfaces Traditional Debian/Ubuntu approach
auto eth0
iface eth0 inet dhcp

post-up route add default gw 192.168.1.1
Legacy but still supported on some systems

Example: Using ip command to set default gateway

ip route add default via 192.168.1.1 dev eth0
Note: Ensure the gateway IP is reachable and the interface exists before setting it.
Warning: Setting the default gateway incorrectly can result in network connectivity loss.

8. Configuring DNS Servers

Configuration File Content Notes
/etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
Primary and secondary DNS servers

Example: Setting DNS Servers via /etc/resolv.conf

echo "nameserver 1.1.1.1" &gt; /etc/resolv.conf
echo "nameserver 1.0.0.1" &gt;&gt; /etc/resolv.conf
Note: Changes to /etc/resolv.conf may be overwritten by network managers like systemd-networkd or NetworkManager.
Warning: Ensure DNS servers are accessible and do not block local network traffic.
Tool Command Description
systemd-resolve systemd-resolve --status Display DNS resolution status and configuration
nmcli nmcli dev show Show network interface details including DNS settings

9. Testing Network Connectivity

Command Description Example
ping Tests connectivity to a host by sending ICMP echo requests ping google.com
ping -c 4 Sends exactly 4 ICMP packets ping -c 4 8.8.8.8
ping -W 5 Waits up to 5 seconds for a response before timing out ping -W 5 example.com

Example: Check if a server is reachable

ping -c 1 192.168.1.1
Note: ping uses ICMP protocol, which might be blocked by firewalls.
Tool Use Case Description
traceroute Shows the path packets take to reach a destination traceroute google.com
mtr Combines ping and traceroute with real-time statistics mtr google.com

Example: Diagnose network path issues

traceroute -m 10 example.com

Network Connectivity Testing Summary

  • ping: Basic connectivity check using ICMP
  • traceroute: Identifies network hops and latency
  • mtr: Real-time monitoring of packet loss and latency

10. Viewing Network Statistics

Command Description Example Output
netstat Displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 192.168.1.10:ssh        10.0.0.5:54321          ESTABLISHED
udp        0      0 0.0.0.0:5353            0.0.0.0:*               LISTEN
ss Socket statistics, faster alternative to netstat
State      Recv-Q Send-Q Local Address:Port           Peer Address:Port
ESTAB      0      0      192.168.1.10:ssh           10.0.0.5:54321
UNCONN     0      0      0.0.0.0:5353                0.0.0.0:*
ifconfig Displays and configures network interface parameters
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
        inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe4a:1b3d%eth0 prefixlen 64 scopeid 0x20
        ether 00:0c:29:4a:1b:3d
ip addr show Displays IP address information for all network interfaces
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP
    inet 192.168.1.10/24 brd 192.168.1.255 scope global eth0

Example: Monitor Network Traffic

watch -n 1 'ss -tuln'

Example: Show Interface Statistics

ifconfig eth0
Note: The ss command is preferred over netstat for better performance on modern systems.

11. Managing Network with NetworkManager

Property Value Description
connection.id my-connection Unique identifier for the connection
connection.type ethernet Type of connection (e.g., ethernet, wifi)
connection.autoconnect true Whether to autoconnect on boot
ipv4.method auto IPv4 configuration method (auto, manual, disabled)
ipv4.addresses 192.168.1.100/24 Static IPv4 address and subnet mask
ipv4.gateway 192.168.1.1 Default gateway for IPv4
ipv4.dns 8.8.8.8 DNS server address

Example: Configure a new Ethernet Connection

nmcli con add type ethernet ifname eth0 con-name "my-ethernet"
nmcli con modify "my-ethernet" ipv4.addresses 192.168.1.100/24
nmcli con modify "my-ethernet" ipv4.gateway 192.168.1.1
nmcli con modify "my-ethernet" ipv4.dns 8.8.8.8
nmcli con up "my-ethernet"

Example: List All Active Connections

nmcli con show --active
Note: NetworkManager must be running to manage network interfaces. Use systemctl status NetworkManager to check its status.
Warning: Modifying network settings via nmcli may disconnect the system if not configured properly. Always ensure backup access (e.g., console or serial) is available.

12. Configuring Network Bonds

Property Value Description
bond.mode balance-rr Bonding mode; options include balance-rr, active-backup, balance-xor, etc.
bond.miimon 100 Link monitoring interval in milliseconds (default 100)
bond.primary eth0 Primary slave interface (used in active-backup mode)

Example: Creating a Bond Interface

sudo ip link add bond0 type bond mode balance-rr miimon 100
sudo ip link set eth0 master bond0
sudo ip link set eth1 master bond0
sudo ip link set bond0 up

Example: Bond Configuration in /etc/network/interfaces

auto bond0
iface bond0 inet static
    bond-slaves eth0 eth1
    bond-mode balance-rr
    bond-miimon 100
    address 192.168.1.100
    netmask 255.255.255.0
Note: Bonding requires the bonding kernel module to be loaded.
Warning: Ensure all slave interfaces are on the same switch or network segment for optimal performance.

Was this article helpful?