Linux System Administration Practical
Index
- Installation of Linux operating system.
- Working with basic commands
- Linux system administration
- Configuring NICs with Network Device Configuration Utilities (ip and ifconfig)
- Install and configure a DNS Server with a domain name of your choice.
- Install and configure DHCP server and client
- Install and configure Mail Server
- Install and configure Apache Web Server for hosting websites
- Securing a simple network with a Linux firewall (Net filter/iptables)
- Setting up Samba Server to share files and printers with Windows-based and other operating systems
Installation of Linux operating system (kali)
Download the Kali Linux iso file.
Create a new virtual machine.
- Open Virtual Machine then create a new Machine for install Linux OS
- Click on “Installer disc image file(iso):” and then set the Linux iso file path then click on next.
- Select Linux in the Guest operating system then select the suitable version then click next
- Fill in the virtual machine name then set the right position to install the Linux OS then click next.
- Set the disk capacity “recommended size 20 GB” then click “store virtual disk as a single file” then click next.
- If you change any hardware property then click on “Customize hardware” otherwise click finish
- Your virtual is ready for use.
Linux Installation
- Click on “Play virtual machine”.
- Linux Installation starting.
- Select a language “English”.
- Select your location “India”
- Configure your keyboard “American English”
- Configure the network
- Enter the system hostname
- Enter the domain name
- Setup the user and password
- Enter the user’s full name
- Enter the username
- Enter the user password
- Disk partition
- Select the “Guided – use enter disk”
- Select disk partition – SCSI33(0,0,0) ……….
- Select partitioning scheme – “All files in one partition”
- Click on “Finish partitioning and write changes to disk”
- Write the change to disk? – yes
- Disk partitioning complete
- Software Selection for according to the user.
- Install the GRUB Boot loader
- Click on yes
- Select devices for boot loader installation
- Linux Installation Finish.
Package Installation
Package Removing
Shutting down
Working with basic commands
Basic Commands
- whoami - User Name
- who - User name and details
- users - List all users
- uname - Print machine name or type
- uname -r - Print machine version
- uname -r -a - Print all machine details.
- pwd - Present working directories
- ls - List all folders or files in the present working directory
- ls -r - Print all details
- ls -a - Print all with hidden files
- man command_name - Print command details
- cd - Change directory
- lsblk - List disk partitioning
- cal - Calendar
- date - Print date full
- wget url - Download any webpage in HTML
- ps - Print service
- top - List all tools and services currently work
- kill pid_number - Close any operation or tool
- figlet text - Text print in a different style
- factor - Number for finding the factors
- shutdown time - Shutdown machine on specific time
Directory Commands and Operations
- mkdir folder_name - Create folder
- touch file_format - Create any type of file
- type > file_format - Create any type of file
- echo text > file_name - Create a file with data
- cat ./to.txt - print file data
- touch .hiddenfile_name - Create hidden file
- cp ./filename /location - File copy on location to other
- mv /filename /location - Move a file from one location to other
- mv old_file_name new_file_name - Rename a file
- rm file_name - Remove files in the current directory
- rmdir directoryname - Remove empty directory
Linux system administration
superuser – superuser is commonly known as root. It is created by default and has user ID & Group ID as 0. It doesn’t have a password by default one can assign it by
# sudo passwd root
Create new user –
Switch user –
Administrative commands –
- man - Display information about all commands
- kill - Kill a process
- wget - Download file from network
- env - Display environment variable for currently logged–in user
- cat - Display, copy or combine text files
- ifconfig - Display configuration
- sudo - Run a command as a root user
- su - Switch from one to another user
- history - Find the all-history command list.
Administrative configuration files
Configuring NICs with Network Device Configuration Utilities (ip and ifconfig)
- Using ip command
- Using ifconfig command
Install and configure a DNS Server with a domain name of your choice.
Check Requirements
- Install DNS
- Checking status DNS server
- If you have UFW firewall, open up access to BIND
- Create Forward zone
- DNS query will be forwarded to the forwarders when your local DNS server is unable to resolve query.
- Uncomment add your DNS
- Create a new forward.hg.local file
- Create a new reverse.hg.local file
Testing DNS Server
- Add DNS server Ip address in /etc/resolve.conf file
- Add new: nameserver IP DNS Server
- Testing on DNS Server
- Testing on Windows
Install DHCP Server
- The ISC DHCP server package is available in the official package repository of ubuntu. So, you can easily install it using the APT package manager.
- Backup Configure File of ISC DHCP server in the /etc/dhcp/ directory.
- Create a new blank configure file dhcpd.conf in /etc/dhcp/ directory
- To check the syntax of dhcpd.conf file for errors.
- Restart and Enable ISC DHCP to auto-start during boot time
- Checking ISC DHCP service, ensure its running.
Install and configure Mail Server
Set a Hostname and Create DNS Records for Domain
- First, set a valid FQDN (Fully Qualified Domain Name) hostname for your Ubuntu server using the hostnamectl command as shown.
- Next, you need to add MX and A records for your domain in your DNS control panel that guides other MTAs that your mail server mail.yourdomain.com domain is responsible for email delivery.
- In order to create a running mail server using “Roundcube”, we’ll have to install Apache2, MariaDB, and PHP packages first, to do so, run.
- Postfix is a mail transfer agent (MTA) which is the responsible software for delivering & receiving emails, it’s essential in order to create a complete mail server.
- During installation, you will be asked to choose the type of mail configuration, choose “Internet Site”.
- Now enter the fully qualified domain name that you want to use for sending and receiving emails.
- Once Postfix is installed, it will automatically start and create a new /etc/postfix/main.cf file. You can verify the Postfix version and status of the service using the following commands.
Testing Postfix Mail Server on Ubuntu
- Now try to check your mail server is connecting on port 25 using the following command.
- The above message indicates that the connection is successfully established. Type quit closing the connection.
- You can also use a mail program to send and read emails using the following command.
Installing Dovecot IMAP and POP in Ubuntu
- Dovecot is a mail delivery agent (MDA), it delivers the emails from/to the mail server, to install it, run the following command.
- Next, restart the Dovecot service using the following command.
Installing Roundcube Webmail in Ubuntu
- Roundcube is the webmail server that you’ll be using to manage emails on your server, it has a simple web interface to do the job, it can be customized by installing more modules & themes.
- Next, you need to create a new database and user for Roundcube and grant all permission to a new user to write to the database.
- Next, import the initial tables to the Roundcube database.
Create an Apache Virtual Host for Roundcube Webmail
- Create an apache virtual host for Roundcube webmail.
- Add the following configuration to it.
- Next, enable this virtual host and reload the apache for the changes.
- You can now access the webmail by going to http://yourdomain.com/roundcubemail/installer/
- Next, go to the Database settings and add the database details.
- After making all the changes, create a config.inc.php file.
- After finishing the installation and the final tests please delete the installer folder and make sure that enable_installer option in config.inc.php is disabled.
- Now go to the login page and enter the user name and the password of the user.
Creating Mail Users
- In order to start using the Roundcube webmail, you’ll have to create a new user, to do so, run.
- Replace “myusername” with the user name you want, create a password for the new user by running.
- Now go back to the login page and enter the user name and the password of the newly created user.
Install and configure Apache Web server for hosting websites
Install Apache server- Run the following command to install Apache.
- Run the following command to start the Apache process.
- Verify that the service is running by executing the following command.
- Run the following command to restart Apache.
- The next step is to set up the web server configuration for the domain. The Apache configuration directory is /etc/apache2 and apache2.conf is the main Apache configuration file. Each domain needs its own Virtual Host configuration file.
- The configuration files use the .conf extension, and needs to be saved in the /etc/apache2/sites-available/ directory.
- Create a file at /etc/apache2/sites-available/yourdomain.com.conf and add the following lines in it.
- Create a directory for the website and then create an index.html file for the website.
- Add some content to index.html.
- Restart Apache service for the above changes to take effect.
- Open any browser and enter the website URL.
- The Apache web server can be tested by entering the server IP address into the browser’s address bar:
- http://your_server_ip
Securing a simple network with a Linux firewall
Netfilter: - The Netfilter project enables packet filtering, network address [and port] translation (NA[P]T), packet logging, userspace packet queueing, and another packet mangling. The Netfilter hooks are a framework inside the Linux kernel that allows kernel modules to register call-back functions at different locations of the Linux network stack.
iptables: - iptables is a generic firewalling software that allows you to define rulesets. Each rule within an IP table consists of a number of classifiers (iptables matches) and one connected action (iptables target).
Displaying the Status of Your Firewall
- Type the following command as root:
- Sample outputs:
- The above output indicates that the firewall is not active. The following sample shows an active firewall:
- Sample outputs:
- -L: List rules.
- -v: Display detailed information. This option makes the list command show the interface name, the rule options, and the TOS masks. The packet and byte counters are also listed, with the suffix ‘K’, ‘M’ or ‘G’ for 1000, 1,000,000, and 1,000,000,000 multipliers respectively.
- -n: Display IP address and port in numeric format. Do not use DNS to resolve names. This will speed up the listing.
To inspect firewall with line numbers, enter:
- Sample outputs:
- You can use line numbers to delete or insert new rules into the firewall.
- To display INPUT or OUTPUT chain rules, enter:
Stop / Start / Restart the Firewall
- If you are using CentOS / RHEL / Fedora Linux, enter:
- You can use the iptables command itself to stop the firewall and delete all rules:
- -F: Deleting (flushing) all the rules.
- -X: Delete chain.
- -t table_name: Select table (called nat or mangle) and delete/flush rules.
- -P: Set the default policy (such as DROP, REJECT, or ACCEPT).
Delete Firewall Rules
- To display line number along with other information for existing rules, enter:
- You will get the list of IP. Look at the number on the left, then use the number to delete it. For example, delete line number 4, enter:
- OR find source IP 202.54.1.1 and delete from the rule:
- -D: Delete one or more rules from the selected chain
Insert Firewall Rules
- To insert one or more rules in the selected chain as the given rule number use the following syntax. First find outline numbers, enter:
- Sample outputs:
- To insert rule between 1 and 2, enter:
- To view updated rules, enter:
- Sample outputs:
Save Firewall Rules
- To save firewall rules under CentOS / RHEL / Fedora Linux, enter:
- In this example, drop an IP and save firewall rules:
- For all other distros use the iptables-save command:
Restore Firewall Rules
- To restore firewall rules form a file called /root/my.active.firewall.rules, enter:
- To restore firewall rules under CentOS / RHEL / Fedora Linux, enter:
Drop Private Network Address on Public Interface
- IP spoofing is nothing but to stop the following IPv4 address ranges for private networks on your public interfaces. Packets with non-routable source addresses should be rejected using the following syntax:
- IPv4 Address Ranges for Private Networks (make sure you block them on the public interface)
Blocking an IP Address (BLOCK IP)
- To block an attackers ip address called 1.2.3.4, enter:
Block Incoming Port Requests (BLOCK PORT)
- To block all service requests on port 80, enter:
- To block port 80 only for an ip address 1.2.3.4, enter:
Block Outgoing IP Address
- To block outgoing traffic to a particular host or domain such as cyberciti.biz, enter:
- Sample outputs:
- Note down its ip address and type the following to block all outgoing traffic to 75.126.153.206:
- You can use a subnet as follows:
- Example - Block Facebook.com Domain
- First, find out all ip address of facebook.com, enter:
- Sample outputs:
- Find CIDR for 69.171.228.40, enter:
- Sample outputs:
- To prevent outgoing access to www.facebook.com, enter:
- You can also use domain name, enter:
Drop or Accept Traffic from Mac Address
- Use the following syntax:
Block or Allow ICMP Ping Request
- Type the following command to block ICMP ping requests:
- Ping responses can also be limited to certain networks or hosts:
- The following only accepts limited type of ICMP requests:
Open Range of Ports
- Use the following syntax to open a range of ports:
Open Range of IP Addresses
- Use the following syntax to open a range of IP address:
Testing Your Firewall
- Find out if ports are open or not, enter:
- Find out if tcp port 80 open or not, enter:
- If port 80 is not open, start the Apache, enter:
- Make sure iptables allowing access to the port 80:
- Otherwise, open port 80 using the iptables for all users:
- Use the telnet command to see if firewall allows to connect to port 80:
- Sample outputs:
- You can use the nmap command to probe your own server using the following syntax:
- Sample outputs:
Setting up Samba server to share files and printers with Windows-based and another operating system
Install samba on system
- Install samba and required packages by samba
- Start and Enable samba service
- Allow samba service through system firewall (ignore, if firewall service is stop)
Configuring Everyone access file sharing
- First, create the shared directory
- Set the appropriate permissions on the “everyone” directory
- Edit config file smb.conf (/etc/samba/smb.conf)
- Verify the samba configuration
- Now, restart samba service
Testing on windows and Linux OS
- Open windows OS
- Open network in file manager
- Open “Everyone” directory
- Create folder “test”
- Create text file “test.txt”
- Edit file insert “test”
- Open Linux OS
Comments
Post a Comment