Вы находитесь на странице: 1из 8

1 . Implement a linux server system with an ip address 192.168.0.

45 and update the hostname as ServerXX (XX stands for rollno)


Soln :
i. #hostname server10
ii. set permanent ip in ifcfg-eth0
2. Restart the basic services essential for any network configurations.
Soln: # service network restart
3. Add a normal user and login using any of the terminal and resume back to the GNOME terminal
Soln: #useradd john , #passwd john
open terminal no 2 as ctrl+alt+F2 and login as john and come back to GNOME i.e , ctrl+alt+F1
4. Create a folder with your name and give full access rights to that folder in server
Soln: #mkdir /john
#chmod -R 777 /john
5. Create a folder with another name and give only read, write access to that folder in client.
Soln: #mkdir /jack
#chmod -R 766 /jack
6. With the above given addresses mount and unmount the folders that are created in Q.1 from server to the client.
Soln: the above is NFS
7. Configure the DHCP server by matching the following conditions: a. Subnet and Netmask should be 192.168.0.0 and 255.255.255.0 b.
Gateway Should be 192.168.0.254 c. DNS Server Should be 192.168.0.254 d. Domain Name should be example.com e. Range from
192.168.0.10 to 192.168.0.50 f. Implement for both linux client and windows client
HINT: In the above question,DNS is ip address to be given to DHCP Server and not to setup DNS SERVER
8. Create Firewall rule to reject all incoming ssh request .
Soln: #iptables -A INPUT -p tcp --dport ssh -j REJECT
The above command block all incoming ssh request generated by tcp through ethernet .
- Rejecting ssh connection from a specific IP :
#iptables -A INPUT -p tcp INPUT -p tcp -d 192.168.1.3 --sport ssh -j REJECT
The above command block incoming ssh req through a specific ip address.
NOTE : since the question is asked for 20M , also show how to start/stop/restart firewalls ,
both iptables and selinux .
9. Apply the immutable attribute for file linux in the home directory of root.
Soln : immutable attribute makes file readonly and non-changeable
#vim linux
#chattr +i linux
open and try to edit , it should not allow to edit .
Run the command again as , #chattr -i linux
the above will again make it changeable and editable .
10. Create user ty and change the password ageing policies for the user
#useradd ty , #passwd ty

#chage -m 10

-M 20

-W 7

-I 7

-E 1/10/2018 ty

#vim /etc/shadow (open and check at the end of the file )


11. Create multiple users abc, xyz and pqr simultaneously using newusers commands.
Soln : #vim myfile
abc:redhat:345:357:new Emp:/home/abc:/bin/bash
pqr:redhat:346:358:new Emp:/home/pqr:/bin/bash
xyz:redhat:347:359:new Emp:/home/xyz:/bin/bash
12. Create a primary partition of size 500 MB and mount in onto directory /data.
HINT : you need to create sda5 / sda6 using fdisk , partx, mkfs.ext3,mount ,umount , /etc/fstab
13. Uninstall the gpm service and install the same again using RPM.
#rpm -e gpm
#cd /media/RHEL-----------------/Packages
#rpm -ivh gpm------------#service gpm restart
14. Send mail using MUA mutt from user root to user bscit.
HINT : this is sendmail server asked , mutt is interface where we write mail on linux , for eg, subject,
body etc.

JAVA AND C++ PROGRAMS


1. socket program to concatenate two string
2. socket program to display length of the string
3. socket program to find average of the numbers
4. socket program to find reverse of the numbers
5. c++ program to find a number is palindrome or not
6. c++ program to find a number is prime or not
7. c program to display numbers in ascending order

TCP/IP SOCKET PROGRAM TO CONCATENATE TWO STRINGS


CLIENT SIDE
import java.io.* ;
import java.net.* ;
public class clientconcat {
public static void main(String[] args) throws IOException {
Socket s = new Socket("localhost",6666);
DataInputStream dis = new DataInputStream(s.getInputStream());
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ;
System.out.println("Enter the first string :");

String str1 = br.readLine();


System.out.println("Enter the second string :");
String str2 = br.readLine();
dos.writeUTF(str1) ;
dos.writeUTF(str2) ;
String str3 = dis.readUTF() ;
System.out.println("Concatenated string is " + str3);
dos.close();
dis.close();
s.close();
}
}
SERVER SIDE
import java.io.* ;
import java.net.* ;
public class serverconcat {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(6666);
Socket s= ss.accept();
DataInputStream dis = new DataInputStream(s.getInputStream());
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
String str1 = dis.readUTF();
String str2 = dis.readUTF();
String str3 = str1 + str2;
dos.writeUTF(str3);
dos.close();
dis.close();
s.close();
}
}
TCP/IP SOCKET PROGRAM TO FIND THE LENGTH OF THE STRING
CLIENT SIDE
import java.io.* ;
import java.net.* ;
public class clientlength {

public static void main(String[] args) throws IOException {


Socket s = new Socket("localhost",6666);
DataInputStream dis = new DataInputStream(s.getInputStream());
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ;
System.out.println("Enter the string :");
String str = br.readLine();
dos.writeUTF(str) ;
int len = dis.readInt();
System.out.println("Length is " + len);
dos.close();
dis.close();
s.close();
}
}
SERVER SIDE
import java.io.* ;
import java.net.* ;
public class serverlength {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(6666);
Socket s= ss.accept();
DataInputStream dis = new DataInputStream(s.getInputStream());
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
String str = dis.readUTF();
dos.writeInt(str.length());
dos.close();
dis.close();
s.close();
}
}
TCP/IP SOCKET PROGRAM TO DISPLAY AVERAGE OF NOS
CLIENT SIDE
import java.io.* ;
import java.net.* ;

public class clientavg {


public static void main(String[] args) throws IOException {
Socket s = new Socket("localhost",6666);
DataInputStream dis = new DataInputStream(s.getInputStream());
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ;
System.out.println("Enter the no of elements in array :");
int n = Integer.parseInt(br.readLine());
int[] arr = new int[n];
dos.writeInt(n);
for(int i=0;i<n;i++)
{

arr[i] = Integer.parseInt(br.readLine());
dos.writeInt(arr[i]) ;
}

int avg = dis.readInt();


System.out.println("Average is " + avg);
dos.close();
dis.close();
s.close();
}
}
SERVER SIDE
import java.io.* ;
import java.net.* ;
public class serveravg {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(6666);
Socket s= ss.accept();
DataInputStream dis = new DataInputStream(s.getInputStream());
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
int n = dis.readInt();
int[] arr= new int[n];
for(int i=0;i<n;i++)
arr[i]= dis.readInt();
int total=0;

for(int i=0;i<n;i++)
total = total+arr[i];
int avg = total/n;
dos.writeInt(avg);
dos.close();
dis.close();
s.close();
}}
TCP/IP SOCKET PROGRAM TO DISPLAY REVERSE OF THE NUMBER
CLIENT SIDE
import java.io.* ;
import java.net.* ;
public class clientreverse {
public static void main(String[] args) throws IOException {
Socket s = new Socket("localhost",6666);
DataInputStream dis = new DataInputStream(s.getInputStream());
DataOutputStream dos = new DataOutputStream(s.getOutputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ;
System.out.println("Enter the number :");
int num = Integer.parseInt(br.readLine());
dos.writeInt(num) ;
int rev = dis.readInt();
System.out.println("Reverse is " + rev);
dos.close();
dis.close();
s.close();
}
}
SERVER SIDE
import java.io.* ;
import java.net.* ;
public class serverreverse {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(6666);
Socket s= ss.accept();

DataInputStream dis = new DataInputStream(s.getInputStream());


DataOutputStream dos = new DataOutputStream(s.getOutputStream());
int d,rev=0;
int num = dis.readInt();
do {
d=num%10;
rev=(rev*10)+d;
num=num/10;

while(num!=0);
dos.writeInt(rev);
dos.close();
dis.close();
s.close();
}
}
c++ PROGRAM TO DISPLAY A NUMBER IS PALINDROME OR NOT
#include <iostream>
using namespace std;

int main()
{
int n, num, digit, rev = 0;
cout << "Enter a positive number: ";
cin >> num;
n = num;
do
{
digit = num%10;
rev = (rev*10) + digit;
num = num/10;
}while (num!=0);
cout << " The reverse of the number is: " << rev << "\n";
if (n==rev)
cout << " The number is a palindrome";
else
cout << " The number is not a palindrome";

return 0;
}

C++ PROGRAM TO DISPLAY NUMBER IS PRIME OR NOT


#include <iostream>
using namespace std;

int main()
{
int n, i, flag=0;
cout << "Enter a positive integer: ";
cin >> n;
for(i=2;i<=n/2;++i)
{

if(n%i==0)
{
flag=1;
break;
}
}
if (flag==0)
cout << "This is a prime number";
else
cout << "This is not a prime number";
return 0;
}

C PROGRAM TO DISPLAY NOS IN ASCENDING ORDER


1.
2.

#include <stdio.h>

3.
4.

void main()
{

5.
6.

int i, j, a, n, number[30];

7.
8.

printf("Enter the value of N \n");


scanf("%d", &n);

9.
10.

printf("Enter the numbers \n");


for (i = 0; i < n; ++i)

11.
12.

scanf("%d", &number[i]);
for (i = 0; i < n; ++i)

13.
14.

{
for (j = i + 1; j < n; ++j)

15.
16.
17.
18.
19.
20.
21.
22.

{
if (number[i] > number[j])
{
a = number[i];
number[i] = number[j];
number[j] = a;
}
}

23.
24.

}
printf("The numbers arranged in ascending order are given below \n");

25.
26.
27.

for (i = 0; i < n; ++i)


printf("%d\n", number[i]);
}