Configuring routing table running on Linux Machine
Question: How do I examine the routing table on a machine?
Once the network interfaces have been configured, the next part of TCP/IP configuration is configuring routing.
TCP/IP routing may be handled in two ways: static routing or dynamic routing. In static routing, routing information is programmed into the machine at boot time. In dynamic routing, a program (a route daemon) communicates with other routing daemons to continually update the system's routing information in response to changing network conditions.
Configure Static Routing:
In this course, we will discuss how to configure static routing only, in the simplest case of a machine with only one network interface, on a local network with only one gateway. Routing is controlled by a table called the routing table, which is maintained by the kernel. To view the routing table, using the route command: View the routing table, using the route command. If you are on a laptop or PC, place your mouse over the IP address table below to see information displayed regarding the table.
How does one monitor traffic for Network Addresses?
Any traffic destined for the network address 131.193.178.0 (the local network) does not need a gateway, and should be sent out interface eth0.
Any traffic intended for network address 127.0.0.1 (the loopback address) should be sent out the loopback interface.
Traffic not intended for the local network or the loopback address defaults to the machine 131.193.178.1, which is the gateway machine.
“U” indicates that the route is UP.
“G” indicated that the route is a gateway.
The image shows a "Kernel IP routing table" with the following columns and key elements. Here's the extracted and analyzed output:
Routing Table Analysis:
Destination
Gateway
Genmask
Flags
Metric
Ref
Use
Iface
131.193.178.0
* (no gateway)
255.255.255.0
U
0
0
1278
eth0
127.0.0.1
* (no gateway)
255.0.0.0
U
0
0
392
lo
default
131.193.178.1
0.0.0.0
UG
0
0
21075
eth0
Explanation of Key Fields:
Destination:
Specifies the network or host to which the route applies.
131.193.178.0 → Specific local subnet.
127.0.0.1 → Local loopback interface.
default → Default route for any destination not explicitly listed.
Gateway:
Identifies the next-hop gateway to reach the destination.
* → No gateway (directly connected).
131.193.178.1 → Default gateway for non-local traffic.
Genmask:
Subnet mask defining the range of the destination.
255.255.255.0 → Subnet mask for local network.
255.0.0.0 → Subnet mask for loopback.
0.0.0.0 → Default route covers all other destinations.
Reference count (number of active routes using this entry).
Use:
Number of packets sent using this route.
Iface:
The network interface used for this route:
eth0 → Ethernet interface for local network and default route.
lo → Loopback interface.
Insights:
Local Network Route:
Traffic for the 131.193.178.0/24 subnet is directly reachable via eth0.
Loopback Route:
All traffic for 127.0.0.1/8 is routed via the loopback interface (lo).
Default Gateway:
All traffic not matching other routes is sent to the gateway at 131.193.178.1 via eth0.
The routing table and route command
Monitor Traffic for Network Addresses
Monitoring traffic for "network addresses" within the context of a "routing table" on a machine typically involves analyzing how packets are routed through the network and identifying specific traffic patterns for certain network addresses or subnets. Below are the key methods and tools to monitor such traffic:
Inspecting the Routing Table
The routing table itself helps determine where packets destined for specific network addresses will be sent. On Linux, you can inspect the routing table with:
ip route show
route -n (deprecated in newer Linux versions but still available)
Look for entries that match specific subnets or default routes to ensure packets are being sent correctly.
Monitoring Network Traffic Using Tools
Monitoring tools help capture and analyze network traffic to or from specific network addresses. Some popular tools include:
tcpdump
A command-line packet analyzer that allows you to capture and inspect traffic.
Example to monitor traffic for a specific network address:
sudo tcpdump host 192.168.1.1
To capture traffic for a subnet:
sudo tcpdump net 192.168.1.0/24
Wireshark
A graphical tool for analyzing network traffic in-depth.
Apply filters to capture traffic for a specific network or subnet:
ip.addr == 192.168.1.1
Wireshark provides advanced filtering and visualization of traffic data.
nload
A command-line tool to monitor incoming and outgoing traffic on specific interfaces.
Helps identify general traffic trends without detailed packet analysis.
iftop
Provides a real-time view of network traffic sorted by IP addresses or subnets.
Launch it for a specific interface to see traffic flow:
sudo iftop -i eth0
Netfilter and iptables/nftables
Use Linux's iptables or nftables to log traffic to specific network addresses or ranges.
Example with iptables to log all packets destined for a network:
sudo iptables -A OUTPUT -d 192.168.1.0/24 -j LOG --log-prefix "Traffic to subnet: "
Logs will appear in /var/log/syslog or /var/log/messages.
Traffic Analysis with NetFlow or sFlow
Use NetFlow (Cisco) or sFlow to gather flow-based traffic data for the entire network.
Flow data provides aggregated insights into traffic patterns, including:
Source and destination IPs
Traffic volumes
Protocol usage
Tools to analyze flow data:
nfdump (NetFlow analyzer)
sFlowTool (sFlow analyzer)
System Logs and Monitoring Solutions
Leverage centralized logging tools like:
Syslog for traffic-related logs
ELK Stack (Elasticsearch, Logstash, Kibana) to analyze logs
Use advanced monitoring systems like Nagios, Zabbix, or Prometheus to set up alerts and dashboards.
Example Workflow for Monitoring a Subnet:
Check the Routing Table:
ip route show
Verify the correct route exists for the subnet (e.g., 192.168.1.0/24).
Filter for the subnet and analyze traffic patterns.
By combining these tools and techniques, you can effectively monitor traffic for specific network addresses and ensure proper routing and network performance.
Reading Routes and IP Information
Assuming an already configured machine named isolde, let uslook at the IP addressing and routing table. Next we will examine how the machine communicates with computers (hosts) on the locally reachable network. We will then send packets through our default gateway to other networks. After learning what a default route is, we will look at a static route.
One of the first things to learn about a machine attached to an IP network is its IP address. We will begin by looking at a machine named isolde on the main desktop network (192.168.99.0/24). The machine isolde is alive on IP 192.168.99.35 and has been properly configured by the system administrator. By examining the route and ifconfig output we can learn a good deal about the network to which isolde is connected.
Solaris: On Solaris, use the command netstat -nr to dump the routing table. The output is nearly identical to the output of the route command used on Linux. The routing table gives a list of potential destinations, and for each destination, the IP address of a gateway[1]. Information intended for one of the listed destinations is sent to the specified gateway. We are assuming that this machine is on a local network with only one gateway (this is a typical situation), so any traffic not for the local network should be directed to that gateway. The only entry in the routing table that needs to be set is the default route, because the local route is set automatically by the ifconfig command. To set the default route, use:
host# /sbin/route add default gw [address]
The route command may also be used to delete a route:
host# /sbin/route del [ address ]
The link below contains additional information regarding linux routing commands.
Linux Routing Commmands:
You are logged on with normal user permissions, and you are in the /home/user1 directory.
Your systems administrator has updated the system PATH value to allow you to use the route command. You are going to work with the routing table in order to further understand the significance of a properly configured routing table.
Your IP address is 192.168.199.34. You are therefore on the 192.168.199.0 network. Issue the proper command to inspect your routing table.
Solution: route
According to the readout, your default gateway is 192.168.199.1. You can see this by viewing the entry that says default
Then, look for the entry beneath “Gateway”. The default gateway is listed here (192.168.199.1). Send four ping packets to your default gateway.
Solution:
ping -c 4 192.168.199.1
You now know that you can access your default gateway. Assert root privileges so that you can work with your routing table. Solution: su
Use rootpass as your password.
Now that you have root privileges, you can experiment with the routing table to further understand the consequences of a misconfigured routing table. Delete the default gateway entry. Hint: Your command will involve the use of the word “default.”
Solution: route del default
One of the many systems on your subnet has the IP address of 192.168.199.129. Issue four ping packets to see if you can still reach this system.
Solution: ping -c 4 192.168.199.129
Notice that you can still connect to this system, even though you have deleted the default gateway from your system's routing table. This is because the system exists on the same subnet, and does not require a default gateway. Now, check to see if you can ping another host on another subnet.For example, the Acme Web server is on another subnet. Ping the host at www.acmecorp.com four times. Solution:ping -c 4 www.acmecorp.com
Note that you have not been able to issue this query, because the Acme Web server exists on a different subnet. In order to send messages to this Web server, you require a router to intercede for you. It is possible, however, that your DNS server may be down. This means that even though you may still have a default gateway, your DNS server will not be able to provide name-to-IP-address resolution. To troubleshoot your connectivity, use ping to query the Acme Web server by its IP address (216.32.118.210). Send the server two ping packets.
Solution: ping -c 2 216.32.118.210
The attempt has failed, confirming your understanding of the routing table. The problem is not with DNS. It is with your routing table. Now, issue a command that creates a new default entry for your default gateway.
Solution: route add default gw 192.168.199.1
Your interface has a default gateway, again. Test your connectivity by pinging the Acme Web server again twice. Use the following command: ping -c 2 www.acmecorp.com. Solution: ping -c 2 www.acmecorp.com
How do I configure Routing command in Solaris?
You are logged on with normal user permissions, and you are in the /home/user1 directory.
Your systems administrator has updated the system PATH value to allow you to use the netstat and route commands.
You are going to work with the routing table in order to further understand the significance of a properly configured routing table.
Your IP address is 192.168.199.34. You are therefore on the 192.168.199.0 network. Issue the proper command to inspect your routing table.
Solution: netstat -nr
According to the readout, your default gateway is 192.168.199.1. You can see this by viewing the entry that says “default”. Then, look for the entry beneath “Gateway”. The default gateway is listed here (192.168.199.1). Send some ping packets to your default gateway.
Solution:ping 192.168.199.1
You now know that you can access your default gateway. Assert root privileges so that you can work with your routing table. Use rootpass as your password.
Solution: su
Now that you have root privileges, you can experiment with the routing table to further understand the consequences of a misconfigured routing table. Assume that the route command is in the execute path for the root shell. Delete the default gateway entry. Hint: Your command will involve the use of the word “default.”
Solution: route delete default 192.168.199.1
One of the many systems on your subnet has the IP address 192.168.199.129. Issue some ping packets to see if you can still reach this system.
Solution: ping 192.168.199.129
Notice that you can still connect to this system, even though you have deleted the default gateway from your system's routing table.
This is because the system exists on the same subnet, and does not require a default gateway. Now, check to see if you can ping another host on another subnet.
For example, the Acme Web server is on another subnet. Ping the host at www.acmecorp.com.
Solution: ping www.acmecorp.com
You receive error messages from ping indicating that there is no valid route to this host—this is because the Acme Web server exists on a different subnet. In order to send messages to this Web server,
you require a router to intercede for you. Issue a command that creates a new default entry for your default gateway.
Solution: route add default 192.168.199.1 Text for all other entries: Use the route command, then use add and specify
the gateway address.
Your interface has a default gateway, again. Test your connectivity by pinging the Acme Web server again.
Solution: ping www.acmecorp.com