dotlinux blog

10 Basic Interview Questions and Answers on Linux Networking

Linux networking is a fundamental aspect of system administration and network engineering. Understanding the basics of Linux networking is crucial for anyone looking to work in the IT industry, especially in roles related to system management, network troubleshooting, and cloud computing. In this blog post, we will explore 10 basic interview questions and answers on Linux networking to help you prepare for your next interview.

2026-06

Table of Contents#

  1. What is the difference between TCP and UDP?
  2. How do you check the network interfaces in Linux?
  3. What is the purpose of the /etc/hosts file?
  4. How can you set a static IP address in Linux?
  5. What is the role of DNS in Linux networking?
  6. How do you troubleshoot network connectivity issues in Linux?
  7. What is the ping command used for?
  8. How can you list all open network ports in Linux?
  9. What is the difference between a bridge and a VLAN?
  10. How do you configure a firewall in Linux?

1. What is the difference between TCP and UDP?#

Answer#

  • TCP (Transmission Control Protocol):
    • Connection - Oriented: TCP establishes a connection between the sender and the receiver before data transmission. It uses a three - way handshake (SYN, SYN - ACK, ACK) to set up the connection.
    • Reliable: It ensures that data is delivered in the correct order and without errors. If a packet is lost or corrupted, TCP will retransmit it.
    • Flow Control: TCP uses a sliding window mechanism to control the amount of data that can be sent at a time, preventing the receiver from being overwhelmed.
    • Higher Overhead: Due to its reliability and connection - oriented nature, TCP has more overhead compared to UDP.
    • Use Cases: Commonly used for applications where data integrity is crucial, such as web browsing (HTTP/HTTPS), email (SMTP, POP3, IMAP), and file transfer (FTP).
  • UDP (User Datagram Protocol):
    • Connectionless: UDP does not establish a connection before sending data. Each packet is sent independently.
    • Unreliable: There is no guarantee that the data will be delivered, and packets may arrive out of order.
    • No Flow Control: UDP does not have a mechanism to control the flow of data.
    • Lower Overhead: Since it lacks the features of TCP, UDP has less overhead.
    • Use Cases: Suitable for applications where real - time data transfer is more important than data integrity, such as streaming media (audio and video), online gaming, and DNS queries.

2. How do you check the network interfaces in Linux?#

Answer#

There are several ways to check network interfaces in Linux:

  • ifconfig:
    • This is a traditional command used to view and configure network interfaces. In most modern Linux distributions, it is part of the net - tools package. To list all network interfaces, you can run the command ifconfig -a.
    • Example output:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.100  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fe68:9999  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:68:99:99  txqueuelen 1000  (Ethernet)
        RX packets 1000  bytes 1024000 (1000.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 500  bytes 512000 (500.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • ip addr:
    • This is a more modern and recommended command for network interface management. It is part of the iproute2 package. To list all network interfaces, run ip addr.
    • Example output:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:68:99:99 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic eth0
       valid_lft 86399sec preferred_lft 86399sec
    inet6 fe80::a00:27ff:fe68:9999/64 scope link 
       valid_lft forever preferred_lft forever

3. What is the purpose of the /etc/hosts file?#

Answer#

The /etc/hosts file is a local text - based file used by the operating system to map hostnames to IP addresses. Its main purposes are:

  • Local Name Resolution: It allows you to resolve hostnames to IP addresses without querying a DNS server. For example, if you have a server named webserver with an IP address of 192.168.1.10, you can add an entry in the /etc/hosts file like this:
192.168.1.10    webserver

Now, when you try to access webserver from the local machine, the system will use the IP address 192.168.1.10 without going to the DNS server.

  • Testing and Development: It is useful for testing and development purposes. You can create fake hostnames and map them to local IP addresses or test servers. For example, if you are developing a website and want to test it using a domain name, you can add an entry in the /etc/hosts file to point the domain name to your local development server.
  • Security: In some cases, the /etc/hosts file can be used to block access to certain websites by mapping the website's hostname to an invalid IP address (e.g., 127.0.0.1).

4. How can you set a static IP address in Linux?#

Answer#

The process of setting a static IP address in Linux can vary depending on the distribution. Here is a general guide for Ubuntu and Debian - based systems:

  1. Edit the Network Configuration File:
    • Open the network configuration file /etc/netplan/*.yaml (in Ubuntu 18.04 and later) or /etc/network/interfaces (in older Ubuntu and Debian systems) using a text editor like nano or vim.
    • For Netplan (Ubuntu 18.04+):
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
- In the above example, `eth0` is the network interface, `dhcp4: no` disables DHCP, `addresses` sets the static IP address and subnet mask, `gateway4` sets the default gateway, and `nameservers` sets the DNS servers.

2. Apply the Changes: - For Netplan, run the command sudo netplan apply to apply the new network configuration. - For the /etc/network/interfaces method, restart the networking service using sudo systemctl restart networking (older systems).

For Red Hat - based systems like CentOS and Fedora:

  1. Edit the Network Configuration File:
    • Edit the network configuration file for the interface, usually located at /etc/sysconfig/network-scripts/ifcfg-<interface_name>. For example, for the eth0 interface:
TYPE=Ethernet
BOOTPROTO=none
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
  1. Restart the Network Service:
    • Run sudo systemctl restart network to apply the new configuration.

5. What is the role of DNS in Linux networking?#

Answer#

DNS (Domain Name System) plays a crucial role in Linux networking:

  • Name Resolution: DNS translates human - readable domain names (e.g., www.example.com) into IP addresses (e.g., 192.0.2.1). In Linux, when you try to access a website using a domain name, the system first queries the DNS server to get the corresponding IP address.
  • Reverse Lookup: DNS can also perform reverse lookups, where an IP address is translated back to a domain name. This is useful for security and logging purposes.
  • Load Balancing: DNS can be used for load balancing by returning multiple IP addresses for a single domain name. The client can then choose one of the IP addresses to connect to, distributing the load across multiple servers.
  • Mail Routing: DNS is used to determine the mail servers (MX records) responsible for receiving emails for a particular domain. In Linux, mail servers use DNS to find the correct destination for outgoing emails.
  • Configuration in Linux: In Linux, the DNS servers are usually configured in the /etc/resolv.conf file. For example:
nameserver 8.8.8.8
nameserver 8.8.4.4

This tells the system to use Google's public DNS servers for name resolution.

6. How do you troubleshoot network connectivity issues in Linux?#

Answer#

Here are some steps and commands to troubleshoot network connectivity issues in Linux:

  1. Check Network Interfaces:
    • Use ip addr or ifconfig -a to check if the network interfaces are up and have the correct IP addresses.
    • If an interface is down, you can try to bring it up using sudo ip link set <interface_name> up.
  2. Ping:
    • Use the ping command to test if you can reach a remote host. For example, ping 8.8.8.8 will try to send ICMP echo requests to Google's public DNS server. If you get a response, it means your network is able to reach the destination.
  3. Traceroute:
    • The traceroute command (or mtr which provides a more continuous view) can be used to determine the route that packets take to reach a destination. It shows all the intermediate routers between your system and the destination. For example, traceroute www.example.com.
  4. DNS Resolution:
    • Use the nslookup or dig commands to test DNS resolution. For example, nslookup www.example.com will query the DNS server for the IP address of www.example.com. If you get an error, it could indicate a DNS configuration issue.
  5. Check Firewall Rules:
    • If you have a firewall enabled (e.g., iptables or ufw), check the rules to make sure they are not blocking the traffic. You can list the rules using sudo iptables -L (for iptables) or sudo ufw status (for ufw).
  6. Check Routes:
    • Use the ip route command to view the routing table. Make sure that the default gateway is set correctly and that there are no incorrect routes.

7. What is the ping command used for?#

Answer#

The ping command is a fundamental network utility used to test the reachability of a host on an IP network and to measure the round - trip time for messages sent from the originating host to a destination host.

  • Testing Connectivity: By sending ICMP (Internet Control Message Protocol) echo request packets to a specified IP address or domain name, ping checks if the destination is reachable. If the destination host is reachable, it will send back ICMP echo reply packets. For example, ping 192.168.1.1 will test if you can reach the device with the IP address 192.168.1.1.
  • Measuring Latency: The ping command also displays the round - trip time (RTT) for each packet sent and received. This RTT is the time it takes for a packet to travel from the source to the destination and back. The output shows the minimum, maximum, and average RTT values, which can be used to measure the latency between the two hosts.
  • Diagnosing Network Issues: If you are getting a high number of packet losses or long RTTs, it could indicate network congestion, a faulty network device, or other issues. For example, if you are pinging a website and getting a high packet loss rate, it could mean there is a problem with the network connection between your system and the website's server.

8. How can you list all open network ports in Linux?#

Answer#

There are several ways to list all open network ports in Linux:

  • netstat:
    • The netstat command can be used to display network connections, routing tables, and network interface statistics. To list all open TCP and UDP ports, you can run netstat -tuln.
    • -t shows TCP ports, -u shows UDP ports, -l lists only listening ports, and -n shows numerical addresses instead of resolving hostnames.
    • Example output:
Active Internet connections (only servers)
Proto Recv - Q Send - Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
udp        0      0 0.0.0.0:68              0.0.0.0:*                          
  • ss:
    • ss is a modern replacement for netstat and is part of the iproute2 package. To list all open TCP and UDP ports, run ss -tuln.
    • Example output:
Netid  State    Recv - Q   Send - Q   Local Address:Port    Peer Address:Port 
tcp    LISTEN   0         128        0.0.0.0:22            0.0.0.0:*         
udp    UNCONN   0         0          0.0.0.0:68            0.0.0.0:*         
  • lsof:
    • The lsof (list open files) command can also be used to list open network ports. To list all open TCP and UDP ports, run sudo lsof -i -P -n | grep LISTEN.
    • -i selects network - related files, -P inhibits the conversion of port numbers to port names, and -n inhibits the conversion of network numbers to host names.

9. What is the difference between a bridge and a VLAN?#

Answer#

  • Bridge:
    • Function: A bridge is a device or a software - based component that connects multiple network segments at the data link layer (Layer 2) of the OSI model. It forwards frames based on the MAC addresses of the devices on the network.
    • Use Case: Bridges are used to extend a network or to connect different types of network segments (e.g., Ethernet and Wi - Fi). In Linux, you can create a bridge using the brctl or ip link commands to connect multiple network interfaces together as if they were part of the same network segment.
    • Traffic Forwarding: Bridges forward traffic between connected segments without modifying the data in the frames. They learn the MAC addresses of devices on each segment and build a forwarding table to determine where to send frames.
  • VLAN (Virtual Local Area Network):
    • Function: A VLAN is a logical grouping of devices on a network, regardless of their physical location. It allows you to segment a network into multiple virtual networks, each with its own broadcast domain.
    • Use Case: VLANs are used for network security, traffic management, and to isolate different types of traffic. For example, you can create separate VLANs for different departments in an organization (e.g., HR, IT, Finance).
    • Traffic Isolation: Devices in different VLANs cannot communicate directly at the data link layer. Traffic between VLANs must be routed through a Layer 3 device (e.g., a router or a Layer 3 switch).
    • Tagging: VLANs use a tagging mechanism (e.g., IEEE 802.1Q) to identify which VLAN a frame belongs to. When a frame enters a VLAN - enabled device, a VLAN tag is added to the frame, and the device uses this tag to determine how to forward the frame.

10. How do you configure a firewall in Linux?#

Answer#

There are several ways to configure a firewall in Linux:

  • iptables:
    • Introduction: iptables is a traditional firewall management tool in Linux. It allows you to define rules for filtering network traffic based on various criteria such as source and destination IP addresses, ports, and protocols.
    • Example Rules:
      • To allow incoming SSH traffic on port 22:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
    - To block all incoming traffic except the rules you have defined:
sudo iptables -P INPUT DROP
- **Saving Rules**: After creating the rules, you can save them so that they are applied on boot. On Debian - based systems, you can use `iptables - save > /etc/iptables.rules` and then add a line to the `/etc/network/interfaces` file to restore the rules on boot. On Red Hat - based systems, you can use `service iptables save`.
  • ufw (Uncomplicated Firewall):
    • Introduction: ufw is a simplified front - end for iptables designed to make firewall configuration easier for beginners.
    • Example Rules:
      • To allow incoming SSH traffic:
sudo ufw allow ssh
    - To enable the firewall:
sudo ufw enable
- **Status**: You can check the status of the firewall using `sudo ufw status`.
  • firewalld:
    • Introduction: firewalld is a dynamic firewall daemon used in Red Hat - based systems (e.g., CentOS, Fedora). It uses zones to manage network traffic.
    • Example Rules:
      • To allow incoming SSH traffic:
sudo firewall-cmd --zone=public --add-service=ssh --permanent
    - To reload the firewall rules:
sudo firewall-cmd --reload

Conclusion#

In this blog post, we have covered 10 basic interview questions and answers on Linux networking. Understanding these concepts is essential for anyone looking to work in the field of Linux system administration and network engineering. By mastering these topics, you will be better prepared to handle network - related tasks and troubleshoot common issues.

References#

  • "Linux Networking Cookbook" by Sander van Vugt
  • "TCP/IP Illustrated, Volume 1: The Protocols" by Richard A. Stevens
  • official documentation of Linux distributions (e.g., Ubuntu, CentOS) for network configuration and management