Transforming Your Old Laptop into a Shared Host

Santheepkumar

Santheepkumar / July 11, 2023

9 min read––– views

image info

Introduction:

Have an old laptop or computer lying around? Instead of letting it gather dust, you can repurpose it as a shared host for your other devices. By setting it up as a server, you can provide services such as file sharing, web hosting, and remote access to streamline your workflow and centralize resources. In this article, we will guide you through the process of transforming your laptop or computer into a versatile shared host.

Preparation

  • Check system requirements: Ensure your laptop meets the minimum system requirements to handle server tasks effectively.

  • Backup important data: Before making any changes, it's essential to back up your important files and data to prevent any potential loss. Section 2: Installing Ubuntu Server

  • Download the latest version of Ubuntu: Visit the official Ubuntu website and download the latest version of Ubuntu Server specifically designed for server deployments.

  • Ubuntu is not the only Linux distribution that can be used; any Linux distribution can be utilized instead of Ubuntu. However, for the purpose of this process, I am currently using Ubuntu.

  • Create a bootable installation media: Use a USB drive or DVD to create a bootable installation media with the Ubuntu Server ISO file. Install Ubuntu: Boot your old laptop from the installation media and follow the on-screen instructions to install Ubuntu Server.

Set up necessary services:

File sharing with Samba (for Windows clients):

  • Install Samba by running the following command in the terminal:

    sudo apt update
    sudo apt install samba
    
  • Configure the Samba shares by editing the Samba configuration file:

    sudo nano /etc/samba/smb.conf
    
  • Add your shared folders by appending the following lines at the end of the file:

    [SharedFolderName]
    path = /path/to/shared/folder1
    read only = no
    guest ok = yes
    
  • Save the changes and exit the editor.

  • Restart the Samba service:

    sudo systemctl restart smbd
    

File sharing with NFS (for Linux clients):

  • Install the NFS server by running the following command in the terminal:

    sudo apt update
    sudo apt install nfs-kernel-server
    
  • Create a directory to be shared:

    sudo mkdir /path/to/shared/folder1
    
  • Configure the exports file:

    sudo nano /etc/exports
    
  • Add the following line:

    /path/to/shared/folder1 *(rw,sync,no_subtree_check)
    
  • Save the changes and exit the editor.

  • Export the shared folder:

    sudo exportfs -ra
    

Web hosting with Apache:

  • Install Apache web server by running the following command:

    sudo apt update
    sudo apt install apache2
    
  • Place your website files in the default web root directory:

    /var/www/html/
    
  • Make sure the necessary permissions are set on the web files:

    sudo chown -R www-data:www-data /var/www/html/
    sudo chmod -R 755 /var/www/html/
    

Remote access with SSH:

  • Install OpenSSH server by running the following command:

    sudo apt update
    sudo apt install openssh-server
    
  • SSH server should be started automatically after installation

  • Configure firewall and security:

    • Enable the UFW firewall and allow necessary services:

      sudo ufw enable
      sudo ufw allow OpenSSH    # For SSH access
      sudo ufw allow Samba      # For Samba file sharing
      sudo ufw allow Apache     # For Apache web server
      sudo ufw allow nfs        # For NFS file sharing (if using)
      
      

Set up static IP address:

  • Edit the network configuration file:

    sudo nano /etc/netplan/00-installer-config.yaml
    
  • Configure a static IP address by modifying the file as follows:

    network:
      version: 2
      renderer: networkd
      ethernets:
        enp0s3:
          dhcp4: no
          addresses: [your_static_ip/24]
          gateway4: your_gateway_ip // drprecated so use routes
          nameservers:
            addresses: [DNS_server_ip]
    
  • To find [your_static_ip/24]

ip a
# find /24 - you will get your static ip
  • To find the gateway IP address in Ubuntu, you can use the following steps:
    1. Open a terminal on your Ubuntu laptop.

    2. Run the command:

      ip route | grep default
      
    3. Look for the line that starts with "default" and ends with the IP address of the gateway. It should look something like this:

      default via <gateway_ip> dev <interface>
      
    4. Note down the IP address mentioned after "via." This is your gateway IP address.

  • To find the DNS (Domain Name System) server IP address in Ubuntu, you can follow these steps:
    1. Open a terminal on your Ubuntu laptop.

    2. Check the DNS server configured for your network connection:

      • Run the command:

        nmcli dev show | grep 'IP4.DNS'
        
    3. Look for the line that starts with "IP4.DNS" and displays the DNS server IP address(es). It should look something like this:

      IP4.DNS[1]:               <DNS_server_ip>
      
    4. Note down the IP address mentioned after "IP4.DNS[1]:". This is your DNS server IP address.

  • Example Config
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      addresses: [192.168.1.10/24]
      routes:
        - to: 0.0.0.0/0
          via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
  • Monitor server logs regularly to ensure proper functioning of services.

  • Save the changes and exit the editor.

  • Apply the new network configuration:

    sudo netplan apply
    

Remember to replace /path/to/shared/folder1 with the actual path to your shared folder, your_static_ip with the desired static IP address, your_gateway_ip with the IP address of your network.

Ensure that everything is functioning properly

To verify if everything is properly working on your Ubuntu shared host, you can perform some checks and tests. Here are a few steps you can follow:

  1. File Sharing:
    • If you have set up Samba for file sharing, try accessing the shared folders from another machine on the network. Ensure you can read, write, and modify files as intended.
    • If you have configured NFS for file sharing, mount the shared NFS directory on another Linux machine and perform file operations to ensure they work as expected.
  2. Web Hosting:
    • Open a web browser on the Ubuntu shared host itself.
    • Enter localhost or 127.0.0.1 in the browser's address bar.
    • Verify that your website or web application loads correctly without any errors.
    • Test different web pages or functionalities to ensure proper functionality.
  3. Remote Access:
    • From another machine on the network, establish an SSH connection to your Ubuntu shared host using an SSH client (e.g., PuTTY for Windows or Terminal for Mac/Linux).
    • Enter the IP address or hostname of your Ubuntu shared host when prompted.
    • Provide the necessary credentials (username and password) to log in.
    • Once logged in, ensure you have access to the command line interface and can perform desired operations.
  4. Network Connectivity:
    • Ping your Ubuntu shared host from another machine on the network using the IP address or hostname to check network connectivity.
    • Run the command ip a or ifconfig on your Ubuntu shared host to verify that the network interface has the correct IP address assigned.
  5. Service Status:
    • Check the status of the services you have set up (e.g., Samba, Apache, NFS) using their respective service management commands. For example:
      • Samba: sudo systemctl status smbd
      • Apache: sudo systemctl status apache2
      • NFS: sudo systemctl status nfs-kernel-server
  6. Log Files:
    • Examine the log files for any error messages or warnings related to the services you have configured. Common log files include /var/log/syslog, /var/log/samba/*, and /var/log/apache2/*.

By performing these checks, you can ensure that the configured services on your Ubuntu shared host are running correctly and accessible from other machines on the network.

Usage Guide

Certainly! Here's a brief usage guide for accessing the file sharing, web hosting, and SSH services on your Ubuntu shared host from other systems:

  • File Sharing:
    • For Samba (Windows sharing):
      • On Windows: Open File Explorer and enter \\<IP_or_hostname> in the address bar. Replace <IP_or_hostname> with the IP address or hostname of your Ubuntu shared host. You can then browse and access the shared folders.

      • On Mac: Open Finder, click on "Go" in the menu bar, select "Connect to Server," and enter smb://<IP_or_hostname>. Replace <IP_or_hostname> with the IP address or hostname of your Ubuntu shared host. Authenticate if prompted and access the shared folders.

      • On Linux: Use the smbclient or mount commands to connect to the Samba shares. For example:

        smbclient //<IP_or_hostname>/SharedFolder -U username
        
    • For NFS (Linux sharing):
      • On Linux: Use the mount command to mount the NFS shares. For example:

        sudo mount <IP_or_hostname>:/path/to/shared/folder /mount/point
        
      • On Mac: NFS support is built into macOS. Use the mount command similar to Linux to mount the NFS shares.

  • Web Hosting:
    • Open a web browser on any system.
    • Enter the IP address or hostname of your Ubuntu shared host in the browser's address bar.
    • If you have set up a specific domain name, use that instead.
    • Press Enter, and the browser should load the website hosted on your Ubuntu shared host.
  • SSH (Secure Shell):
    • Open a terminal or SSH client application on the system.

    • Use the following command to establish an SSH connection to your Ubuntu shared host:Replace username with the actual username of a valid user account on the Ubuntu shared host, and <IP_or_hostname> with the IP address or hostname of your Ubuntu shared host.

      ssh username@<IP_or_hostname>
      # Example
      ssh ubuntu@182.23.2.2
      
    • Enter the password for the specified username when prompted.

    • Once connected, you will have command line access to your Ubuntu shared host.

Remember to replace <IP_or_hostname> with the actual IP address or hostname of your Ubuntu shared host, and <username> with a valid user account on the shared host.

These guidelines should help you access the file sharing, web hosting, and SSH services on your Ubuntu shared host from other systems.

Conclusion:

Transforming your old laptop into a shared host can breathe new life into the device and provide valuable services such as file sharing, web hosting, and remote access. By following the step-by-step guide in this article, you can repurpose your laptop using Ubuntu Server and enjoy the benefits of a centralized hub for your digital resources. Don't let your old laptop gather dust – give it a new purpose and unlock its full potential as a shared host.

Subscribe to the newsletter

Get emails from me about web development, tech, and early access to new articles.

- subscribers – 32 issues