Linux networking encompasses a broad range of network configuration tasks, including managing network interfaces, securing communications with firewalls, and ensuring privacy with Virtual Private Networks (VPNs). This page provides an overview of different networking components on Linux, including network interfaces, firewalls, and VPN types.
A Virtual Private Network (VPN) is a secure connection between your computer and a remote server, typically used for privacy and security over public networks. There are several types of VPNs available for Linux:
In Linux, a network interface represents the connection between your system and a network. The most common types of network interfaces are:
eth0, this is the standard wired network connection for desktops, servers, and workstations.wlan0 or similar and are used to connect to wireless networks (Wi-Fi).tun0 (for OpenVPN), wg0 (for WireGuard), or docker0 (for Docker containers).lo, this interface is used for internal communications within the system itself (localhost).A firewall is a crucial component in Linux networking that controls incoming and outgoing network traffic based on predefined security rules. The most common types of firewalls on Linux are:
Linux supports a wide variety of network services that are essential for communication, remote access, and managing network configurations. Common network services include:
Linux networking provides flexibility and control over how systems interact with one another. Whether you're configuring simple static IPs or setting up complex VPNs and firewalls, understanding the different types of network interfaces, services, and protocols will help you maintain secure and efficient network connections. With tools like UFW, iptables, and NetworkManager, Linux offers a variety of options for managing networking tasks at both basic and advanced levels.
iptables is the traditional user-space tool for configuring the Linux kernel's packet filtering rules. It's highly flexible and powerful, though often complex due to its verbose command-line syntax. It's suitable for administrators who want fine-grained control.
nftables is the modern replacement for iptables, offering a unified framework for both IPv4 and IPv6. It simplifies rule management, provides performance improvements, and is becoming the default firewall tool on many Linux distributions.
firewalld is a dynamic firewall manager that uses zones and services to simplify management. It supports both iptables and nftables backends and allows for changes without restarting the firewall, making it ideal for modern desktop and server environments.
UFW is a simple command-line frontend for iptables, designed to make managing a host-based firewall easy. It is the default on Ubuntu and ideal for basic rule sets and beginners who want straightforward security without complex syntax.
Shorewall, or Shoreline Firewall, is a high-level abstraction tool for iptables and nftables. It uses configuration files rather than direct CLI input, making it easier to manage complex setups such as multiple zones, interfaces, and policies.
CSF is a firewall configuration script with advanced security features, designed for web hosting servers. It integrates with control panels like cPanel and includes features such as login failure detection, IP blocking, and port scanning protection.
IPFire is a dedicated firewall distribution based on Linux. It provides an easy-to-use web interface and integrates features like intrusion detection, VPN, and traffic shaping. It's intended for both business and home users looking for a turnkey solution.
OpenWRT is a Linux-based firmware for embedded devices like routers. It provides a fully writable filesystem and a package management system, allowing users to install and configure iptables, nftables, and other tools for a highly customizable firewall environment.
# List all network interfaces
ip a
# Check Ethernet link status
ethtool eth0
# Check Wi-Fi link and scan
iw dev
iw wlan0 link
sudo iwlist wlan0 scan
# Temporary static IP (non-persistent)
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip route add default via 192.168.1.1
# Set DNS manually
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
# Install DHCP client
sudo apt install dhclient
# Obtain IP address via DHCP
sudo dhclient eth0
# Install DHCP server
sudo apt install isc-dhcp-server
# Edit config file
sudo nano /etc/dhcp/dhcpd.conf
# Example static lease config
host printer {
hardware ethernet AA:BB:CC:DD:EE:FF;
fixed-address 192.168.1.50;
}
# Set subnet config
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.1.150;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8;
}
# Enable DHCP on eth0
sudo nano /etc/default/isc-dhcp-server
INTERFACESv4="eth0"
# Restart DHCP server
sudo systemctl restart isc-dhcp-server
# Manual DNS setup (temporary)
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
# Permanent DNS setup (Netplan on Ubuntu)
sudo nano /etc/netplan/01-netcfg.yaml
# Add:
# nameservers:
# addresses: [8.8.8.8, 1.1.1.1]
# Apply changes
sudo netplan apply
# Enable IP forwarding
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
# Make it permanent
sudo nano /etc/sysctl.conf
# Uncomment or add:
net.ipv4.ip_forward = 1
# Add forwarding rule
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# Allow traffic from internal to external interface
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT
# Install SLIP support
sudo apt install slattach
# Attach SLIP device to serial port
sudo slattach -L -s 9600 -p slip /dev/ttyS0 &
# Configure SLIP interface (sl0)
sudo ip addr add 192.168.2.1 peer 192.168.2.2 dev sl0
sudo ip link set sl0 up
The Network Time Protocol (NTP) client is used to synchronize the system time with an NTP server. It allows systems to get the correct time based on time servers across the network.
sudo apt install ntpdate
sudo ntpdate time.google.com
sudo apt install ntpdatesudo ntpdate time.google.comThe NTP server provides the correct time to clients on the network. It is essential for maintaining time synchronization across devices.
sudo apt install ntp
sudo systemctl start ntp
sudo systemctl status ntp
sudo apt install ntpsudo systemctl start ntpsudo systemctl status ntpA DNS server resolves domain names to IP addresses for network communications.
sudo apt install bind9
sudo systemctl start bind9
dig @localhost example.com
sudo apt install bind9sudo systemctl start bind9dig @localhost example.comDynamic DNS (DYNDNS) servers allow DNS records to be updated dynamically when an IP address changes.
sudo apt install ddclient
sudo systemctl start ddclient
ddclient): sudo apt install ddclientsudo systemctl start ddclientSecure Telnet (SSH) is used to securely log into a remote system over the network.
sudo apt install openssh-server
sudo systemctl start ssh
sudo systemctl status ssh
sudo apt install openssh-serversudo systemctl start sshsudo systemctl status sshBootstrap Protocol (BOOTP) is used to assign IP addresses to client machines when they boot up, often used in embedded systems or networks.
sudo apt install isc-dhcp-server
sudo systemctl start isc-dhcp-server
dchp-server): sudo apt install isc-dhcp-serversudo systemctl start isc-dhcp-serverTrivial File Transfer Protocol (TFTP) is used for simple file transfers, often used in network booting and device firmware updates.
sudo apt install tftpd-hpa
sudo systemctl start tftpd-hpa
tftp localhost
sudo apt install tftpd-hpasudo systemctl start tftpd-hpatftp localhostThis guide details how to configure a WireGuard VPN server on an Ubuntu Server or Raspberry Pi. This setup enables remote access to the file system, terminal, and MariaDB as if on a local network.
Run the following commands to install WireGuard:
sudo apt update && sudo apt install wireguard -y
Generate a private and public key for WireGuard:
wg genkey | tee privatekey | wg pubkey > publickey
Save the private key securely and note the public key.
Create and edit the WireGuard server configuration file:
sudo nano /etc/wireguard/wg0.conf
Add the following content:
[Interface]
Address = 10.8.0.1/24
PrivateKey = <server_private_key>
ListenPort = 51820
# Enable IP forwarding
PostUp = sysctl -w net.ipv4.ip_forward=1
PostDown = sysctl -w net.ipv4.ip_forward=0
Replace <server_private_key> with the actual private key.
Enable packet forwarding to allow VPN traffic:
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Run the following commands to start WireGuard:
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
If using ufw (Uncomplicated Firewall), allow WireGuard traffic:
sudo ufw allow 51820/udp
sudo ufw enable
For each client, generate keys and add them to the server.
Edit the WireGuard server configuration:
sudo nano /etc/wireguard/wg0.conf
Add a client under [Peer]:
[Peer]
PublicKey = <client_public_key>
AllowedIPs = 10.8.0.2/32
Apply the new settings:
sudo systemctl restart wg-quick@wg0
Ensure SSH is accessible:
sudo systemctl enable ssh
sudo systemctl start ssh
Edit the MariaDB configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Modify the bind address:
bind-address = 10.8.0.1
Restart MariaDB:
sudo systemctl restart mariadb
Install SSHFS on the client:
sudo apt install sshfs -y
Mount the remote filesystem:
sshfs user@10.8.0.1:/home/user /mnt/server
Proceed to Client Configuration to connect Linux and Windows clients.
First, install the WireGuard client package on Linux Mint:
sudo apt update
sudo apt install wireguard
Set up the WireGuard configuration file:
sudo nano /etc/wireguard/wg0.conf
Example configuration:
[Interface]
PrivateKey = <Your_Private_Key>
Address = 10.0.0.2/24
[Peer]
PublicKey = <Server_Public_Key>
Endpoint = <Server_IP>:51820
AllowedIPs = 0.0.0.0/0
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
To mount remote server disks:
sudo mount -t nfs <server_ip>:/remote/path /mnt
Open a terminal and run:
gnome-terminal
Use the following command to install WireGuard on Raspberry Pi:
sudo apt update
sudo apt install wireguard
sudo nano /etc/wireguard/wg0.conf
Example configuration:
[Interface]
PrivateKey = <Your_Private_Key>
Address = 10.0.0.3/24
[Peer]
PublicKey = <Server_Public_Key>
Endpoint = <Server_IP>:51820
AllowedIPs = 0.0.0.0/0
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
sudo mount -t nfs <server_ip>:/remote/path /mnt
lxterminal
Download and install the WireGuard client from the official website:
After installation, open the WireGuard client and create a new tunnel. Input the following configuration:
[Interface]
PrivateKey = <Your_Private_Key>
Address = 10.0.0.4/24
[Peer]
PublicKey = <Server_Public_Key>
Endpoint = <Server_IP>:51820
AllowedIPs = 0.0.0.0/0
Click the "Activate" button in the WireGuard client to start the VPN connection.
To mount server disks on Windows, use the following method:
net use X: \\<server_ip>\share
Open the command prompt by pressing Win + R, typing cmd, and pressing Enter.
OpenVPN is a popular, open-source VPN solution that allows for secure communication between clients and servers over a network. Here’s how to install and configure the OpenVPN server on Linux:
sudo apt update
sudo apt install openvpn easy-rsa
sudo make-cadir /etc/openvpn/easy-rsa
cd /etc/openvpn/easy-rsa
source vars
./clean-all
./build-ca
./build-key-server server
./build-dh
./build-key client
cp keys/{server.crt,server.key,ca.crt,dh2048.pem} /etc/openvpn
sudo nano /etc/openvpn/server.conf
sudo systemctl start openvpn@server
sudo systemctl enable openvpn@server
sudo apt install openvpn easy-rsa./build-ca, ./build-key-server serversudo systemctl start openvpn@serversudo systemctl enable openvpn@serverTo connect to the OpenVPN server from a Linux machine, you need to install OpenVPN and configure the client with the server's certificates.
sudo apt install openvpn
sudo cp /path/to/server/ca.crt /etc/openvpn/
sudo cp /path/to/server/client.crt /etc/openvpn/
sudo cp /path/to/server/client.key /etc/openvpn/
sudo nano /etc/openvpn/client.conf
sudo systemctl start openvpn@client
sudo systemctl enable openvpn@client
sudo apt install openvpnsudo cp /path/to/server/ca.crt /etc/openvpn/sudo nano /etc/openvpn/client.confsudo systemctl start openvpn@clientsudo systemctl enable openvpn@clientTo connect to the OpenVPN server from an Android device, you need to install the OpenVPN Connect app and import the server’s configuration file.
1. Install the OpenVPN Connect app from the Google Play Store.
2. Transfer the OpenVPN configuration file and certificates (ca.crt, client.crt, client.key) to your Android device.
3. Open the OpenVPN Connect app and import the configuration file (client.ovpn).
4. Tap "Connect" to establish the VPN connection.
To connect to the OpenVPN server from a Windows machine, you need to install the OpenVPN client and configure it with the necessary certificates.
1. Download and install OpenVPN from https://openvpn.net/community-downloads/.
2. Copy the server's configuration file (client.ovpn), ca.crt, client.crt, and client.key to the OpenVPN config folder (usually C:\Program Files\OpenVPN\config).
3. Right-click the OpenVPN GUI icon in the system tray and click "Connect" to establish the VPN connection.
Filename: tux.svg
Description: Tux is the official Linux mascot — a friendly cartoon penguin designed to represent the open-source spirit of Linux. It features a black and white penguin with yellow feet and beak, usually shown sitting and smiling cheerfully.
By Larry Ewing, Simon Budig, Garrett LeSage - https://isc.tamu.edu/~lewing/linux/, http://www.home.unix-ag.org/simon/penguin/, garrett/Tux on GitHub, CC0, Link