10 Basic Interview Questions with Answers on Linux Networking


Linux is a widely used operating system, and networking is a crucial aspect of it. The ability to understand and troubleshoot Linux networking is a valuable skill for any IT professional. In this article, we will cover some basic interview questions on Linux networking, along with their answers and examples.

What is the purpose of the ifconfig command, and how is it used?

The ifconfig command is used to configure and manage network interfaces on Linux. It can be used to view the current network configuration, assign IP addresses, configure network interfaces, and set other network-related parameters. Here is an example of how to use ifconfig −

$ ifconfig eth0

This command will display the current configuration of the eth0 interface, including its IP address, netmask, and other details.

How do you check the routing table on a Linux system?

The routing table is used to determine the best path for network traffic to take. To check the routing table on a Linux system, use the following command −

$ netstat -r

This command will display the routing table, including the destination network, netmask, gateway, and other information.

How do you assign a static IP address to a network interface in Linux?

To assign a static IP address to a network interface in Linux, you will need to edit the network configuration file. The location of this file may vary depending on your distribution, but it is usually located in the /etc/network/interfaces directory. Here is an example of how to assign a static IP address to the eth0 interface −

$ sudo vi /etc/network/interfaces

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1

In this example, we have assigned the IP address 192.168.1.100 to the eth0 interface, along with the netmask and gateway.

How do you configure a Linux system as a router?

To configure a Linux system as a router, you will need to enable IP forwarding and configure NAT (Network Address Translation). IP forwarding allows the Linux system to forward packets between networks, while NAT allows the Linux system to translate private IP addresses to public IP addresses. Here is an example of how to configure a Linux system as a router −

$ sudo sysctl -w net.ipv4.ip_forward=1
$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

In this example, we have enabled IP forwarding and configured NAT on the eth0 interface.

What is the purpose of the netstat command, and how is it used?

The netstat command is used to display various network-related statistics on a Linux system. It can be used to view active network connections, listening ports, routing tables, and other information. Here is an example of how to use netstat to display active network connections −

$ netstat -an | grep ESTABLISHED

This command will display a list of active network connections that are currently in the ESTABLISHED state.

What is the purpose of the route command, and how is it used?

The route command is used to view and modify the kernel's IP routing table. It can be used to add or delete routes, view the routing table, and set other routing-related parameters. Here is an example of how to use the route command to add a new route −

$ sudo route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1

This command will add a new route for the network 192.168.2.0/24 via the gateway 192.168.1.1.

How do you configure a Linux system to use a static IP address for DNS resolution?

To configure a Linux system to use a static IP address for DNS resolution, you will need to edit the /etc/resolv.conf file. Here is an example of how to configure a static IP address for DNS resolution −

$ sudo vi /etc/resolv.conf
nameserver 192.168.1.1

In this example, we have configured the DNS server to use the IP address 192.168.1.1 for DNS resolution. You can replace this IP address with the IP address of your own DNS server.

How do you configure a Linux system to use a VPN connection?

To configure a Linux system to use a VPN connection, you will need to install a VPN client and configure it with the appropriate settings. OpenVPN is a popular open-source VPN client that can be installed on Linux. Here is an example of how to configure OpenVPN on a Linux system −

$ sudo apt-get install openvpn
$ sudo cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf /etc/openvpn/
$ sudo vi /etc/openvpn/client.conf

In this example, we have installed the OpenVPN client, copied the sample configuration file to the /etc/openvpn directory, and edited it to include the appropriate settings. You will need to replace the sample configuration settings with your own VPN settings.

How do you configure a Linux system to use a static MAC address for a network interface?

To configure a Linux system to use a static MAC address for a network interface, you will need to edit the network configuration file for that interface. The location of this file may vary depending on your distribution, but it is usually located in the /etc/network/interfaces directory. Here is an example of how to configure a static MAC address for the eth0 interface −

$ sudo vi /etc/network/interfaces

auto eth0
iface eth0 inet dhcp
hwaddress ether 00:11:22:33:44:55

In this example, we have assigned the MAC address 00:11:22:33:44:55 to the eth0 interface.

How do you configure a Linux system to use a static IP address for a wireless network interface?

To configure a Linux system to use a static IP address for a wireless network interface, you will need to edit the network configuration file for that interface. The location of this file may vary depending on your distribution, but it is usually located in the /etc/network/interfaces directory. Here is an example of how to configure a static IP address for the wlan0 interface −

$ sudo vi /etc/network/interfaces

auto wlan0
iface wlan0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid myssid
wpa-psk mypassword

In this example, we have assigned the IP address 192.168.1.100 to the wlan0 interface, along with the netmask, gateway, SSID, and password for the wireless network.

How do you configure a Linux system to use VLAN tagging?

To configure a Linux system to use VLAN tagging, you will need to create a virtual network interface for each VLAN. Here is an example of how to configure VLAN tagging −

$ sudo vconfig add eth0 100
$ sudo vconfig add eth0 200

In this example, we have created two virtual network interfaces for VLAN 100 and 200 on the eth0 physical interface. You will need to configure the virtual network interfaces with the appropriate network settings.

How do you configure a Linux system to use a static route for a specific destination?

To configure a Linux system to use a static route for a specific destination, you will need to use the route command to add the route. Here is an example of how to add a static route −

$ sudo route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1

In this example, we have added a static route for the network 192.168.2.0/24 via the gateway 192.168.1.1.

How do you configure a Linux system to use a static DNS server for a specific network interface?

To configure a Linux system to use a static DNS server for a specific network interface, you will need to edit the network configuration file for that interface. The location of this file may vary depending on your distribution, but it is usually located in the /etc/network/interfaces directory. Here is an example of how to configure a static DNS server for the eth0 interface −

$ sudo vi /etc/network/interfaces

auto eth0
iface eth0 inet dhcp
dns-nameservers 192.168.1.1

In this example, we have configured the eth0 interface to use the DNS server at IP address 192.168.1.1.

Updated on: 02-May-2023

580 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements