Share an Internet Connection from Linux with NAT

A Linux system can act as a gateway for devices on a private LAN. Older documentation often called this IP masquerading; today the same idea is usually described as NAT or source NAT. What you need One interface connected to the upstream network or Internet. One interface connected to the private LAN. IP forwarding enabled. … Read more

script — Record a Terminal Session

The script command records everything shown in a terminal session. It is useful when you want to capture troubleshooting steps, command output, or a repeatable install log. Start recording Run your commands as usual. When finished, exit the recording session. View the log Avoid recording passwords, tokens or private data. The output is saved as … Read more

halt — Stop or Power Off a Linux System

The halt command is used to stop a Linux system. On modern Linux systems, systemctl poweroff or shutdown is usually preferred because it is clearer and works through systemd. Check the command first Modern equivalent Only run shutdown or power-off commands on a machine you are allowed to stop. Be especially careful on remote servers, … Read more

host — DNS Lookup Utility

The host command is a simple DNS lookup tool. It is useful for checking whether a hostname resolves, which IP address it points to, or which mail servers are configured for a domain. Basic lookup Check mail servers Check name servers For deeper DNS troubleshooting, compare the result with dig and check whether the issue … Read more

hdparm — View Disk Parameters in Linux

hdparm can display disk parameters and run simple read-performance checks. Some write options can be risky, so use read-only commands unless you are sure of the device and impact. Show disk information Run a basic read test Replace /dev/sda with the correct device name for your system. Check devices first with lsblk.

lsof — List Open Files

lsof lists open files on a Linux or Unix system. It is useful because sockets, devices, directories and regular files can all appear as open files. Find which process is using a port List open files for a process List files opened by a user This command is helpful when troubleshooting ports, locked files, deleted … Read more

strace — Trace System Calls and Signals

strace traces system calls and signals made by a process. It is useful when a program fails but the error message does not explain what happened. Trace a command Attach to a running process Save output to a file Common things to look for are missing files, permission errors, failed network calls and repeated retries.

ltrace — Trace Library Calls in Linux

The ltrace command traces library calls made by a program. It can help when a command fails and you want to see which shared library functions it is calling. Basic usage Example Use ltrace when you are interested in library calls. Use strace when you want to trace system calls such as file, process and … Read more

gcc — GNU C Compiler Basics

gcc is the GNU C compiler. It is commonly used to compile C programs on Linux and is often required when building software from source. Compile a simple C file Run the compiled program Show warnings while compiling For larger projects, prefer the project’s documented build process, such as make, cmake or package-specific instructions.

dd — Convert and Copy Files

dd copies data at a low level. It is powerful, but it can overwrite disks if the input and output paths are wrong. Create an image of a disk or partition Write an image to a USB drive Always double-check the target device before running dd. A wrong of= value can destroy data.