nslookup
nslookup
is a cross-platform command-line tool for querying the Domain Name System (DNS).
Purpose | Command |
---|---|
Basic DNS Lookup | nslookup example.com |
Find Mail Servers for a Domain | nslookup -type=mx example.com |
Query Specific DNS Server | nslookup example.com ns1.isp.com |
Find Authoritative Name Servers | nslookup -type=ns example.com |
Reverse DNS Lookup (IP to Hostname) | nslookup 192.0.2.1 |
Find Text (TXT) Records | nslookup -type=txt example.com |
Query with Non-Interactive Mode | echo server 8.8.8.8 | nslookup example.com |
Find Start of Authority (SOA) Records | nslookup -type=soa example.com |
List All Records for a Domain (Zone Transfer) | nslookup -type=any example.com |
Set Query Time-out | nslookup -timeout=10 example.com |
Display Detailed Query Information | nslookup -debug example.com |
ifconfig
ifconfig
(interface configuration) is a command-line utility in Unix-like operating systems to configure, control, and query TCP/IP network interface parameters. It is often used for network troubleshooting and setup. Below is a table listing some common ifconfig
commands used for daily debugging, along with their purposes:
Purpose | Command |
---|---|
Display all active interfaces | ifconfig |
Display a specific interface (e.g., eth0) | ifconfig eth0 |
Enable an interface (e.g., eth0) | sudo ifconfig eth0 up |
Disable an interface (e.g., eth0) | sudo ifconfig eth0 down |
Assign an IP address to an interface | sudo ifconfig eth0 192.168.1.5 |
Set a netmask for an interface | sudo ifconfig eth0 netmask 255.255.255.0 |
Change the MAC address of an interface | sudo ifconfig eth0 hw ether 02:01:02:03:04:05 |
Add a new alias to an interface | sudo ifconfig eth0:0 192.168.1.6 |
Remove an alias from an interface | sudo ifconfig eth0:0 down |
Note: Modern Linux systems have largely replaced ifconfig
with the ip
command from the iproute2
package, as ifconfig
is considered deprecated. However, ifconfig
is still in use in many systems and scenarios, especially in older or legacy systems.
ip
The ip
command in Linux is a versatile tool for managing and configuring network interfaces, routing, and tunnels. It’s part of the iproute2
package and is used to replace many of the old network configuration tools like ifconfig
, route
, netstat
, etc. Here’s a table with some common ip
command examples used for daily debugging:
Purpose | Command |
---|---|
Display all network interfaces | ip link show |
Display a specific interface (e.g., eth0) | ip addr show eth0 |
Enable an interface (e.g., eth0) | ip link set eth0 up |
Disable an interface (e.g., eth0) | ip link set eth0 down |
Assign an IP address to an interface | ip addr add 192.168.1.5/24 dev eth0 |
Remove an IP address from an interface | ip addr del 192.168.1.5/24 dev eth0 |
Display the routing table | ip route show |
Add a route | ip route add 192.168.1.0/24 via 192.168.1.1 |
Delete a route | ip route del 192.168.1.0/24 |
Display ARP table | ip neigh show |
Change the MAC address of an interface | ip link set dev eth0 address 02:01:02:03:04:05 |
Display statistics for all interfaces | ip -s link |
Monitor network interfaces for new events | ip monitor |
These commands provide a powerful set of tools for managing network interfaces and configurations on a Linux system. The ip
command is more consistent and offers more features compared to the older ifconfig
, making it the preferred choice in modern Linux distributions.
traceroute
The traceroute
command in Linux is a network diagnostic tool used to trace the path that an IP packet takes to reach a destination. It displays each hop along the route and measures transit delays of packets across the network. This can be useful for identifying network bottlenecks or misconfigurations. Here’s a table with some common traceroute
command examples used for daily debugging:
Purpose | Command |
---|---|
Basic traceroute to a destination | traceroute example.com |
Specify the maximum number of hops | traceroute -m 30 example.com |
Use ICMP ECHO instead of UDP datagrams | traceroute -I example.com |
Specify the size of the probing packets | traceroute --mtu example.com |
Perform a traceroute with a specific source IP | traceroute -s [source_ip] example.com |
Use a specific port number | traceroute -p 80 example.com |
Perform a verbose traceroute | traceroute -v example.com |
Use TCP SYN for probes instead of UDP or ICMP | traceroute -T example.com |
Specify the wait time for a response (in seconds) | traceroute -w 5 example.com |
Perform traceroute with a specific interface | traceroute -i eth0 example.com |
These commands can help network administrators and IT professionals diagnose routing issues and understand the path traffic takes to reach a destination. Note that the behavior and options of traceroute
can vary slightly between different Linux distributions and versions.
ping
The ping
command in Linux is a simple yet powerful tool used to test the reachability of a host on an Internet Protocol (IP) network. It measures the round-trip time for messages sent from the originating host to a destination computer and echoes back. Here’s a table with some common ping
command examples used for daily debugging:
Purpose | Command |
---|---|
Basic ping to a destination | ping example.com |
Ping a specific number of times (e.g., 4 times) | ping -c 4 example.com |
Ping with an interval of seconds (e.g., 2 sec) | ping -i 2 example.com |
Ping with a specific packet size (e.g., 100 bytes) | ping -s 100 example.com |
Ping with a deadline (stop after N seconds) | ping -w 10 example.com |
Flood ping (for testing, requires privileges) | sudo ping -f example.com |
Ping and record the route taken | ping -R example.com |
Ping with a specific source IP or interface | ping -I [source_ip/interface] example.com |
Ping and bypass routing table, use direct route | ping -r example.com |
Verbose output | ping -v example.com |
These commands are useful for checking connectivity, response times, and the general health of a network connection between the host and a destination. However, it’s important to use them responsibly, especially commands like flood ping (ping -f
), as they can generate a lot of traffic and might be considered a denial-of-service attack if used improperly.
netstat
The netstat
command in Linux is a versatile networking tool used for examining network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. It’s useful for network troubleshooting and performance measurement. Here’s a table with some common netstat
command examples used for daily debugging:
Purpose | Command |
---|---|
Display all ports (listening and non-listening) | netstat -a |
Display all listening ports | netstat -l |
Display listening TCP ports | netstat -lt |
Display listening UDP ports | netstat -lu |
Show statistics for all ports | netstat -s |
Display PID and program names | netstat -p |
Show network interfaces and statistics | netstat -i |
Display routing table | netstat -r |
Display masquerade connections | netstat -M |
Continuously display network connections | netstat -c |
Display both IPv4 and IPv6 statistics | netstat -46 |
Show the number of network connections by state | netstat -an | grep ESTABLISHED | wc -l |
Note: Modern Linux systems have started to replace netstat
with more powerful and flexible tools like ss
and ip
from the iproute2
package. While netstat
is still widely used and available in many systems, it’s considered somewhat deprecated, and users are encouraged to learn the newer tools for future compatibility.
dig
The dig
(Domain Information Groper) command in Linux is a powerful tool for querying DNS name servers. It’s used for fetching DNS information and troubleshooting DNS problems. Here’s a table with some common dig
command examples used for daily debugging:
Purpose | Command |
---|---|
Basic DNS lookup | dig example.com |
Query a specific DNS record type (e.g., MX) | dig example.com MX |
Query a specific DNS server | dig @ns1.example.com example.com |
Perform a reverse DNS lookup | dig -x 8.8.8.8 |
Query with short answer format | dig example.com +short |
Query with detailed answer (trace the query) | dig example.com +trace |
Get DNSSEC information | dig example.com +dnssec |
Query all record types | dig example.com ANY |
Specify a different query timeout | dig example.com +time=5 |
Perform multiple queries at once | dig example.com example.org |
Check the version of the DNS server | dig @ns1.example.com version.bind CHAOS TXT |
Query with additional statistics | dig example.com +stats |
dig
is a part of the BIND DNS software suite and is a more advanced and flexible tool compared to older tools like nslookup
. It’s widely used by system administrators and network engineers for DNS troubleshooting and analysis.
route
The route
command in Linux is used to view and manipulate the IP routing table. Although it’s been largely superseded by the ip route
command from the iproute2
package, route
is still used in many systems for network configuration and troubleshooting. Here’s a table with some common route
command examples used for daily debugging:
Purpose | Command |
---|---|
Display the current routing table | route -n |
Add a new route | sudo route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 |
Delete a route | sudo route del -net 192.168.1.0 netmask 255.255.255.0 |
Add a default gateway | sudo route add default gw 192.168.1.1 |
Delete a default gateway | sudo route del default gw 192.168.1.1 |
Add a route for a specific host | sudo route add -host 192.168.1.5 gw 192.168.1.1 |
Delete a route for a specific host | sudo route del -host 192.168.1.5 |
Add a route for an interface | sudo route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0 |
Display the routing table for IPv6 | route -A inet6 |
Please note that the route
command requires root privileges for adding or deleting routes, hence the use of sudo
in the examples. Also, as mentioned earlier, the ip
command is now the preferred tool for most routing tasks in modern Linux distributions due to its advanced features and consistent syntax.
hostname
The hostname
command in Linux is used to show or set the system’s host name. It’s a simple yet essential tool for system administrators, particularly when managing networks and server settings. Here’s a table with some common hostname
command examples used for daily debugging:
Purpose | Command |
---|---|
Display the current hostname | hostname |
Set a new hostname | sudo hostname new-name |
Display the DNS domain name | hostname -d |
Display the FQDN (Fully Qualified Domain Name) | hostname -f |
Display the network node hostname | hostname -n |
Display the IP address of the host | hostname -I |
Display all network addresses of the host | hostname -i |
Display the short hostname (first part of FQDN) | hostname -s |
Display the alias name of the host | hostname -a |
Remember that changing the hostname with hostname new-name
doesn’t persist across reboots. To permanently change the hostname on most systems, you need to edit system-specific configuration files (like /etc/hostname
and /etc/hosts
on many Linux distributions) and then use the hostname
command or restart the system.
Also, the way the hostname
command functions can vary slightly between different Linux distributions and versions, so it’s always a good idea to check the man page (man hostname
) for the most accurate information on your specific system.
lsof
lsof
stands for “List Open Files” and is a command in Unix and Linux that provides information about files opened by processes. An open file may be a regular file, a directory, a block special file, a character special file, an executing text reference, a library, a stream, or a network file (like a socket, an NFS file, or an Internet address).
Here’s a table with some common lsof
command examples used for daily debugging:
Purpose | Command |
---|---|
List all open files | lsof |
List files opened by a specific user | lsof -u username |
List open files by a specific process | lsof -p PID |
List open files on a specific port | lsof -i :port |
List all network connections | lsof -i |
List all TCP or UDP connections | lsof -i tcp or lsof -i udp |
List files in a specific directory | lsof +D /path/to/dir |
List open files based on file names | lsof /path/to/file |
List files opened by a specific command | lsof -c command_name |
List open files associated with a file system | lsof /dev/sda1 |
List open files with a specific network protocol | lsof -i tcp or lsof -i udp |
List all open files by all users except one | lsof -u ^username |
lsof
is an extremely powerful tool for system administrators, as it can be used to track down files that are being used by processes, which is helpful in diagnosing various system issues, such as why a file system cannot be unmounted or what is causing network traffic. Remember that many lsof
commands require root privileges to provide complete and accurate information.
du
The du
(disk usage) command in Linux is used to estimate file and directory space usage. It’s a crucial tool for managing disk space, identifying which files and directories are consuming the most space, and for general storage housekeeping. Here’s a table with some common du
command examples used for daily debugging:
Purpose | Command |
---|---|
Display the disk usage of a directory | du /path/to/directory |
Display disk usage in human-readable format | du -h /path/to/directory |
Summarize disk usage of each file in a directory | du -a /path/to/directory |
Display disk usage up to N levels deep | du --max-depth=N /path/to/directory |
Display total disk usage of a directory | du -s /path/to/directory |
Display disk usage in bytes | du -b /path/to/directory |
Display disk usage of all files and directories | du -ah |
Display disk usage of all .jpg files | du -ch *.jpg |
Sort the output by size in human-readable format | du -hs * | sort -h |
Exclude files matching a pattern | du --exclude="*.log" /path/to/directory |
The du
command is highly versatile and can be combined with other commands like sort
for more advanced disk usage analysis. It’s a fundamental tool for Linux system administrators and users for monitoring and managing disk space usage.
df
The df
(disk free) command in Linux is used to report file system disk space usage. It provides an overview of the available and used disk space on all mounted filesystems. Here’s a table with some common df
command examples used for daily debugging:
Purpose | Command |
---|---|
Display all file systems disk space usage | df |
Display in human-readable format (e.g., MB, GB) | df -h |
Display the file system type | df -T |
Include dummy file systems | df -a |
Display inodes usage instead of block usage | df -i |
Display disk space usage of a specific file system | df /path/to/directory |
Display disk space usage in 1K blocks | df -k |
Display disk space usage in megabytes | df -m |
Display disk space usage for a specific type | df -t ext4 |
Exclude a specific type of file system | df -x tmpfs |
The df
command is essential for monitoring overall disk space usage, ensuring that systems do not run out of space, and for managing disk resources effectively. It’s one of the most basic and frequently used commands for system administrators and users alike.
To list large files in a Linux system sorted by size, you can use the find
, du
, and sort
commands in combination. Here’s a command that searches for large files in a specific directory and sorts them by size in a human-readable format:
find /path/to/search -type f -exec du -h {} + | sort -rh
Breaking down the command:
find /path/to/search
: This part of the command specifies thefind
command to search in/path/to/search
directory. Replace/path/to/search
with the specific directory you want to search in, or use.
to represent the current directory.-type f
: This option tellsfind
to look for files only (not directories).-exec du -h {} +
: For each file found,exec
executes thedu -h
command.du -h
displays the disk usage in a human-readable format (e.g., K, M, G).{}
is replaced by the name of each file found, and+
at the end executesdu
on multiple files at once for efficiency.| sort -rh
: The output fromdu
is then piped (|
) into thesort
command. The-rh
option tellssort
to handle the sizes in a human-readable format (-h
) and sort them in reverse order (-r
), which puts the largest files at the top of the list.
If you want to search the entire filesystem and you have permission to access all directories, you can run this command starting from the root (/
):
sudo find / -type f -exec du -h {} + | sort -rh
Remember that searching the entire filesystem can take a considerable amount of time and might produce a very long list. It’s often more practical to target specific directories known for containing large files.
Expand A Directory By Mounting New Volume
Expanding the storage capacity of a directory in Linux by mounting a new volume to that directory, need to use the new volume to increase the available space for that directory.
- Identify the New Volume: First, you need to identify the device name of the new volume. You can use
lsblk
orfdisk -l
to list all storage devices and their partitions. The new volume might be something like/dev/sdb1
,/dev/sdc1
, etc. - Create a Filesystem (if necessary): If the new volume doesn’t have a filesystem, you need to create one. For example, to create an
ext4
filesystem on/dev/sdb1
, use:
sudo mkfs.ext4 /dev/sdb1
Warning: This step will erase existing data on the partition. Ensure that you’re operating on the correct device and that no important data is lost.
- Mount the Volume Temporarily: Before making it permanent, you might want to mount the volume temporarily to ensure everything works correctly.
sudo mount /dev/sdb1 /path/to/directory
Replace /path/to/directory
with the path to the directory you want to expand. This directory should exist.
- Test the Setup: Check if the volume is mounted correctly and if you can read/write data as expected.
- Unmount the Volume: If everything is fine, unmount the volume before proceeding to permanent mounting.
sudo umount /path/to/directory
- Edit
/etc/fstab
for Permanent Mounting: To make the mounting permanent, you need to add an entry to the/etc/fstab
file.
- Open
/etc/fstab
with a text editor, for example:sudo nano /etc/fstab
- Add a line at the end of the file:
/dev/sdb1 /path/to/directory ext4 defaults 0 2
Replace/dev/sdb1
with your device name,/path/to/directory
with your directory path, andext4
with the filesystem type you used.
- Mount All Filesystems: After saving the changes to
/etc/fstab
, you can mount all filesystems mentioned in it without rebooting:
sudo mount -a
- Verify the Mount: Finally, verify that the new volume is mounted correctly:
df -h /path/to/directory
This process effectively “expands” the chosen directory by mounting a new volume to it, thereby increasing its available storage capacity. Remember to back up important data before performing operations like formatting or editing /etc/fstab
, as mistakes can lead to data loss.