Posts in Category: linux


Using sdiff like a pro

My colleague Kiran Patel, has showed me this really cool command:

superdiffcommand='systemctl list-units --type=service | grep running' && sdiff -w 200 <(ssh box1.com $superdiffcommand) <(ssh box2.com $superdiffcommand)

If the command you want to run requires root priveleges, then you can do:

superdiffcommand='sudo systemctl list-units --type=service | grep running' && sdiff -w 200 <(ssh -t box1.com $superdiffcommand) <(ssh -t box2.com $superdiffcommand)

ssh tunnel

Create an ssh tunnel like this:

$ ssh -L 8081:localhost:80 {fqdn}

Then access the server’s website using:

http://localhost:8081


Data Packets, packet headers, and the OSI model

When 2 devices wants to communicate with each other over a network, it does so by constructing packets of data and then sending them to each other. A data packet is basically a structured data (similar to xml), where the actual payload data is nested inside header tags. The header tag’s data contains information to help routing the data packets. These header tags are nested inside other header tags, which in turn are nested inside other header tags.

You can imagine a data packet being similar to a hand written letter (data payload) that is put inside an envelope and an address written on that envelope (packet header, along with it’s information), which in turn is put inside a bigger envelope with another address written on it (another header)….and


Using arp

arp translates ip address to mac addresses.

The arp command let’s you see which one of your interfaces has access to the default gateway, and therefore can access the internet.

the following shows which interface has access to the the default gateway:

$ arp
Address                  HWtype  HWaddress           Flags Mask            Iface
172.28.128.2             ether   08:00:27:88:f1:e5   C                     enp0s10
172.28.128.1   															

The DHCP server

A dhcp (dynamic host configuration protocol) server provides configuration to boxes that joins it’s network.

The dhcp often acts as the default gateway too.



Using mtr

Sometimes that ping and traceroute command doesn’t work due to network security reasons:

https://www.linux.com/news/ping-icmp-vs-arp

Note: I couldn’t get arping to work either.

That’s where mtr can come in handy. mtr is a combination of the ping and traceroute command.

$ yum install mtr

Then do:

$ mtr codingbee.net

This starts up a text based display (a bit like how the top command does) that is constantly refreshing. It looks something like this:

                                     My traceroute  [v0.85]
localhost.localdomain (0.0.0.0)