DEV Community

Cover image for Linux Network Configuration
Teniola
Teniola

Posted on • Edited on

Linux Network Configuration

A few more steps forward in my DevOps journey! This time, I worked on another task in Linux administration which is focused on configuring server and network settings. In this task, I set a static IP address, configured firewall rules for added security, and installed and set up Nginx to host a simple website. I also explored DNS concepts to understand how domain resolution works. Each step helped solidify the foundational skills necessary for effective system management—a critical part of any DevOps role. Documenting these tasks not only tracks my progress but serves as a practical guide for anyone on a similar path.

This task focuses on configuring essential server and network settings on Linux. Key objectives include assigning a static IP, setting up a firewall for security, installing and configuring Nginx to host a basic website, and learning DNS for domain resolution. Completing this task will build foundational skills in network management, server setup, and security configuration on Ubuntu.

  1. Network Configuration Objective: Configure network settings on a Linux server, assign a static IP address, and troubleshoot network issues with basic tools.

Step 1: Set up a Static IP Address
Identify the Network Interface:

The network interface represents the physical or virtual network adapter through which the system connects to a network.
Use the following command to list all available network interfaces and their current IP addresses:

ip a
Enter fullscreen mode Exit fullscreen mode

Look for your primary interface (often named eth0, enp0s3, or something similar). The IP and subnet mask appear as inet /.
Edit the Network Configuration File:

Ubuntu (using Netplan):
Netplan is the default network configuration utility on recent Ubuntu versions.
Open /etc/netplan/01-netcfg.yaml (the filename may vary in the /etc/netplan/ directory) to configure your network.
Update or add your settings for the desired static IP, gateway, and DNS servers:

network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: no  # Disables DHCP, which automatically assigns IPs
      addresses:
        - 192.168.1.100/24  # Sets static IP and subnet mask
      gateway4: 192.168.1.1  # Sets the gateway IP for outbound traffic
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
Enter fullscreen mode Exit fullscreen mode

Save changes and apply them using:

sudo netplan apply
Enter fullscreen mode Exit fullscreen mode

Step 2: Network Troubleshooting

Using ifconfig:

This tool displays network interface configurations (IP addresses, subnet masks, etc.). It’s commonly pre-installed or installable with sudo apt install net-tools.

ifconfig
Enter fullscreen mode Exit fullscreen mode

Using ip:

The ip command provides comprehensive network configuration details and is widely used on modern systems.

ip addr show
Enter fullscreen mode Exit fullscreen mode

Testing Network Connectivity with ping:

Verifies that a remote server is reachable. A successful response means the network is configured and routing correctly.

ping google.com
Enter fullscreen mode Exit fullscreen mode
  1. Firewall Configuration Objective: Set up a firewall to manage incoming and outgoing traffic, limiting access only to necessary services.

Step 1: Install and Configure UFW (Ubuntu)
Install UFW:

UFW (Uncomplicated Firewall) simplifies the management of iptables-based firewall settings.

sudo apt install ufw
Enter fullscreen mode Exit fullscreen mode

Enable UFW:

Activates the firewall. You may need to confirm any prompts.

sudo ufw enable
Enter fullscreen mode Exit fullscreen mode

Allow Traffic for Specific Services:

Allowing specific services like SSH (for remote login) and HTTP/HTTPS (for web services) is crucial. UFW has predefined rules for these services:
SSH:

sudo ufw allow ssh
Enter fullscreen mode Exit fullscreen mode

HTTP (port 80):

sudo ufw allow http
Enter fullscreen mode Exit fullscreen mode

HTTPS (port 443):

sudo ufw allow https
Enter fullscreen mode Exit fullscreen mode

Check Status:

Verifies the current firewall rules.

sudo ufw status
Enter fullscreen mode Exit fullscreen mode

Check Status:

View the active firewall rules and settings:

sudo firewall-cmd --list-all
Enter fullscreen mode Exit fullscreen mode
  1. Install and Configure Nginx Objective: Install the Nginx web server and configure a basic website.

Step 1: Install Nginx
Ubuntu:

sudo apt install nginx
Enter fullscreen mode Exit fullscreen mode

Step 2: Start and Enable Nginx Service
Start Nginx:

Starts the web server, making it active immediately.

sudo systemctl start nginx
Enter fullscreen mode Exit fullscreen mode

Step 3: Configure a Basic HTML Page
Create a Test HTML File:

Place an HTML page in Nginx’s default root directory (/var/www/html/). This will act as the main website.
Create a sample file:

echo "<html><body><h1>My Nginx Server!</h1></body></html>" | sudo tee /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

Verify Nginx Setup:

Open a web browser and enter the server’s IP address (e.g., http://192.168.1.100). You should see the "My Nginx Serve!" message if the setup is successful.

  1. Domain Name System (DNS) Objective: Understand DNS basics and configure the system to use specific DNS servers.

Step 1: Basic DNS Concepts
DNS (Domain Name System): Translates domain names (like example.com) to IP addresses.
Resolver: A DNS resolver queries name servers to get IPs for requested domain names.
Name Servers: DNS servers that hold information about domain names and provide IP mappings.
Step 2: Set Up a Local DNS Resolver
Edit the /etc/resolv.conf File:

Configure the system to use specific DNS servers by editing the /etc/resolv.conf file. This example sets Google’s DNS servers:

nameserver 8.8.8.8
nameserver 8.8.4.4
Enter fullscreen mode Exit fullscreen mode

Install and Use dig for DNS Queries:

Ubuntu: Install dnsutils to access dig.

sudo apt install dnsutils
Enter fullscreen mode Exit fullscreen mode

Use dig to check domain resolution:

dig example.com
Enter fullscreen mode Exit fullscreen mode

Step 3: Verify DNS Settings
Use ping to check if the server can resolve domain names, which confirms DNS configuration:

ping google.com
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
olalekan_oladipupo_fc0e91 profile image
Olalekan Oladipupo

I'm proud Teniola. This is interesting.