How to Configure Network Settings on Linux — A Clear, Step‑by‑Step Guide

How to Configure Network Settings on Linux — A Clear, Step‑by‑Step Guide

Get confident managing Linux network configuration with this friendly, step‑by‑step guide that demystifies interfaces, routing, DNS, and advanced features like bonding and VLANs. Whether youre prepping a VPS or troubleshooting connectivity, youll learn practical commands and best practices to make changes reliably and persist across reboots.

Configuring network settings on Linux is a routine yet critical task for web hosts, developers, and system administrators. Whether you’re preparing a VPS for production, setting up a development environment, or troubleshooting connectivity issues, understanding how Linux networking components work and how to configure them deterministically is essential. This article walks you through the core concepts, practical commands, configuration files, and best practices so you can confidently manage network interfaces, routing, DNS, and advanced features like bonding, bridging, and VLANs.

Introduction to Linux Networking Principles

At a high level, Linux networking is built around a few core abstractions: network interfaces (physical and virtual), IP addressing, routing tables, and packet filtering. The Linux kernel exposes networking functionality through the netlink interface, which user-space tools manipulate. Common user-space tools include ip (from iproute2), ifconfig (deprecated but still in use), NetworkManager, systemd-networkd, and distribution-specific utilities like netplan or /etc/network/interfaces on Debian/Ubuntu.

Key concepts to understand:

  • Interfaces: Identified like eth0, ens3, eno1, or virtual names such as lo, br0, bond0, and veth pairs.
  • IP addressing: IPv4 (e.g., 192.0.2.10/24) and IPv6 (e.g., 2001:db8::1/64) addresses assigned per interface.
  • Routing: The kernel routing table determines next-hop behavior; use ip route show to inspect.
  • DNS: Name resolution is handled by /etc/resolv.conf or systemd-resolved; DNS affects outgoing name lookups only.
  • Firewalling: iptables or nftables control packet filtering and NAT.

Common Configuration Tools and When to Use Them

ip (iproute2)

The modern Swiss army knife for network configuration. Use ip to add addresses, routes, and configure advanced settings:

  • Assign IP: ip addr add 192.0.2.10/24 dev ens3
  • Bring interface up: ip link set ens3 up
  • Show routes: ip route show
  • Add route: ip route add default via 192.0.2.1 dev ens3

Note: Changes with ip are ephemeral by default; to persist them across reboots, edit appropriate configuration files or use a network manager.

ifconfig

Legacy tool from net-tools. Some older scripts and environments still use ifconfig. Replaceable by ip; avoid if possible for new automation.

NetworkManager

Provides both CLI (nmcli) and GUI controls and is common on desktop and many server distributions. Best when you need dynamic management, Wi-Fi, VPNs, and per-user control.

systemd-networkd and netplan

systemd-networkd is a lightweight, fast manager for servers. Ubuntu now often uses netplan as a declarative front-end that generates systemd-networkd or NetworkManager configs. Use systemd-networkd for minimal, reproducible server setups.

/etc/network/interfaces

Debian/Ubuntu classic configuration file. Still widely used on servers. Example snippet for static IPv4:

  • auto ens3
  • iface ens3 inet static
  • address 192.0.2.10
  • netmask 255.255.255.0
  • gateway 192.0.2.1

Step-by-Step: Configuring a Static IPv4 Address

This section provides a practical approach that works across distributions. Replace interface names and IPs with your actual values.

1) Check current interface state

Use: ip link show and ip addr show. Confirm the interface name (for example, ens3) and whether a DHCP lease exists.

2) Temporarily set an IP to test connectivity

Command: ip addr add 192.0.2.10/24 dev ens3 then ip link set ens3 up. Add a temporary default route: ip route add default via 192.0.2.1 dev ens3.

3) Verify connectivity

Use ping 8.8.8.8 for basic IP connectivity and ping google.com to test DNS resolution. Inspect route with ip route and DNS servers with cat /etc/resolv.conf.

4) Persist the configuration

On Debian/Ubuntu using /etc/network/interfaces, add:

  • auto ens3
  • iface ens3 inet static
  • address 192.0.2.10
  • netmask 255.255.255.0
  • gateway 192.0.2.1
  • dns-nameservers 8.8.8.8 8.8.4.4

On systems using netplan (YAML files in /etc/netplan), a minimal config looks like:

  • network:
  • version: 2
  • renderer: networkd
  • ethernets:
  • ens3:
  • addresses: [192.0.2.10/24]
  • gateway4: 192.0.2.1
  • nameservers:
  • addresses: [8.8.8.8,8.8.4.4]

Apply with sudo netplan apply.

IPv6, Dual-Stack, and DHCP

IPv6 addresses can be configured similarly: ip -6 addr add 2001:db8::10/64 dev ens3. Most VPS providers support DHCPv6 or SLAAC. For DHCP (IPv4 or IPv6), ensure your network manager is set to acquire addresses automatically — for NetworkManager use nmcli con modify or for systemd-networkd include DHCP=yes in the .network file.

Advanced Topics: Routing, Policy Routing, and Multiple NICs

Multiple default routes and policy routing

When using multiple NICs or connections to different ISPs, use ip rule and ip route show table X to create policy routing. Example:

  • ip route add default via 192.0.2.1 dev ens3 table 100
  • ip rule add from 192.0.2.10/32 table 100

This ensures traffic from a specific source uses the correct gateway.

Static routes and route metrics

Add static routes with ip route add 203.0.113.0/24 via 192.0.2.254 dev ens3. Use metrics to prefer one default route over another: ip route add default via 192.0.2.1 dev ens3 metric 100 and the other with a higher metric.

Bridging, Bonding, and VLANs

These features are common in virtualization, high-availability, and multi-tenant setups.

  • Bridging (brctl or ip link add type bridge): Create br0 and add interfaces to let VMs or containers share a Layer 2 domain.
  • Bonding: Combine multiple NICs for redundancy or throughput (modes: balance-rr, active-backup, 802.3ad/LACP). Configure via /etc/modprobe.d and interface config or systemd-networkd.
  • VLANs: Create subinterfaces like ens3.100 for VLAN ID 100: ip link add link ens3 name ens3.100 type vlan id 100

Firewalling and NAT: iptables vs nftables

Linux supports both iptables (legacy) and nftables (modern replacement). For NAT and port forwarding on a server, enable IP forwarding (sysctl net.ipv4.ip_forward=1) and create appropriate rules:

  • iptables -t nat -A PREROUTING -p tcp –dport 80 -j DNAT –to-destination 192.0.2.10:80
  • nftables equivalent uses nft add rule ip nat prerouting tcp dport 80 dnat to 192.0.2.10:80

Important: Persist firewall configurations using distribution mechanisms (iptables-persistent, nftables ruleset file, or systemd unit).

Troubleshooting Checklist

  • Confirm interface is up: ip link show dev ens3
  • Show addresses: ip addr show dev ens3
  • Check routing table: ip route show
  • Verify DNS: cat /etc/resolv.conf and test with dig or nslookup
  • Check packet flow with tcpdump: sudo tcpdump -i ens3 -n
  • Inspect firewall rules: iptables -S or nft list ruleset
  • Look at system logs: journalctl -u NetworkManager or journalctl -b

Comparison: Systemd-networkd vs NetworkManager vs Traditional Files

systemd-networkd — lightweight, predictable, ideal for headless servers and automation. Better suited for static configurations and high-performance environments.

NetworkManager — flexible with many features (VPN, Wi-Fi). Good for desktops or complex dynamic setups but can be overkill on servers.

Traditional /etc/network/interfaces or distribution-specific files — explicit and simple for administrators who prefer file-based configs. Works well in controlled server environments.

Choose based on automation needs, complexity, and team familiarity. For VPS hosting where reproducibility matters, systemd-networkd or netplan + networkd often yields the most consistent results.

Best Practices and Security Considerations

  • Use static IPs for servers that provide services so DNS and routing are stable.
  • Keep DNS servers reliable and consider a local caching resolver (e.g., dnsmasq) to reduce latency.
  • Enable and configure a firewall to limit exposure — default-deny inbound and explicit allow for required ports.
  • Use secure management channels (SSH with keys, not passwords) and restrict SSH to management IPs when possible.
  • Monitor interface errors and traffic to detect duplex/MTU mismatches or abnormal traffic.
  • Document network topology and persistent configurations in a version-controlled repository.

Choosing a VPS for Network-Sensitive Workloads

When selecting a VPS, consider network performance, available network features (public IPv4/IPv6, bonding, private networking), and the provider’s support for advanced networking setups. For example, providers that offer multiple NICs, configurable VLANs, or predictable network throughput are preferable for high-availability or bandwidth-sensitive applications.

If you need a reliable, US-based VPS with flexible configuration options and predictable network performance, consider evaluating offerings like the USA VPS plans provided by VPS.DO — see the product page: https://vps.do/usa/. These services typically expose the networking primitives required for advanced setups described above while providing control panels or APIs for automation.

Summary

Linux network configuration ranges from simple static IP assignment to complex policy routing and virtual networking. Mastering the ip tool, understanding persistence via systemd-networkd or netplan, and applying solid firewall practices will make your servers more reliable and secure. For production deployments, prefer declarative and version-controlled network configurations, and select VPS providers that give you the necessary network features and performance guarantees.

For hands-on deployments, pair these techniques with a stable VPS provider that supports advanced networking. Explore options that match your requirements, such as the USA VPS offerings at https://vps.do/usa/, to get started quickly with predictable network behavior.

Fast • Reliable • Affordable VPS - DO It Now!

Get top VPS hosting with VPS.DO’s fast, low-cost plans. Try risk-free with our 7-day no-questions-asked refund and start today!