Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Networking Basics in Linux

1. Introduction

Networking is a core component of Linux system administration. Understanding how to configure and manage network settings is essential for ensuring connectivity and security.

2. Network Interfaces

In Linux, network interfaces can be physical (like network cards) or virtual (like loopback). Each interface is represented as a file in the /sys/class/net/ directory.

Common Commands

  • ip link show - Displays all network interfaces and their status.
  • ifconfig - Legacy command to configure network interfaces.
  • ip addr show - Shows IP addresses assigned to interfaces.

3. IP Configuration

IP configuration can be done statically or dynamically. Static configuration is done manually, while dynamic configuration typically uses DHCP.

Static IP Configuration Example

sudo nano /etc/network/interfaces
# Example static configuration
auto eth0
iface eth0 inet static
    address 192.168.1.10
    netmask 255.255.255.0
    gateway 192.168.1.1

Dynamic IP Configuration with DHCP

sudo nano /etc/network/interfaces
# Example DHCP configuration
auto eth0
iface eth0 inet dhcp

4. Networking Tools

Linux offers various tools for diagnosing network issues.

Common Networking Tools

  • ping - Tests connectivity to a host.
  • traceroute - Displays the route packets take to a network host.
  • netstat - Shows network connections, routing tables, and interface statistics.
  • nslookup - Queries DNS to obtain domain name or IP address mapping.

5. Firewall Configuration

Firewall settings are essential for securing your network. Common tools include iptables and ufw.

Basic UFW Commands

sudo ufw enable      # Enable the firewall
sudo ufw allow ssh    # Allow SSH connections
sudo ufw deny 80      # Deny HTTP connections
sudo ufw status       # Check the status of the firewall

6. FAQ

What is a network interface?

A network interface is a point of interconnection between a computer and a private or public network.

How do I check my current IP address?

You can check your current IP address using ip addr show or ifconfig.

What is the difference between static and dynamic IP?

A static IP is a fixed address manually assigned to a device, while a dynamic IP is assigned by a DHCP server and can change over time.