Skip to content

Networking

PotatoScript edited this page Mar 30, 2025 · 1 revision

Networking in Linux

🌟 1. Introduction to Networking in Linux

Networking in Linux allows you to connect to the internet, share files, manage remote servers, and perform a wide range of communication tasks. Think of it as the "communication highway" of your computer, where data travels back and forth to connect with other devices. In Linux, there are several tools and commands to help you manage and troubleshoot your network connections.


πŸ› οΈ Why Is Networking Important?

Networking in Linux allows you to:

  • Connect to the internet for browsing, downloading, and uploading files.
  • Share files between computers in a network.
  • Manage servers remotely, such as through SSH.
  • Troubleshoot network issues to ensure smooth connectivity.

πŸ–§ 2. Basic Networking Concepts

πŸ“š What is an IP Address?

An IP (Internet Protocol) address is a unique address assigned to your computer or device on a network. It’s like your home address on the internet, making sure that data sent to you arrives at the right place.

There are two types of IP addresses:

  • IPv4: Most common format, looks like 192.168.1.1.
  • IPv6: Newer format, looks like 2001:0db8:85a3:0000:0000:8a2e:0370:7334.

πŸ“š What is a Subnet Mask?

A subnet mask is used to divide an IP address into network and host parts. It helps devices understand whether another device is on the same local network or if the data should be sent to a router for further routing.


πŸ“š What is DNS (Domain Name System)?

DNS helps translate human-friendly domain names (like www.google.com) into IP addresses that computers can understand. It’s like a phonebook for the internet, connecting names to numbers.


πŸ› οΈ 3. Networking Tools and Commands in Linux

Linux offers a wide range of networking commands that allow you to view and configure network settings.


πŸ“š Checking Network Configuration: ifconfig

The ifconfig command is used to display or configure the network interfaces on your system.

To view the current network configuration:

ifconfig

This will display a list of network interfaces, their IP addresses, and other information.


πŸ“š Checking Network Configuration: ip

The ip command is more modern and powerful than ifconfig. It’s used to show and configure network settings.

To show all network interfaces and their configurations:

ip addr

To view the status of a specific interface (like eth0):

ip addr show eth0

πŸ“š Viewing Routing Information: route

The route command is used to display or modify the routing table of your Linux system. The routing table is like a map that determines how data is forwarded to its destination.

To view the routing table:

route -n

πŸ“š Viewing Network Connections: netstat

The netstat command is used to display information about active network connections, routing tables, and interface statistics.

To see active network connections:

netstat -tuln
  • -t shows TCP connections.
  • -u shows UDP connections.
  • -l shows only listening ports.
  • -n shows numerical addresses instead of resolving domain names.

πŸ“š Testing Network Connectivity: ping

The ping command is used to test the network connection between your machine and another device on the network or the internet. It sends a small packet of data and waits for a reply, showing the round-trip time.

To ping a website:

ping www.google.com

To stop the ping command, press Ctrl + C.


πŸ“š Testing Network Speed: speedtest-cli

To test your internet speed from the terminal, you can use the speedtest-cli tool.

First, install it using:

sudo apt-get install speedtest-cli

To run the speed test:

speedtest-cli

This will display the download and upload speeds of your internet connection.


πŸ“š Checking Open Ports: ss

The ss command is used to investigate socket connections on your system, like checking which ports are open and being used by applications.

To list all open ports:

ss -tuln

This shows active sockets and their listening ports.


🌐 4. Managing Network Interfaces

Your Linux system can have multiple network interfaces, such as wired Ethernet (eth0), Wi-Fi (wlan0), or virtual network interfaces. You can manage these interfaces with tools like ifconfig, ip, or the more advanced nmcli for NetworkManager.


πŸ“š Bringing a Network Interface Up or Down

To bring a network interface up (enable):

sudo ifconfig eth0 up

To bring it down (disable):

sudo ifconfig eth0 down

Using ip:

To bring up an interface:

sudo ip link set eth0 up

To bring it down:

sudo ip link set eth0 down

πŸ“š Assigning an IP Address to a Network Interface

To assign a static IP address to an interface (e.g., eth0), use the following command:

sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up

Using ip:

sudo ip addr add 192.168.1.100/24 dev eth0

πŸ”„ 5. Configuring DNS Settings

DNS settings are configured through a file called /etc/resolv.conf. To set a DNS server, edit the file using your preferred text editor.

For example, to use Google’s public DNS:

sudo nano /etc/resolv.conf

Add the following line:

nameserver 8.8.8.8

Save the file and exit.


πŸ”’ 6. Network Security in Linux

Ensuring that your network is secure is very important. You can use tools like firewalls to control incoming and outgoing traffic.

πŸ“š Using ufw for Simple Firewall Management

ufw (Uncomplicated Firewall) is an easy-to-use front-end for iptables that simplifies firewall configuration.

To enable ufw:

sudo ufw enable

To check the status of ufw:

sudo ufw status

To allow a service (e.g., HTTP):

sudo ufw allow http

To block a service:

sudo ufw deny http

πŸ§‘β€πŸ’» 7. Managing Remote Connections

πŸ“š Using SSH for Remote Access

SSH (Secure Shell) is used to connect to a remote system securely over the network.

To connect to a remote system:

ssh username@remote_host

Example:

ssh lucy@192.168.1.10

Clone this wiki locally