Skip to content

Instantly share code, notes, and snippets.

@kapil1024
Last active January 18, 2022 11:55
Show Gist options
  • Save kapil1024/20bfc60f1813a4f82b99b9556f1b0148 to your computer and use it in GitHub Desktop.
Save kapil1024/20bfc60f1813a4f82b99b9556f1b0148 to your computer and use it in GitHub Desktop.
Setting up nbd server, https server, samba server and tftp server on ubuntu 18.04

Install required packages

apt install -y nbd-server nbd-client apache2 wget samba smbclient cifs-utils tftpd-hpa tftp

Set a variable for local IP (not mandatory)

export LOCAL_IP="192.168.21.2"

HTTPS server

  1. Enable SSL module and restart the server
    • a2enmod ssl
    • a2ensite default-ssl
    • systemctl restart apache2
  2. Create a file to share. I am just creating a disk file to reuse it in NBD server. You can create any type of file.
    • dd if=/dev/zero of=/var/www/html/disk0 bs=1M count=100
    • chmod a+w /var/www/html/disk0
    • mke2fs /var/www/html/disk0
  3. Access the file via HTTPS server
    • wget --no-check-certificate https://${LOCAL_IP}/disk0

NBD server

  1. Start hosting the disk image created above.
    • nbd-server ${LOCAL_IP}:10809 /var/www/html/disk0
  2. Access the disk image via NBD server
    • nbd-client ${LOCAL_IP} 10809 /dev/nbd0
  3. Mount, use & unmount NBD disk
    • mount /dev/nbd0 /mnt
    • ls /mnt
    • umount /mnt
  4. Disconnect the client after we are done with the disk
    • nbd-client -d /dev/nbd0

Samba/CIFS server

  1. Add a share named "users" to server configuration
    cat <<"EOF" >> /etc/samba/smb.conf
    [users]
        path = /var/www/html
        browseable = yes
        read only = no
        force create mode = 0660
        force directory mode = 2770
        guest ok = no
        #valid users = nbd @nbd @sambashare
    EOF
    
  2. Add & enable a user
    • smbpasswd -a nbd
    • smbpasswd -e nbd
  3. Restart services
    • systemctl restart smbd
    • systemctl restart nmbd
  4. Verify the server
    • smbclient //${LOCAL_IP}/users -U nbd
  5. Mount samba share locally
    • mount -t cifs -o username=nbd -o nolock,sec=ntlmsspi,seal,vers=3.0,rw //${LOCAL_IP}/users /mnt
  6. Use and unmount
    • ls /mnt
    • umount /mnt

TFTP server

  1. Update server configuration
    cat <<"EOF" > /etc/default/tftpd-hpa
    TFTP_USERNAME="nbd"
    TFTP_DIRECTORY="/var/www/html"
    TFTP_ADDRESS=":69"
    TFTP_OPTIONS="--secure"
    EOF
    
  2. Restart service
    • systemctl restart tftpd-hpa
  3. Get a file from the server
    • tftp ${LOCAL_IP}
    • tftp> get disk0

    • tftp> quit

  4. Get a file from the server using busybox
    • busybox tftp -g -r disk0 ${LOCAL_IP}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment