Theory
In this episode I decided to take a slight diversion into networking fundamentals. As before, if you want to learn more about installing the ONICS tool suite, go back and listen to HPR 2882.
There are three key concepts to understand about modern networks. They are:
digital - the networks carry bits and bytes (binary digits)
packet switched - devices break data into blobs of data called "packets" and take turns sending and receiving those packets to/from other devices attached to the network
internetworked -- machines communicate using a protocol that allows traffic to traverse across multiple, independently-managed networks in a uniform way
My Setup
2 laptops connected to a home wifi network that has Internet connectivity.
Practicing sending data from a source machine to a destination machine. Both are running Linux.
Source machine:
Wifi interface: wlan0
Ethernet address: 00:22:fa:a7:69:90
IP address: 192.168.0.4
Destination machine
Wifi interface: wlo1
Ethernet address: 6c:88:14:7c:2e:14
IP address: 192.168.0.248
Internet Router:
Ethernet address: 00:0d:b9:23:f2:51
IP address: 192.168.0.1
More Terminology
Address - a number that identifies a machine's interface in a network
Packet - a blob of binary data sent as a unit over a network
Route - a rule that specifies how to forward traffic to a given address
Router / Gateway - a machine that uses the IP protocol and forwards traffic between multiple networks that it connects to
Network Protocol - a set of rules and data formats for exchanging information over a network
Standard UNIX Commands
ifconfig (no arguments or '-a')
list interfaces on a machine
ifconfig IFNAME
list properites about a given interface
ping -c 1 IPADDRESS
send an echo request to machine IPADDRESS
arp -na
Dump the Ethernet addresses of known nearby machines
netstat -nr
Dump the routes in a system
netstat -nr | grep "^0.0.0.0"
Find the route (and thus IP address) of the default gateway
ONICS Commands in this Episode
rawpkt - take a blob of data and wrap it in an XPKT format (so other ONICS tools can understand what it is)
ethwrap - take an XPKT and prepend an Ethernet header to it
ipwrap - take an XPKT and prepend an IP header to it
pktin - read a stream of packets from a network interface
pflt - filter a stream of packets so that only those matching a pattern get through
pktout - send a stream of packets to a network interface
x2hpkt - convert XPKTs into a hex dump
xpktdump - like x2hpkt, but send the output to a pager like 'less' for easy reading
Sending an Ethernet Packet to the Destination
On the receiver:
$ sudo pktin wlo1 |
pflt "not ip and eth.dst == 6c:88:14:7c:2e:14" |
x2hpkt
On the sender:
$ echo "hello world" |
rawpkt |
ethwrap "eth.dst = 6c:88:14:7c:2e:14; "
"eth.src = 00:22:fa:a7:69:90; "
"eth.ethtype = 12;" |