Practical Interview Questions and Answers
1. Managing Linux Server Network Interfaces and Bridges
--------------------------------------------------------Q1: How do you assign a static IP address to a network interface in Linux?
A:
1. Open the network configuration file for the interface:
- On RHEL-based systems: /etc/sysconfig/network-scripts/ifcfg-<interface>.
- On Debian-based systems: /etc/network/interfaces.
2. Example configuration for a static IP (ifcfg):
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
3. Restart the network service:
sudo systemctl restart network
Q2: How can you check if a network interface is up and running?
A:
Use the ip command:
ip link show <interface>
Check for "state UP" to confirm the interface is active.
Q3: Explain how to create a network bridge and attach two interfaces to it.
A:
1. Install bridge utilities:
sudo apt install bridge-utils
2. Create a bridge:
sudo brctl addbr br0
3. Add interfaces to the bridge:
sudo brctl addif br0 eth0 eth1
4. Bring the bridge up:
sudo ip link set br0 up
2. Linux SSH Login Between Two Systems
---------------------------------------Q1: How do you set up passwordless SSH between two servers? Can you explain the process step
by step?
A:
1. Generate SSH keys on the source server:
ssh-keygen -t rsa
2. Copy the public key to the target server:
ssh-copy-id user@remote-ip
3. Test the connection:
ssh user@remote-ip
Q2: You try to SSH into a remote server, but the connection is refused. What steps would you take
to troubleshoot?
A:
- Verify the SSH service is running:
sudo systemctl status ssh
- Check if the port is open:
sudo netstat -tuln | grep 22
- Ensure the firewall allows SSH:
sudo ufw allow ssh
3. LVM Linux Storage / Mount
-----------------------------Q1: Explain how to create a new logical volume using LVM.
A:
1. Create a physical volume:
pvcreate /dev/sdX
2. Create a volume group:
vgcreate my_vg /dev/sdX
3. Create a logical volume:
lvcreate -L 10G -n my_lv my_vg
Q2: How would you extend an existing logical volume without unmounting it?
A:
1. Extend the logical volume:
lvextend -L +5G /dev/my_vg/my_lv
2. Resize the filesystem:
resize2fs /dev/my_vg/my_lv
4. LAMP Stack
-------------Q1: Can you describe the process of installing and configuring a LAMP stack?
A:
1. Install Apache:
sudo apt install apache2
2. Install MySQL/MariaDB:
sudo apt install mysql-server
3. Install PHP:
sudo apt install php libapache2-mod-php
4. Test PHP: Create /var/www/html/info.php with:
<?php phpinfo(); ?>
Q2: How would you secure a LAMP server?
A:
- Remove default files:
sudo rm /var/www/html/index.html
- Use a firewall to block unnecessary ports.
- Configure strong MySQL passwords and remove test databases.
5. Firewalls such as CSF
-------------------------Q1: How do you install and configure CSF on a Linux server?
A:
1. Install CSF:
wget https://download.configserver.com/csf.tgz
tar -xzf csf.tgz
cd csf
sudo ./install.sh
2. Enable CSF:
sudo systemctl enable csf
sudo csf -e
Q2: How do you allow or block a specific IP address using CSF?
A:
- Allow:
sudo csf -a <IP>
- Block:
sudo csf -d <IP>