Author: Stefan

  • How To Use Systemctl to Manage Systemd Services and Units

    All credits to:

    jellingwood @ Digitalocean.com

     Introduction

    Systemd is an init system and system manager that is widely becoming the new standard for Linux machines. While there are considerable opinions about whether systemd is an improvement over the traditional SysV init systems it is replacing, the majority of distributions plan to adopt it or have already done so.

    Due to its heavy adoption, familiarizing yourself with systemd is well worth the trouble, as it will make administrating these servers considerably easier. Learning about and utilizing the tools and daemons that comprise systemd will help you better appreciate the power, flexibility, and capabilities it provides, or at least help you to do your job with minimal hassle.

    In this guide, we will be discussing the systemctl command, which is the central management tool for controlling the init system. We will cover how to manage services, check statuses, change system states, and work with the configuration files.

  • TK102 GPS tracker configuration

    TK102 GPS tracker configuration

    We are going to use a KPN prepaid SIM card. The pin code is removed using a cell phone and mobile internet is activated.

    We will transfer the data via GPRS connection to a GPS server called Traccar. The server is free downloadable for any platform.

    Make sure the battery of the GPS is well charged, insert the sim card and turn on the GPS.

    Follow the steps below to perform the basic configuration:

    (more…)

  • Ubuntu error: A job is running for dev-mapper-cryptswap1.device

    (Thanks to: Ubuntuhak )
    If you notice that booting Ubuntu takes a long time and you see the following error message on the booting screen after pressing ‘ESC’,

    A job is running for dev-mapper-cryptswap1.device (50s / 1m30s)

    This is caused by the system looking for an encrypted swap partition, however most likely you have not created one. Which is normal, now when a lot of RAM is available, and a swap partition is not necessary. This is all due to a misconfiguration entry in the fstab, which tells the system to try and mount the said (non existing) partition.

    Solution

    The solution is to remove or comment out the “cryptswap” entries from /etc/fstab and /etc/crypttab.
    This can be done easily by editing the above mentioned files as commenting out the lines that say cryptswap by placing a “#” in front of the matching lines.

    sudo nano /etc/fstab
    sudo nano /etc/crypttab

    The result is shown below in the image, where the lines referring to the cryptswap partition are already commented out.

    Reminder: ‘CTRL + O’ saves the file, ‘CTRL + X’ exits the nano text editor.

  • Chrome browser in Ubuntu

    Chrome browser in Ubuntu

    Follow the instruction for installation:

    1. Add Key:
      wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - 
      
    2. Set repository:
      sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
      
    3. Install package:
      sudo apt-get update 
      sudo apt-get install google-chrome-stable
      
  • PXE Server on Existing Network

    Many thanks to Sebastian Krysmanski’s original post!

    The Goal

    At the end of this article you’ll have a working PXE server that lets you boot memtest86+ over a network.

    The goal is to have a simple but working solution. This is why I’m using memtest. It consists of just one file and thus is easy to use in a PXE setup. More complex scenarios (i.e. loading real operating systems) can be built on top of this simple setup.

    Everything described in the article can be done inside a virtual machine. The only requirement is that the VM is connected directly (i.e. no NAT) to the network where it’s supposed to serve PXE (usually the host’s network).

    The Basics: PXE, DHCP, ProxyDHCP, TFTP, and dnsmasq

    PXE is an abbreviation for “Preboot Execution Environment”. To put it simple: It’s a standardized way to boot an operating system over network (rather than from hard disk).

    DHCP is usually used to assign IP addresses to computers/devices in a network. PXE is an extension to DHCP. To use PXE one needs a PXE-capable DHCP server.

    When PXE was designed, the creators wanted to make it compatible with networks that already have an existing DHCP server. As a result, PXE and DHCP can be provided by separate servers without interfering with each other. In this scenario, the PXE server is called proxyDHCP server and only provides the PXE functionality (but doesn’t do IP assigning).

    TFTP (Trivial File Transfer Protocol) is used by PXE clients to download the operating system (file) from the PXE server.

    dnsmasq is a “simple” Linux tool that combines a DNS server, a DHCP server, a TFTP server, and a PXE server. This is the tool you’ll use in this article.

    Prerequisites

    The steps in this article are based on Ubuntu 16.04.

    You need the following packages:

    $ apt-get install dnsmasq pxelinux syslinux-common

    You also need the precompiled memtest binary:

    $ wget http://www.memtest.org/download/5.01/memtest86+-5.01.bin.gz
    $ gzip -dk memtest86+-5.01.bin.gz

    Furthermore, you need a working DHCP server (e.g. one provided by a hard router).

    The last thing you need is to know the network you’re on. My network is 192.168.178.XXX – so I’ll use this in this article. This information is only needed once in a configuration file (see below).

    Warning: During the course of this article your Ubuntu machine may temporarily lose the ability to do DNS lookups. This is caused by dnsmasq. If this happens to you and you need to download anything or access the web, just (temporarily) stop dnsmasq.

    Step by Step: From Start to Finish

    Lets do it then. This section describes all steps need to get a working PXE server.

    First, lets stop dnsmasq for now.

    $ service dnsmasq stop

    Create the directory where all transferable operating system files will reside:

    $ mkdir -p /var/lib/tftpboot

    Inside of this directory, create a directory for the unzipped memtest binary file and copy it there:

    $ mkdir -p /var/lib/tftpboot/memtest
    $ cp ~/memtest86+-5.01.bin /var/lib/tftpboot/memtest/memtest86+-5.01

    Important: Note that the copy command removed the .bin file extension. This is required.

    Now create the directory for the PXE configuration file:

    $ mkdir -p /var/lib/tftpboot/pxelinux.cfg

    Important: This directory must always be called pxelinux.cfg.

    Inside of this directory, create a file called default and put in the following content:

    default memtest86
    prompt 1
    timeout 15
    
    label memtest86
      menu label Memtest86+ 5.01
      kernel /memtest/memtest86+-5.01

    Next, you need to put the files pxelinux.0 (Ubuntu package pxelinux) and ldlinux.c32 (Ubuntu package syslinux-common) in /var/lib/tftpboot. I’ll use symlinks for that:

    $ ln -s /usr/lib/PXELINUX/pxelinux.0 /var/lib/tftpboot/
    $ ln -s /usr/lib/syslinux/modules/bios/ldlinux.c32 /var/lib/tftpboot/

    Now, clear all contents of /etc/dnsmasq.conf and replace them with this:

    1
    2
    3
    4
    5
    6
    7
    8
    910
    11
    12
    13
    14
    15
    16
    17
    
    # Disable DNS Server
    port=0
     
    # Enable DHCP logging
    log-dhcp
     
    # Respond to PXE requests for the specified network;
    # run as DHCP proxy
    dhcp-range=192.168.178.0,proxy 
    dhcp-boot=pxelinux.0
     
    # Provide network boot option called "Network Boot".
    pxe-service=x86PC,"Network Boot",pxelinux
     
    enable-tftp
    tftp-root=/var/lib/tftpboot

    Important: In line 9 you need to put in your network, if you’re not on 192.168.178.XXX.

    Edit /etc/default/dnsmasq and add the following line to the end:

    DNSMASQ_EXCEPT=lo

    This line is necessary because you disabled dnsmasq’s DNS functionality above (with port=0). Without it Ubuntu will still redirect all DNS queries to dnsmasq – which doesn’t answer them anymore and thus all DNS lookups would be broken. You can check /etc/resolv.conf and verify that it contains the correct IP address for your network’s DNS server.

    Last step – start dnsmasq again:

    $ service dnsmasq start

    Now, when starting a PXE-enabled machine, it should boot memtest.

  • Change linux hostname

    How to change the hostname of the system

    sudo hostname (new hostname)


    Change old hostname also in the following file:

    sudo nano /etc/hosts


  • OpenVPN shortcut

    This script will show your current WAN IP address before and after connecting to your VPN.

    VALID_IP="123.123.123.123" #this is the correct IP you should be connected to
    myip="$(dig +short myip.opendns.com @resolver1.opendns.com)"
    echo "My current WAN/Public IP address: ${myip}"
    echo "Starting OpenVPN connection"
    
    sleep 1
    sudo openvpn --config ~/path/to/VPNConfig.ovpn --daemon
    echo "Establishing connection..."
    sleep 8
    myip="$(dig +short myip.opendns.com @resolver1.opendns.com)"
    echo "Now connected to WAN/Public IP address: ${myip}"
    if [ "$myip" == "$VALID_IP" ]; then
    echo "Succesfull connected to VPN-server!"
    sleep 1
    fi;
    exit
    

    (more…)

  • Add user to sudo- ers file

    Open the sudoers file: sudo visudo will open the /etc/sudoers file in the editor defined in $EDITOR (probably GNU nano – set the variable if it’s not what you want, eg export EDITOR="nano" and try sudo visudo again).

    Add the below line to the end of the file.

    username ALL=(ALL) ALL   # Change the user name before you issue the commands
    

    Then perform WriteOut with Ctrl + O. The editor will ask you for the file name to write into. The default will be a temporary file that’s used by visudo to check for syntax errors before saving to the actual sudoers file. Press Enter to accept it. Quit the nano editor with Ctrl + X.

  • OpenVPN running in background

    Simply run the following command in terminal:

    sudo openvpn --config ~/Documents/path-to/VPNConfig.ovpn --daemon


    It is not nescessary to leave the terminal open!

    To kill the connection, stop the process.
    Identify the correct process ID number.

    ps aux | grep openvpn


    Kill the process.

    sudo kill [id-number]


    (more…)

  • Raspberry Pi Static ip address

    Edit /etc/dhcpcd.conf

    sudo nano /etc/dhcpcd.conf

    Add the following rows add the bottom of the text. Leave the default text intact.

    interface eth0
    static ip_address=192.168.1.99
    interface wlan0
    static ip_address=192.168.1.100
    static routers=192.168.1.1
    static domain_name_servers=202.62.64.3 8.8.8.8

    Reboot