Some Interview questions Networking and linux basics.

ยท

8 min read

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

ย