Configuring Network Interfaces
1. Viewing Network Interfaces
| Command | Description | Example Output |
|---|---|---|
| ip addr show | Display all network interfaces and their IP addresses | |
| ifconfig | Display network interface configuration (legacy tool) | |
| ip link show | List all network interfaces (without IP info) | |
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
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. |
|
| ifconfig | Deprecated but still used; enables/disables interfaces via ifconfig. |
|
Note: The
ip command is preferred over ifconfig in modern systems.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 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 |
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 | |
Requires systemd-networkd service |
| /etc/network/interfaces | Traditional Debian/Ubuntu approach | |
Legacy but still supported on some systems |
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 | |
Primary and secondary DNS servers |
Example: Setting DNS Servers via /etc/resolv.conf
echo "nameserver 1.1.1.1" > /etc/resolv.conf
echo "nameserver 1.0.0.1" >> /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 |
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 |
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 | |
| ss | Socket statistics, faster alternative to netstat | |
| ifconfig | Displays and configures network interface parameters | |
| ip addr show | Displays IP address information for all network interfaces | |
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"
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.