Sei sulla pagina 1di 7

******************************************************************

EXPERIMENT NO. 6
Name :- Class : T.E. COMPUTER
SUB : COMPUTER NETWORKS Roll No :
Date of conductance : / /2023 Date of submission : /0 /2023
******************************************************************
Aim :
a) Set up multiple IP addresses on a single LAN.
b) Using netstat and route commands of Linux, do the following:
• View current routing table
• Add and delete routes
• Change default gateway
c) Perform packet filtering by enabling IP forwarding using IPtables in Linux.
Theory:-

IP Address: An IP address is a unique address that identifies a device on the internet


or a local network. IP stands for "Internet Protocol," which is the set of rules
governing the format of data sent via the internet or local network.
An IP address is a string of numbers separated by periods. IP addresses are expressed
as a set of four numbers — an example address might be 192.158.1.38. Each number
in the set can range from 0 to 255. So, the full IP addressing range goes from 0.0.0.0
to 255.255.255.255.
LAN: A local area network (LAN) is a collection of devices connected together in
one physical location, such as a building, office, or home. A LAN can be small or
large, ranging from a home network with one user to an enterprise network with
thousands of users and devices in an office or school.
Routing Table: A routing table is a set of rules, often viewed in table format, that
is used to determine where data packets traveling over an Internet Protocol (IP)
network will be directed. All IP-enabled devices, including routers and switches, use
routing tables.
Default Gateway: A default gateway is a node that enables a seamless connection
between networks, allowing one machine to talk to another machine on a different
network. It's called a 'default' gateway because it is the first and default route taken
unless another option is actively requested. The most common use for the default
gateway is to gain access to a webpage, where the request will be sent via the gateway
before going on to the internet. Another key use is connecting devices on one subnet
with devices on another, with the default gateway acting as an intermediary.
IPtables: iptables is a command-line firewall utility that uses policy chains to allow
or block traffic. When a connection tries to establish itself on your system, iptables
looks for a rule in its list to match it to. If it doesn’t find one, it resorts to the default
action. iptables almost always comes pre-installed on any Linux distribution.
Packet Filtering: Packet filtering protects a local network from undesired invasion
depending upon the predefined rules. The information passes through a network in
the form of small pieces called packets, which travel independently across IP
networks. These small packets travel through a node only if they match with
predefined filtering rules otherwise get dropped. Hence, the filtering rules that are
defined by the network layer firewalls in a packet filtering firewall prove to be highly
efficient in providing security mechanisms.

IP Forwarding: IP forwarding is the ability for an operating system to accept


incoming network packets on one interface, recognize that it is not meant for the
system itself, but that it should be passed on to another network, and then forwards
it accordingly.
a) Set up multiple IP addresses on Ubuntu 20.04 LAN using GUI
1. Open Ubuntu Network Manager Settings
Go to the top panel of Ubuntu and on the right side click on the Network icon. From
the drop-down menu select the Wired Connected then Wired Settings. After that
click on the Gear icon to open further settings related to a particular active
connection on your system.

2. Select Ipv4
Click on the Ipv4 tab to access different methods for fetching IP address on your
Linux system.

3. Add multiple IP addresses manually


Now, select the manual method to provide Ip address on your Ubuntu Linux
computer. After that you will see a section to add multiple Ip addresses, so add the
ones which you want to use as shown in the below screenshot. In the DNS, we can
either use the common 8.8.8.8 / 4.4.4.4 or else the one you have from your naming
server. Once you are done save the settings by clicking on Apply button.
4. Turn off and on network connection
Now, to make changes into effect, click on the Toggle button available in Settings
under the Network section to turn it off, and clicking again will turn it on again.

5. Check Ip address in Terminal


To confirm whether our Ubuntu’s system Network interface has binned successfully
to the multiple IP addresses we have manually assigned, open Command Terminal
and run the following command: ip addr You will see something like given in the
screenshot. All the IP address which has been set by us manually are showing in the
command terminal, this means we have multiple addresses to communicate to the
same network interface.
We can confirm this further by pinging each IP address we have set with some other
computer or virtual machine available in the same network. Here we are using
Windows PC to ping the addresses of our Ubuntu 20.04 LTS machine. And all of
them were communicated.

b) Using netstat and route commands of Linux


View current routing table:
Command:

netstat -rn
Adding route:
Command:

sudo route add -net 192.168.3.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

Deleting route:
Command:

sudo route del -net 192.168.3.0 gw 192.168.1.1 netmask 255.255.255.0 dev eth0

A quick way to add default route:


Command:

route add default gw 192.168.1.1

A quick way to delete default route:


Command:

route del default gw 192.168.1.1


Change default gateway:
Command:

sudo route add default gw 192.168.1.254


OR
sudo ip route add default via 192.168.1.254

c) Perform packet filtering by enabling IP forwarding using IPtables in


Linux.
To test this requirement, we need two servers (rhce1 and rhce2). The first server has
two ethernet adapters. One allows connections to the internet, while the other is part
of a private network. The second server has a single ethernet adapter on the private
network. Make sure rhce1.localdomain : eth0 192.168.0.190 - Connects to the
internet. eth1 192.168.1.190 - Private network. rhce2.localdomain : eth0
192.168.1.191 - Private network.
Setup:

1. Edit the "/etc/sysctl.conf" file on rhce1, amending the "net.ipv4.ip_forward" entry


as follows.
net.ipv4.ip_forward = 1

2. Run the following command to make the change take effect.


# /sbin/sysctl -p

3. Make sure the gateway on rhce2 is set to the private network address of rhce1 and
that rhce2 can resolve names.
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.190 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 1 0 0 eth0
#
# nslookup oracle.com
Server: 192.168.0.4
Address: 192.168.0.4#53
Non-authoritative answer:
Name: oracle.com
Address: 137.254.16.101
#

4. Configure the firewall on rhce1 to allow forwarding of packets between the


networks
and allow NAT to access the adapter with external access.
# iptables -I FORWARD -i eth1 -o eth0 -j ACCEPT
# iptables -I FORWARD -i eth0 -o eth1 -j ACCEPT
# iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
# service iptables save

Conclusion: Thus, we successfully set up multiple ip address on single lan, used


netstat and route commands, and performed packet filtering using iptables.

Potrebbero piacerti anche