Some Interview questions Networking and linux basics.
IP address and Gateway address difference.
An IP address is a unique identifier for a device on a network, while a gateway is a device that connects two or more networks and allows them to communicate. A gateway usually has an IP address on each network it connects. For example, if your computer has an IP address of 192.168.1.10 on your local network, and your router has an IP address of 192.168.1.1 on the same network and another IP address of 203.0.113.5 on the internet, then your router is the gateway between your local network and the internet. Your computer can send packets to any device on your local network using their IP addresses, but to send packets to devices on the internet, it needs to use the gatewayโs IP address as the destination. The gateway will then forward the packets to the appropriate network using its own routing table.
What is Port?
The purpose of having ports in the computer is to allow different types of data and devices to communicate with the computer. Ports are software-based and managed by the computerโs operating system. Each port is associated with a specific process or service, such as web browsing, email, file transfer, audio, video, etc. Ports are identified by numbers, and each port number is assigned to a standard protocol or application. For example, port 80 is used for HTTP, port 21 is used for FTP, port 25 is used for SMTP, and so on. By using different ports, the computer can easily differentiate between different kinds of traffic and send or receive data accordingly.
S๐จ๐ฆ๐ ๐๐จ๐ฆ๐ฆ๐จ๐ง ๐ฉ๐จ๐ซ๐ญ ๐ง๐ฎ๐ฆ๐๐๐ซ๐ฌ ๐ญ๐ก๐๐ญ ๐๐๐ฏ๐๐ฉ๐ฌ ๐๐ง๐ ๐ข๐ง๐๐๐ซ๐ฌ ๐ฆ๐๐ฒ ๐๐ง๐๐จ๐ฎ๐ง๐ญ๐๐ซ:
1. ๐๐จ๐๐ค๐๐ซ ๐๐๐๐ฆ๐จ๐ง:
- Port: 2375 (unencrypted) and 2376 (encrypted)
2. ๐๐๐ง๐ค๐ข๐ง๐ฌ:
- Typically runs on ๐๐๐๐ ๐ฉ๐จ๐ซ๐ญ 8080 ๐จR ๐๐๐๐๐ ๐ฉ๐จ๐ซ๐ญ 8443
3. ๐๐๐๐ (๐๐ฒ๐ฉ๐๐ซ๐ญ๐๐ฑ๐ญ ๐๐ซ๐๐ง๐ฌ๐๐๐ซ ๐๐ซ๐จ๐ญ๐จ๐๐จ๐ฅ):
- Default Port: 80
4.๐๐๐๐๐ (๐๐ฒ๐ฉ๐๐ซ๐ญ๐๐ฑ๐ญ ๐๐ซ๐๐ง๐ฌ๐๐๐ซ ๐๐ซ๐จ๐ญ๐จ๐๐จ๐ฅ ๐๐๐๐ฎ๐ซ๐):
- Default Port: 443
5. ๐๐๐ (๐๐๐๐ฎ๐ซ๐ ๐๐ก๐๐ฅ๐ฅ):
- Default Port: 22
6. ๐
๐๐ (๐
๐ข๐ฅ๐ ๐๐ซ๐๐ง๐ฌ๐๐๐ซ ๐๐ซ๐จ๐ญ๐จ๐๐จ๐ฅ):
- Control Port: 21
- Data Port: 20
7. ๐๐๐๐ (๐๐ข๐ฆ๐ฉ๐ฅ๐ ๐๐๐ข๐ฅ ๐๐ซ๐๐ง๐ฌ๐๐๐ซ ๐๐ซ๐จ๐ญ๐จ๐๐จ๐ฅ):
- Port: 25
8. ๐๐๐ (๐๐จ๐ฆ๐๐ข๐ง ๐๐๐ฆ๐ ๐๐ฒ๐ฌ๐ญ๐๐ฆ):
- Port: 53
9. ๐๐๐ (๐๐๐ฆ๐จ๐ญ๐ ๐๐๐ฌ๐ค๐ญ๐จ๐ฉ ๐๐ซ๐จ๐ญ๐จ๐๐จ๐ฅ):
- Port: 3389
10. ๐๐ฒ๐๐๐ ๐๐๐ญ๐๐๐๐ฌ๐:
- Port: 3306
11. ๐๐จ๐ฌ๐ญ๐ ๐ซ๐๐๐๐ ๐๐๐ญ๐๐๐๐ฌ๐:
- Port: 5432
12. ๐๐จ๐ง๐ ๐จ๐๐:
- Port: 27017
13. ๐๐ฎ๐๐๐ซ๐ง๐๐ญ๐๐ฌ ๐๐๐ ๐๐๐ซ๐ฏ๐๐ซ:
- Port: 6443
14. ๐๐ ๐ข๐ง๐ฑ:
- Default HTTP Port: 80
- Default HTTPS Port: 443
15. ๐๐ฅ๐๐ฌ๐ญ๐ข๐๐ฌ๐๐๐ซ๐๐ก:
- Port: 9200
16.๐๐ฉ๐๐๐ก๐ ๐๐จ๐ฆ๐๐๐ญ:
- Default HTTP Port: 8080
- Default HTTPS Port: 8443
17. ๐๐ซ๐จ๐ฆ๐๐ญ๐ก๐๐ฎ๐ฌ:
- Port: 9090
18.๐๐ซ๐๐๐๐ง๐:
- Default HTTP Port: 3000
19 . ๐๐ข๐ญ:
- SSH Port: 22
- Git Protocol Port: 9418
Remember that these are default port numbers, for security reasons, it's common to change default port numbers or use secure protocols (e.g., HTTPS) when possible.
What is a subnet?
A subnet is a smaller network that is part of a larger network. Subnetting is the process of dividing a network into subnets to improve efficiency, security, and performance. Each subnet has its own range of IP addresses that identify the devices connected to it. A subnet mask is a number that determines how many bits of an IP address are used for the network and how many are used for the host. For example, a subnet mask of 255.255.255.0 means that the first 24 bits of an IP address are for the network and the last 8 bits are for the host.
How to start a process in Linux?
There are different ways to start a process in Linux, depending on whether you want to run it in the foreground or the background, and whether you want to control it from the terminal or not. Here are some common methods:
- To start a process in the foreground, simply type its name at the command line and press Enter. For example, to start an Nginx web server, type `nginx`ยน. The process will be attached to the terminal and you can interact with it using keyboard input. To stop the process, you can press Ctrl+C or send a signal to it using another terminal.
- To start a process in the background, append an ampersand (`&`) to the command. For example, to start a CloudCommander file manager, type `cloudcmd &`โต. The process will be detached from the terminal and you can run other commands without waiting for it to finish. To bring the process to the foreground, you can use the `fg` command with the job number or the process IDโด.
- To start a process as a service, you can use the `systemctl` command with the `start` option and the service name. For example, to start an Apache web server as a service, type `sudo systemctl start apache2`ยน. The service will run in the background and will be managed by systemd, which is the default init system for most Linux distributions. You can use other options of `systemctl` to stop, restart, reload, enable, or disable servicesยน.
- To start a process with a specific priority, you can use the `nice` command with a value between -20 (highest priority) and 19 (lowest priority). For example, to start a process with a low priority, type `nice -n 19 command`โด. The default priority is 0. You can use the `renice` command to change the priority of a running processโด.
What is the use of /proc in Linux?
The /proc directory in Linux is a virtual file system that provides information about the systemโs processes and kernel. It is not a conventional file system that stores files on a disk, but rather a dynamic view of the systemโs internal state. The /proc directory contains various files and subdirectories that represent different aspects of the system, such as memory, CPU, filesystems, network, devices, and more. You can use the /proc directory to monitor your systemโs performance, configuration, and behaviour, as well as to control some kernel parameters and processes.
Some of the common files and subdirectories in the /proc directory are:
/proc/cpuinfo
: This file contains information about the CPU(s) on the system, such as the model, speed, and number of cores./proc/meminfo
: This file contains information about the memory usage and statistics on the system, such as the total amount of memory, free memory, and the memory used by each process/proc/filesystems
: This file contains a list of all the filesystems that are supported by the kernel at the time of listing/proc/sys
: This subdirectory contains configuration and runtime parameters for the kernel, such as network settings, security options, and system limits/proc/loadavg
: This file shows the system load average over different time intervals, such as 1, 5, and 15 minutes/proc/self
: This subdirectory is a symbolic link to the processโs own directory/proc/stat
: This file contains a variety of statistics about the system, such as the number of processes running, the number of interrupts, and the amount of time spent in each CPU state./proc/uptime
: This file contains the amount of time the system has been running/proc/PID
: This subdirectory contains information about a specific process, where PID is the process ID.
What is the difference between memory virtual memory and cache?
Memory, virtual memory, and cache are different types of storage that are used by a computer to perform various tasks. Here is a brief explanation of each term:
- Memory: Memory is the primary storage unit of a computer that holds data and instructions that are currently being processed by the CPU. Memory is also known as RAM (Random Access Memory) because it can be accessed randomly by the CPU. Memory is volatile, which means it loses its data when the power is turned off. Memory is faster than other types of storage, but it is also more expensive and has a limited capacity.
- Virtual memory: Virtual memory is a memory management technique that allows the user to execute programs that are larger than the actual main memory. Virtual memory is not a physical storage unit, but a logical space that is created by the operating system using some part of the hard disk. Virtual memory maps the logical addresses of the program to the physical addresses of the main memory or the disk. Virtual memory increases the capacity of the main memory, but it is slower than accessing data from the memory directly.
- Cache: Cache is a type of fast-access memory that is used to store copies of data from frequently used main memory locations so that the CPU can access that data faster. Cache is not a technique, but a physical storage unit that is located close to the CPU. Cache is smaller than the main memory, but it is faster and more expensive. Cache reduces the average access time of the CPU to the main memory.
What is swap space and how to check swap space?
Swap space is a part of the hard disk that acts as an extension of the physical memory (RAM) of a computer. It allows the operating system to store some data that are not frequently used or accessed by the CPU, and free up some space in the RAM for more important or urgent tasks. Swap space can improve the performance and stability of the system, especially when the RAM is fully utilized or insufficient. However, swap space is slower than RAM, so it should not be used as a replacement for RAM.
There are different ways to check the swap space usage and size in Linux, such as:
Using the free command with the -h option to display the total, used, and free swap space in human-readable format.
For example, free -h
Using the swapon command with the --show option to display detailed information about the swap space, such as the name, type, size, used, and priority.
For example, swapon --show
Using the cat command to read the /proc/swaps file, which contains information about the swap areas in use.
For example, cat /proc/swaps
Using the top or htop command to monitor the swap space utilization along with other system resources.
For example, top or htop
Using the smem command to find out which processes are using how much swap space on the system.
For example, smem -rs swap